Skip to content

Commit 149824a

Browse files
committed
WIP: nixified webui
currently packaging as a nixosModule so should be easy to integrate with nixos generators in the future. Also looking at making a docker image without systemd
1 parent 82a973c commit 149824a

File tree

22 files changed

+4214
-19
lines changed

22 files changed

+4214
-19
lines changed

.envrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
use flake
2+
watch_file uv.lock

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,5 @@ notification.mp3
4242
/cache
4343
trace.json
4444
/sysinfo-????-??-??-??-??.json
45+
.direnv
46+
result

flake.lock

Lines changed: 170 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
{
2+
description = "Django application using uv2nix";
3+
4+
inputs = {
5+
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
6+
7+
pyproject-nix = {
8+
url = "github:pyproject-nix/pyproject.nix";
9+
inputs.nixpkgs.follows = "nixpkgs";
10+
};
11+
12+
uv2nix = {
13+
url = "github:pyproject-nix/uv2nix";
14+
inputs.pyproject-nix.follows = "pyproject-nix";
15+
inputs.nixpkgs.follows = "nixpkgs";
16+
};
17+
18+
pyproject-build-systems = {
19+
url = "github:pyproject-nix/build-system-pkgs";
20+
inputs.pyproject-nix.follows = "pyproject-nix";
21+
inputs.uv2nix.follows = "uv2nix";
22+
inputs.nixpkgs.follows = "nixpkgs";
23+
};
24+
25+
uv2nix-hammer-overrides = {
26+
url = "github:TyberiusPrime/uv2nix_hammer_overrides";
27+
inputs.nixpkgs.follows = "nixpkgs";
28+
};
29+
};
30+
31+
outputs =
32+
inputs@{
33+
self,
34+
nixpkgs,
35+
pyproject-nix,
36+
pyproject-build-systems,
37+
uv2nix,
38+
uv2nix-hammer-overrides,
39+
40+
...
41+
}:
42+
let
43+
lib = nixpkgs.lib.extend (
44+
self: _: {
45+
flake = import ./nix/lib (
46+
{
47+
lib = self;
48+
}
49+
// inputs
50+
);
51+
}
52+
);
53+
package-name = "stable-diffusion-webui";
54+
pythonSets = import ./pythonSets.nix ({ inherit lib; } // inputs);
55+
allArgs = inputs // {
56+
inherit lib package-name pythonSets;
57+
};
58+
59+
nixDirs = lib.flake.getSubdirs ./nix;
60+
importFolder = (
61+
name: {
62+
name = name;
63+
value =
64+
65+
import ./nix/${name} allArgs;
66+
}
67+
);
68+
in
69+
{
70+
asgiApp = "django_webapp.asgi:application";
71+
settingsModules = {
72+
prod = "django_webapp.settings";
73+
};
74+
}
75+
// builtins.listToAttrs (map importFolder nixDirs);
76+
}

nix/checks/default.nix

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
lib,
3+
self,
4+
package-name,
5+
...
6+
}:
7+
lib.flake.forAllSystems (
8+
system:
9+
let
10+
mainPkg = self.packages.${system}.${package-name};
11+
in
12+
13+
rec {
14+
inherit (mainPkg) tests;
15+
inherit (mainPkg.tests) mypy pytest nixos;
16+
default = pytest;
17+
}
18+
19+
)

nix/devShells/default.nix

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
args@{
2+
lib,
3+
self,
4+
package-name,
5+
pythonSets,
6+
nixpkgs,
7+
...
8+
}:
9+
lib.flake.forAllSystems (
10+
system:
11+
let
12+
pkgs = import nixpkgs {
13+
inherit system;
14+
config.allowUnfree = true;
15+
};
16+
pythonSet = pythonSets.${system};
17+
folders = lib.flake.getSubdirs ./.;
18+
folderAttrs = (
19+
name: {
20+
name = name;
21+
value = import ./${name} (
22+
args
23+
// {
24+
inherit pkgs system pythonSet;
25+
}
26+
); # You can replace this with any value
27+
}
28+
);
29+
in
30+
builtins.listToAttrs (map folderAttrs folders)
31+
// {
32+
default = self.devShells.${system}.${package-name};
33+
}
34+
)

nix/devShells/init/default.nix

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
pkgs,
3+
lib,
4+
system,
5+
self,
6+
...
7+
}:
8+
let
9+
inherit (self.packages.${system}) venv;
10+
in
11+
pkgs.mkShell {
12+
packages = [
13+
pkgs.uv
14+
pkgs.python310
15+
];
16+
env = {
17+
UV_NO_SYNC = "1";
18+
UV_PYTHON = "${pkgs.python310}";
19+
UV_PYTHON_DOWNLOADS = "never";
20+
};
21+
shellHook = ''
22+
unset PYTHONPATH
23+
export REPO_ROOT=$(git rev-parse --show-toplevel)
24+
'';
25+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
pkgs,
3+
lib,
4+
self,
5+
system,
6+
...
7+
}:
8+
let
9+
venv = self.packages.${system}.venv;
10+
in
11+
pkgs.mkShell {
12+
packages = [
13+
venv
14+
pkgs.uv
15+
];
16+
env = {
17+
UV_NO_SYNC = "1";
18+
UV_PYTHON = "${venv}/bin/python";
19+
UV_PYTHON_DOWNLOADS = "never";
20+
};
21+
shellHook = ''
22+
unset PYTHONPATH
23+
export REPO_ROOT=$(git rev-parse --show-toplevel)
24+
'';
25+
}

nix/lib/default.nix

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
lib,
3+
...
4+
}:
5+
{
6+
forAllSystems = lib.genAttrs lib.systems.flakeExposed;
7+
getSubdirs =
8+
dir:
9+
let
10+
dirContents = builtins.readDir dir; # Reads the current directory
11+
folders = builtins.attrNames (lib.attrsets.filterAttrs (_: type: type == "directory") dirContents);
12+
in
13+
folders;
14+
15+
}

0 commit comments

Comments
 (0)