Update fooocus and add as subflake

master
Yorick van Pelt 2023-11-14 21:57:15 +01:00
parent 070d64145e
commit e47eb158af
Signed by: yorick
GPG Key ID: D8D3CC6D951384DE
6 changed files with 407 additions and 26 deletions

View File

@ -60,6 +60,45 @@
"type": "github"
}
},
"devshell": {
"flake": false,
"locked": {
"lastModified": 1663445644,
"narHash": "sha256-+xVlcK60x7VY1vRJbNUEAHi17ZuoQxAIH4S4iUFUGBA=",
"owner": "numtide",
"repo": "devshell",
"rev": "e3dc3e21594fe07bdb24bdf1c8657acaa4cb8f66",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "devshell",
"type": "github"
}
},
"dream2nix": {
"inputs": {
"devshell": "devshell",
"flake-compat": "flake-compat",
"flake-parts": "flake-parts",
"nix-unit": "nix-unit",
"nixpkgs": "nixpkgs",
"pre-commit-hooks": "pre-commit-hooks"
},
"locked": {
"lastModified": 1697623956,
"narHash": "sha256-/YfNW+FYOcfcrT3RmvVZMipP9S/F5DFRZ/Hs7lIxD+M=",
"owner": "yorickvP",
"repo": "dream2nix",
"rev": "372c3e8fe1f4ae909cb198dff0b9c6d6127b92eb",
"type": "github"
},
"original": {
"owner": "yorickvP",
"repo": "dream2nix",
"type": "github"
}
},
"emacs-overlay": {
"inputs": {
"flake-utils": "flake-utils",
@ -82,6 +121,22 @@
}
},
"flake-compat": {
"flake": false,
"locked": {
"lastModified": 1673956053,
"narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=",
"owner": "edolstra",
"repo": "flake-compat",
"rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9",
"type": "github"
},
"original": {
"owner": "edolstra",
"repo": "flake-compat",
"type": "github"
}
},
"flake-compat_2": {
"flake": false,
"locked": {
"lastModified": 1668681692,
@ -97,7 +152,7 @@
"type": "github"
}
},
"flake-compat_2": {
"flake-compat_3": {
"locked": {
"lastModified": 1688025799,
"narHash": "sha256-ktpB4dRtnksm9F5WawoIkEneh1nrEvuxb5lJFt1iOyw=",
@ -113,6 +168,28 @@
}
},
"flake-parts": {
"inputs": {
"nixpkgs-lib": [
"fooocus",
"dream2nix",
"nixpkgs"
]
},
"locked": {
"lastModified": 1675933616,
"narHash": "sha256-/rczJkJHtx16IFxMmAWu5nNYcSXNg1YYXTHoGjLrLUA=",
"owner": "hercules-ci",
"repo": "flake-parts",
"rev": "47478a4a003e745402acf63be7f9a092d51b83d7",
"type": "github"
},
"original": {
"owner": "hercules-ci",
"repo": "flake-parts",
"type": "github"
}
},
"flake-parts_2": {
"inputs": {
"nixpkgs-lib": [
"nixpkgs-wayland",
@ -173,6 +250,24 @@
"inputs": {
"systems": "systems_3"
},
"locked": {
"lastModified": 1689068808,
"narHash": "sha256-6ixXo3wt24N/melDWjq70UuHQLxGV8jZvooRanIHXw0=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "919d646de7be200f3bf08cb76ae1f09402b6f9b4",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"flake-utils_4": {
"inputs": {
"systems": "systems_4"
},
"locked": {
"lastModified": 1694529238,
"narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=",
@ -187,6 +282,26 @@
"type": "github"
}
},
"fooocus": {
"inputs": {
"dream2nix": "dream2nix",
"nixpkgs": [
"fooocus",
"dream2nix",
"nixpkgs"
]
},
"locked": {
"lastModified": 1,
"narHash": "sha256-tHWUJkwbjf/NTs2WgvuGwLC48QnY7w2be2+PB45TfDw=",
"path": "./pkgs/fooocus",
"type": "path"
},
"original": {
"path": "./pkgs/fooocus",
"type": "path"
}
},
"home-manager": {
"inputs": {
"nixpkgs": [
@ -231,7 +346,7 @@
},
"lib-aggregate": {
"inputs": {
"flake-utils": "flake-utils_3",
"flake-utils": "flake-utils_4",
"nixpkgs-lib": "nixpkgs-lib"
},
"locked": {
@ -250,9 +365,9 @@
},
"nix-eval-jobs": {
"inputs": {
"flake-parts": "flake-parts",
"nixpkgs": "nixpkgs_2",
"treefmt-nix": "treefmt-nix"
"flake-parts": "flake-parts_2",
"nixpkgs": "nixpkgs_3",
"treefmt-nix": "treefmt-nix_2"
},
"locked": {
"lastModified": 1694654058,
@ -268,6 +383,29 @@
"type": "github"
}
},
"nix-github-actions": {
"inputs": {
"nixpkgs": [
"fooocus",
"dream2nix",
"nix-unit",
"nixpkgs"
]
},
"locked": {
"lastModified": 1688870561,
"narHash": "sha256-4UYkifnPEw1nAzqqPOTL2MvWtm3sNGw1UTYTalkTcGY=",
"owner": "nix-community",
"repo": "nix-github-actions",
"rev": "165b1650b753316aa7f1787f3005a8d2da0f5301",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "nix-github-actions",
"type": "github"
}
},
"nix-index-database": {
"inputs": {
"nixpkgs": [
@ -329,6 +467,35 @@
"type": "github"
}
},
"nix-unit": {
"inputs": {
"flake-parts": [
"fooocus",
"dream2nix",
"flake-parts"
],
"nix-github-actions": "nix-github-actions",
"nixpkgs": [
"fooocus",
"dream2nix",
"nixpkgs"
],
"treefmt-nix": "treefmt-nix"
},
"locked": {
"lastModified": 1694670962,
"narHash": "sha256-HvMq0TJGYSx37zHm4j2d+JUZx4/6X7xKEt/0DeCiwjQ=",
"owner": "adisbladis",
"repo": "nix-unit",
"rev": "3ed2378bddad85257fc508a291408f9ed9673d01",
"type": "github"
},
"original": {
"owner": "adisbladis",
"repo": "nix-unit",
"type": "github"
}
},
"nixos-hardware": {
"locked": {
"lastModified": 1694710316,
@ -346,7 +513,7 @@
"nixos-mailserver": {
"inputs": {
"blobs": "blobs",
"flake-compat": "flake-compat",
"flake-compat": "flake-compat_2",
"nixpkgs": [
"nixpkgs"
],
@ -371,18 +538,17 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1694753796,
"narHash": "sha256-QPE7dqcicQH/nq9aywVXJWWtci4FvxHaM+BSIEbGBvA=",
"owner": "nixos",
"lastModified": 1698318101,
"narHash": "sha256-gUihHt3yPD7bVqg+k/UVHgngyaJ3DMEBchbymBMvK1E=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "360a7d31c30abefdc490d203f80e3221b7a24af2",
"rev": "63678e9f3d3afecfeafa0acead6239cdb447574c",
"type": "github"
},
"original": {
"owner": "nixos",
"ref": "nixos-23.05",
"repo": "nixpkgs",
"type": "github"
"id": "nixpkgs",
"ref": "nixos-unstable",
"type": "indirect"
}
},
"nixpkgs-22_11": {
@ -463,7 +629,7 @@
},
"nixpkgs-wayland": {
"inputs": {
"flake-compat": "flake-compat_2",
"flake-compat": "flake-compat_3",
"lib-aggregate": "lib-aggregate",
"nix-eval-jobs": "nix-eval-jobs",
"nixpkgs": [
@ -485,6 +651,22 @@
}
},
"nixpkgs_2": {
"locked": {
"lastModified": 1694753796,
"narHash": "sha256-QPE7dqcicQH/nq9aywVXJWWtci4FvxHaM+BSIEbGBvA=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "360a7d31c30abefdc490d203f80e3221b7a24af2",
"type": "github"
},
"original": {
"owner": "nixos",
"ref": "nixos-23.05",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs_3": {
"locked": {
"lastModified": 1694651847,
"narHash": "sha256-W+2eI96glLiEwLnX/kWn5HDO7WfKKkF0lKW9yyNLEbY=",
@ -500,17 +682,41 @@
"type": "github"
}
},
"pre-commit-hooks": {
"inputs": {
"flake-utils": "flake-utils_3",
"nixpkgs": [
"fooocus",
"dream2nix",
"nixpkgs"
]
},
"locked": {
"lastModified": 1646153636,
"narHash": "sha256-AlWHMzK+xJ1mG267FdT8dCq/HvLCA6jwmx2ZUy5O8tY=",
"owner": "cachix",
"repo": "pre-commit-hooks.nix",
"rev": "b6bc0b21e1617e2b07d8205e7fae7224036dfa4b",
"type": "github"
},
"original": {
"owner": "cachix",
"repo": "pre-commit-hooks.nix",
"type": "github"
}
},
"root": {
"inputs": {
"agenix": "agenix",
"emacs-overlay": "emacs-overlay",
"flake-utils": "flake-utils_2",
"fooocus": "fooocus",
"home-manager": "home-manager_2",
"nix-index-database": "nix-index-database",
"nix-npm-buildpackage": "nix-npm-buildpackage",
"nixos-hardware": "nixos-hardware",
"nixos-mailserver": "nixos-mailserver",
"nixpkgs": "nixpkgs",
"nixpkgs": "nixpkgs_2",
"nixpkgs-mozilla": "nixpkgs-mozilla",
"nixpkgs-wayland": "nixpkgs-wayland",
"timesync": "timesync"
@ -561,6 +767,21 @@
"type": "github"
}
},
"systems_4": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
},
"timesync": {
"inputs": {
"nix-npm-buildpackage": "nix-npm-buildpackage_2",
@ -583,6 +804,29 @@
}
},
"treefmt-nix": {
"inputs": {
"nixpkgs": [
"fooocus",
"dream2nix",
"nix-unit",
"nixpkgs"
]
},
"locked": {
"lastModified": 1689620039,
"narHash": "sha256-BtNwghr05z7k5YMdq+6nbue+nEalvDepuA7qdQMAKoQ=",
"owner": "numtide",
"repo": "treefmt-nix",
"rev": "719c2977f958c41fa60a928e2fbc50af14844114",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "treefmt-nix",
"type": "github"
}
},
"treefmt-nix_2": {
"inputs": {
"nixpkgs": [
"nixpkgs-wayland",

View File

@ -20,6 +20,7 @@
url = "github:datakami/timesync";
inputs.nixpkgs.follows = "nixpkgs";
};
fooocus.url = "path:./pkgs/fooocus";
};
outputs = inputs@{ nixpkgs, home-manager, nixpkgs-mozilla, emacs-overlay
, nixpkgs-wayland, nixos-hardware, agenix, flake-utils
@ -110,6 +111,7 @@
(final: prev: {
flake-inputs = inputs;
nix-npm-buildpackage = nix-npm-buildpackage.legacyPackages."${final.system}";
fooocus = inputs.fooocus.packages.${final.system}.default;
inherit (nixpkgs-wayland.packages.${final.system}) wldash;
})

View File

@ -5,6 +5,7 @@ let
in {
imports = [
inputs.agenix.nixosModules.default
inputs.fooocus.nixosModules.default
../modules/dashy.nix
../modules/tor-hidden-service.nix
../modules/nginx.nix

View File

@ -22,5 +22,6 @@
packages.x86_64-linux.default = package;
devShells.x86_64-linux.default = package.devShell;
packages.x86_64-linux.lock = package.config.lock.refresh;
nixosModules.default = ./module.nix;
};
}

139
pkgs/fooocus/module.nix Normal file
View File

@ -0,0 +1,139 @@
{ config, lib, pkgs, ... }:
let cfg = config.services.fooocus; in
{
options.services.fooocus = with lib; {
enable = mkEnableOption "Fooocus";
package = mkOption {
type = types.package;
description = "The package name of the Fooocus server";
default = pkgs.fooocus;
};
port = mkOption {
type = types.int;
description = "The port to run the Fooocus server on";
default = 7860;
};
listen = mkOption {
type = types.str;
description = "The address to listen on";
default = "127.0.0.1";
};
path = {
models = mkOption {
type = types.path;
description = "The path to the models directory";
default = "/var/models/Fooocus/models";
};
outputs = mkOption {
type = types.path;
description = "The path to the outputs directory";
default = "/var/sd/outputs/sdxl";
};
checkpoints = mkOption {
type = types.path;
description = "The path to the checkpoints directory";
default = "${cfg.path.models}/checkpoints";
};
loras = mkOption {
type = types.path;
description = "The path to the loras directory";
default = "${cfg.path.models}/loras";
};
embeddings = mkOption {
type = types.path;
description = "The path to the embeddings directory";
default = "${cfg.path.models}/embeddings";
};
vae_approx = mkOption {
type = types.path;
description = "The path to the vae_approx directory";
default = "${cfg.path.models}/vae_approx";
};
upscale_models = mkOption {
type = types.path;
description = "The path to the upscale_models directory";
default = "${cfg.path.models}/upscale_models";
};
inpaint = mkOption {
type = types.path;
description = "The path to the inpaint directory";
default = "${cfg.path.models}/inpaint";
};
controlnet = mkOption {
type = types.path;
description = "The path to the controlnet directory";
default = "${cfg.path.models}/controlnet";
};
clip_vision = mkOption {
type = types.path;
description = "The path to the clip_vision directory";
default = "${cfg.path.models}/clip_vision";
};
fooocus_expansion = mkOption {
type = types.path;
description = "The path to the fooocus_expansion directory";
default = "${cfg.path.models}/prompt_expansion/fooocus_expansion";
};
};
config = mkOption {
type = types.attrsOf types.str;
description = "The configuration for the Fooocus server";
default = {
"path_checkpoints" = "${cfg.path.checkpoints}";
"path_loras" = "${cfg.path.loras}";
"path_embeddings" = "${cfg.path.embeddings}";
"path_vae_approx" = "${cfg.path.vae_approx}";
"path_upscale_models" = "${cfg.path.upscale_models}";
"path_inpaint" = "${cfg.path.inpaint}";
"path_controlnet" = "${cfg.path.controlnet}";
"path_clip_vision" = "${cfg.path.clip_vision}";
"path_fooocus_expansion" = "${cfg.path.fooocus_expansion}";
"path_outputs" = "${cfg.path.outputs}";
};
};
};
config = let
configFile = pkgs.writeText "config.json" (builtins.toJSON cfg.config);
in lib.mkIf cfg.enable {
systemd.services.fooocus = {
description = "Fooocus server";
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
serviceConfig = {
Type = "simple";
# it wants to write for no good reason
# todo: remove these symlinks
ExecStartPre = pkgs.writeShellScript "pre-start" ''
cp ${configFile} /var/lib/fooocus/config.txt
chmod +w /var/lib/fooocus/config.txt
mkdir /tmp/fooocus
ln -sfn ${cfg.package}/javascript /var/lib/fooocus/javascript
ln -sfn ${cfg.package}/css /var/lib/fooocus/css
'';
ExecStart = "${cfg.package}/webui.py --port ${toString cfg.port} --disable-auto-launch --listen ${cfg.listen}";
Restart = "always";
RestartSec = "10";
User = "fooocus";
Group = "fooocus";
PrivateTmp = true;
ProtectSystem = "full";
ProtectHome = true;
NoNewPrivileges = true;
WorkingDirectory = "/var/lib/fooocus";
ReadWritePaths = [
"/var/lib/fooocus"
"/var/models/Fooocus"
"/var/sd/outputs/sdxl"
];
};
};
users.users.fooocus = {
isSystemUser = true;
createHome = true;
group = "fooocus";
home = "/var/lib/fooocus";
};
users.groups.fooocus = {};
};
}

View File

@ -4,24 +4,18 @@
name = "Fooocus";
version = "2.1.807";
# todo
mkDerivation = {
src = config.deps.fetchFromGitHub {
owner = "lllyasviel";
owner = "yorickvP";
repo = config.name;
rev = "515846321686424bb5e61ad9f1912c49c37903eb";
hash = "sha256-gKLkMntmZnfwAyOwivcf8mRmdBSIGQhhHnAaGQgtx40=";
rev = "cc11a770ea8db7573ae58b9b8fc30edabaa4a146";
hash = "sha256-9DV9r1GG3vVwsx+0KYXL3Sd8g5qjSShbBWa1j74BnUs=";
};
buildPhase = "true";
installPhase = ''
mkdir $out
cp -r ./* $out
mv $out/models{,-orig}
ln -s /var/models/Fooocus/models $out/models
ln -s /var/sd/outputs/sdxl $out/outputs
ln -s /var/sd/sdxl-input $out/input
ln -s /var/sd/config.txt $out/config.txt
ln -s /var/sd/config_modification_tutorial.txt $out/config_modification_tutorial.txt
ln -s /tmp/fooocus $out/input
for f in $out/{launch,webui}.py; do
chmod +x $f
sed -i '1s;^;#!/usr/bin/env python\n;' $f