Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: nixified webui #16887

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
use flake
watch_file uv.lock
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,5 @@ notification.mp3
/cache
trace.json
/sysinfo-????-??-??-??-??.json
.direnv
result
170 changes: 170 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

76 changes: 76 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{
description = "Django application using uv2nix";

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";

pyproject-nix = {
url = "github:pyproject-nix/pyproject.nix";
inputs.nixpkgs.follows = "nixpkgs";
};

uv2nix = {
url = "github:pyproject-nix/uv2nix";
inputs.pyproject-nix.follows = "pyproject-nix";
inputs.nixpkgs.follows = "nixpkgs";
};

pyproject-build-systems = {
url = "github:pyproject-nix/build-system-pkgs";
inputs.pyproject-nix.follows = "pyproject-nix";
inputs.uv2nix.follows = "uv2nix";
inputs.nixpkgs.follows = "nixpkgs";
};

uv2nix-hammer-overrides = {
url = "github:TyberiusPrime/uv2nix_hammer_overrides";
inputs.nixpkgs.follows = "nixpkgs";
};
};

outputs =
inputs@{
self,
nixpkgs,
pyproject-nix,
pyproject-build-systems,
uv2nix,
uv2nix-hammer-overrides,

...
}:
let
lib = nixpkgs.lib.extend (
self: _: {
flake = import ./nix/lib (
{
lib = self;
}
// inputs
);
}
);
package-name = "stable-diffusion-webui";
pythonSets = import ./pythonSets.nix ({ inherit lib; } // inputs);
allArgs = inputs // {
inherit lib package-name pythonSets;
};

nixDirs = lib.flake.getSubdirs ./nix;
importFolder = (
name: {
name = name;
value =

import ./nix/${name} allArgs;
}
);
in
{
asgiApp = "django_webapp.asgi:application";
settingsModules = {
prod = "django_webapp.settings";
};
}
// builtins.listToAttrs (map importFolder nixDirs);
}
19 changes: 19 additions & 0 deletions nix/checks/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
lib,
self,
package-name,
...
}:
lib.flake.forAllSystems (
system:
let
mainPkg = self.packages.${system}.${package-name};
in

rec {
inherit (mainPkg) tests;
inherit (mainPkg.tests) mypy pytest nixos;
default = pytest;
}

)
34 changes: 34 additions & 0 deletions nix/devShells/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
args@{
lib,
self,
package-name,
pythonSets,
nixpkgs,
...
}:
lib.flake.forAllSystems (
system:
let
pkgs = import nixpkgs {
inherit system;
config.allowUnfree = true;
};
pythonSet = pythonSets.${system};
folders = lib.flake.getSubdirs ./.;
folderAttrs = (
name: {
name = name;
value = import ./${name} (
args
// {
inherit pkgs system pythonSet;
}
); # You can replace this with any value
}
);
in
builtins.listToAttrs (map folderAttrs folders)
// {
default = self.devShells.${system}.${package-name};
}
)
25 changes: 25 additions & 0 deletions nix/devShells/init/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
pkgs,
lib,
system,
self,
...
}:
let
inherit (self.packages.${system}) venv;
in
pkgs.mkShell {
packages = [
pkgs.uv
pkgs.python310
];
env = {
UV_NO_SYNC = "1";
UV_PYTHON = "${pkgs.python310}";
UV_PYTHON_DOWNLOADS = "never";
};
shellHook = ''
unset PYTHONPATH
export REPO_ROOT=$(git rev-parse --show-toplevel)
'';
}
25 changes: 25 additions & 0 deletions nix/devShells/stable-diffusion-webui/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
pkgs,
lib,
self,
system,
...
}:
let
venv = self.packages.${system}.venv;
in
pkgs.mkShell {
packages = [
venv
pkgs.uv
];
env = {
UV_NO_SYNC = "1";
UV_PYTHON = "${venv}/bin/python";
UV_PYTHON_DOWNLOADS = "never";
};
shellHook = ''
unset PYTHONPATH
export REPO_ROOT=$(git rev-parse --show-toplevel)
'';
}
15 changes: 15 additions & 0 deletions nix/lib/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
lib,
...
}:
{
forAllSystems = lib.genAttrs lib.systems.flakeExposed;
getSubdirs =
dir:
let
dirContents = builtins.readDir dir; # Reads the current directory
folders = builtins.attrNames (lib.attrsets.filterAttrs (_: type: type == "directory") dirContents);
in
folders;

}
Loading
Loading