From 9aaf8fec270cb6be7c5ed761a326536d2708a20d Mon Sep 17 00:00:00 2001 From: Denis Manherz Date: Mon, 27 Nov 2023 13:55:54 +0100 Subject: [PATCH 01/35] A1111 Service --- projects/automatic1111/nixos/default.nix | 45 ++++++++++-------------- 1 file changed, 19 insertions(+), 26 deletions(-) diff --git a/projects/automatic1111/nixos/default.nix b/projects/automatic1111/nixos/default.nix index 716f371..8365e61 100644 --- a/projects/automatic1111/nixos/default.nix +++ b/projects/automatic1111/nixos/default.nix @@ -8,33 +8,33 @@ let floatToString optionalString ; - cfg = config.services.invokeai; + cfg = config.services.a1111; in { - imports = map ({ old, new ? old }: mkRenamedOptionModule [ "services" "invokeai" old ] [ "services" "invokeai" "settings" new ]) [ + imports = map ({ old, new ? old }: mkRenamedOptionModule [ "services" "a1111" old ] [ "services" "a1111" "settings" new ]) [ { old = "host"; } { old = "port"; } { old = "dataDir"; new = "root"; } { old = "precision"; } ]; options.services.invokeai = { - enable = mkEnableOption "InvokeAI Web UI for Stable Diffusion"; + enable = mkEnableOption "Automatic1111 UI for Stable Diffusion"; package = mkOption { - description = "Which InvokeAI package to use."; + description = "Which Automatic1111 package to use."; type = types.package; }; user = mkOption { - description = "Which user to run InvokeAI as."; - default = "invokeai"; + description = "Which user to run A1111 as."; + default = "a1111"; type = types.str; }; group = mkOption { - description = "Which group to run InvokeAI as."; - default = "invokeai"; + description = "Which group to run A1111 as."; + default = "a1111"; type = types.str; }; @@ -52,28 +52,22 @@ in in attrsOf (either atom (listOf atom)); options = { host = mkOption { - description = "Which IP address to listen on."; - default = "127.0.0.1"; - type = types.str; + description = "Launch gradio with 0.0.0.0 as server name, allowing to respond to network requests."; + default = false; + type = types.bool; }; port = mkOption { - description = "Which port to listen on."; - default = 9090; + description = "Launch gradio with given server port, you need root/admin rights for ports < 1024; defaults to 7860 if available."; + default = 7860; type = types.port; }; root = mkOption { - description = "Where to store InvokeAI's state."; - default = "/var/lib/invokeai"; + description = "Where to store A1111's state."; + default = "/var/lib/a1111"; type = types.path; }; - - precision = mkOption { - description = "Set model precision."; - default = "auto"; - type = types.enum [ "auto" "float32" "autocast" "float16" ]; - }; }; }; }; @@ -98,21 +92,20 @@ in ) cfg.settings)) ++ cfg.extraArgs; in mkIf cfg.enable { - users.users = mkIf (cfg.user == "invokeai") { + users.users = mkIf (cfg.user == "a1111") { invokeai = { isSystemUser = true; inherit (cfg) group; }; }; - users.groups = mkIf (cfg.group == "invokeai") { - invokeai = {}; + users.groups = mkIf (cfg.group == "a1111") { + a1111 = {}; }; - systemd.services.invokeai = { + systemd.services.a1111 = { after = [ "network.target" ]; wantedBy = [ "multi-user.target" ]; environment = { HOME = "${cfg.settings.root}/.home"; - INVOKEAI_ROOT = "${cfg.settings.root}"; NIXIFIED_AI_NONINTERACTIVE = "1"; }; serviceConfig = { From b3914b1459cd1ab45d3ce73594e4fe2266ae52bf Mon Sep 17 00:00:00 2001 From: Denis Manherz Date: Mon, 27 Nov 2023 13:59:33 +0100 Subject: [PATCH 02/35] Update --- projects/automatic1111/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/automatic1111/default.nix b/projects/automatic1111/default.nix index 28d2f67..f6b9b52 100644 --- a/projects/automatic1111/default.nix +++ b/projects/automatic1111/default.nix @@ -90,7 +90,7 @@ in in { a1111 = ./nixos; - invokeai-nvidia = { + a1111-nvidia = { imports = [ config.flake.nixosModules.invokeai (packageModule "a1111-nvidia") From 7518e0e3330a043f15f6d62e1bb60c14cbbf992a Mon Sep 17 00:00:00 2001 From: Denis Manherz Date: Mon, 27 Nov 2023 14:07:25 +0100 Subject: [PATCH 03/35] Update --- projects/automatic1111/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/automatic1111/default.nix b/projects/automatic1111/default.nix index f6b9b52..0891904 100644 --- a/projects/automatic1111/default.nix +++ b/projects/automatic1111/default.nix @@ -92,7 +92,7 @@ in a1111 = ./nixos; a1111-nvidia = { imports = [ - config.flake.nixosModules.invokeai + config.flake.nixosModules.a1111 (packageModule "a1111-nvidia") ]; }; From 0b912feb3b5d0ef1d89536e42a107da4b886b95f Mon Sep 17 00:00:00 2001 From: Denis Manherz Date: Mon, 27 Nov 2023 14:09:50 +0100 Subject: [PATCH 04/35] Update --- projects/automatic1111/nixos/default.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/projects/automatic1111/nixos/default.nix b/projects/automatic1111/nixos/default.nix index 8365e61..450a2e9 100644 --- a/projects/automatic1111/nixos/default.nix +++ b/projects/automatic1111/nixos/default.nix @@ -18,7 +18,7 @@ in { old = "dataDir"; new = "root"; } { old = "precision"; } ]; - options.services.invokeai = { + options.services.a1111 = { enable = mkEnableOption "Automatic1111 UI for Stable Diffusion"; package = mkOption { @@ -93,7 +93,7 @@ in in mkIf cfg.enable { users.users = mkIf (cfg.user == "a1111") { - invokeai = { + a1111 = { isSystemUser = true; inherit (cfg) group; }; From bc500968934b5efd17808a73c740cfc5da75f75e Mon Sep 17 00:00:00 2001 From: Denis Manherz Date: Mon, 27 Nov 2023 14:12:50 +0100 Subject: [PATCH 05/35] Update --- projects/bark-gui/default.nix | 16 ++++++++-------- projects/kohya_ss/default.nix | 4 ++-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/projects/bark-gui/default.nix b/projects/bark-gui/default.nix index ec49cb8..6977f34 100644 --- a/projects/bark-gui/default.nix +++ b/projects/bark-gui/default.nix @@ -35,17 +35,17 @@ in flake.nixosModules = let packageModule = pkgAttrName: { pkgs, ... }: { - services.a1111.package = withSystem pkgs.system ( + services.bark-gui.package = withSystem pkgs.system ( { config, ... }: lib.mkOptionDefault config.packages.${pkgAttrName} ); }; in { - bark-gui = ./nixos; - invokeai-nvidia = { - imports = [ - config.flake.nixosModules.invokeai - (packageModule "bark-gui-nvidia") - ]; - }; + #bark-gui = ./nixos; + #invokeai-nvidia = { + # imports = [ + # config.flake.nixosModules.invokeai + # (packageModule "bark-gui-nvidia") + # ]; + #}; }; } diff --git a/projects/kohya_ss/default.nix b/projects/kohya_ss/default.nix index 7c0371a..7ceac8b 100644 --- a/projects/kohya_ss/default.nix +++ b/projects/kohya_ss/default.nix @@ -48,13 +48,13 @@ in kohya_ss = ./nixos; kohya_ss-amd = { imports = [ - config.flake.nixosModules.invokeai + config.flake.nixosModules.kohya_ss (packageModule "kohya_ss-amd") ]; }; kohya_ss-nvidia = { imports = [ - config.flake.nixosModules.invokeai + config.flake.nixosModules.kohya_ss (packageModule "kohya_ss-nvidia") ]; }; From a062543a61ae427e099b1c0bc6243c5b31443781 Mon Sep 17 00:00:00 2001 From: Denis Manherz Date: Mon, 27 Nov 2023 14:24:08 +0100 Subject: [PATCH 06/35] Update --- projects/automatic1111/nixos/default.nix | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/projects/automatic1111/nixos/default.nix b/projects/automatic1111/nixos/default.nix index 450a2e9..cae21b6 100644 --- a/projects/automatic1111/nixos/default.nix +++ b/projects/automatic1111/nixos/default.nix @@ -51,7 +51,7 @@ in ]); in attrsOf (either atom (listOf atom)); options = { - host = mkOption { + listen = mkOption { description = "Launch gradio with 0.0.0.0 as server name, allowing to respond to network requests."; default = false; type = types.bool; @@ -63,7 +63,7 @@ in type = types.port; }; - root = mkOption { + data-dir = mkOption { description = "Where to store A1111's state."; default = "/var/lib/a1111"; type = types.path; @@ -83,7 +83,7 @@ in cliArgs = (flatten (mapAttrsToList (n: v: if v == null then [] - else if isBool v then [ "--${optionalString (!v) "no-"}${n}" ] + else if isBool v then [ "--${optionalString v }--${n}" ] else if isInt v then [ "--${n}" "${toString v}" ] else if isFloat v then [ "--${n}" "${floatToString v}" ] else if isString v then ["--${n}" v ] From 28c02b1f6a7c67ced20f76a7b94b1165afd53fad Mon Sep 17 00:00:00 2001 From: Denis Manherz Date: Mon, 27 Nov 2023 14:28:14 +0100 Subject: [PATCH 07/35] Update --- projects/automatic1111/nixos/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/automatic1111/nixos/default.nix b/projects/automatic1111/nixos/default.nix index cae21b6..e8a6a48 100644 --- a/projects/automatic1111/nixos/default.nix +++ b/projects/automatic1111/nixos/default.nix @@ -83,7 +83,7 @@ in cliArgs = (flatten (mapAttrsToList (n: v: if v == null then [] - else if isBool v then [ "--${optionalString v }--${n}" ] + else if isBool v then [ "--${optionalString v }${n}" ] else if isInt v then [ "--${n}" "${toString v}" ] else if isFloat v then [ "--${n}" "${floatToString v}" ] else if isString v then ["--${n}" v ] From 0f7734670be3f5ff7eef6f1cce13970900ed3fde Mon Sep 17 00:00:00 2001 From: Denis Manherz Date: Mon, 27 Nov 2023 14:30:04 +0100 Subject: [PATCH 08/35] Update --- projects/automatic1111/nixos/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/automatic1111/nixos/default.nix b/projects/automatic1111/nixos/default.nix index e8a6a48..097d5fb 100644 --- a/projects/automatic1111/nixos/default.nix +++ b/projects/automatic1111/nixos/default.nix @@ -83,7 +83,7 @@ in cliArgs = (flatten (mapAttrsToList (n: v: if v == null then [] - else if isBool v then [ "--${optionalString v }${n}" ] + else if isBool v then [ "${optionalString v }--${n}" ] else if isInt v then [ "--${n}" "${toString v}" ] else if isFloat v then [ "--${n}" "${floatToString v}" ] else if isString v then ["--${n}" v ] From bd93aa6e0ef9ca3773ed5eeb8c6b1405556faa0c Mon Sep 17 00:00:00 2001 From: Denis Manherz Date: Mon, 27 Nov 2023 14:32:20 +0100 Subject: [PATCH 09/35] Update --- projects/automatic1111/nixos/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/automatic1111/nixos/default.nix b/projects/automatic1111/nixos/default.nix index 097d5fb..a812fd6 100644 --- a/projects/automatic1111/nixos/default.nix +++ b/projects/automatic1111/nixos/default.nix @@ -83,7 +83,7 @@ in cliArgs = (flatten (mapAttrsToList (n: v: if v == null then [] - else if isBool v then [ "${optionalString v }--${n}" ] + else if isBool v then [ "${optionalString v "--"n}" ] else if isInt v then [ "--${n}" "${toString v}" ] else if isFloat v then [ "--${n}" "${floatToString v}" ] else if isString v then ["--${n}" v ] From 9ff54ac6346e9b754d467e82274e6b8c4ef886db Mon Sep 17 00:00:00 2001 From: Denis Manherz Date: Mon, 27 Nov 2023 14:35:19 +0100 Subject: [PATCH 10/35] Update --- projects/automatic1111/nixos/default.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/projects/automatic1111/nixos/default.nix b/projects/automatic1111/nixos/default.nix index a812fd6..7b6d999 100644 --- a/projects/automatic1111/nixos/default.nix +++ b/projects/automatic1111/nixos/default.nix @@ -82,8 +82,8 @@ in config = let cliArgs = (flatten (mapAttrsToList (n: v: - if v == null then [] - else if isBool v then [ "${optionalString v "--"n}" ] + if v == null then [] + #else if isBool v then [ "--${optionalString (!v) "no-"}${n}" ] else if isInt v then [ "--${n}" "${toString v}" ] else if isFloat v then [ "--${n}" "${floatToString v}" ] else if isString v then ["--${n}" v ] From 0e22c503ac7e9dec490c2815ca768e41047e4ab9 Mon Sep 17 00:00:00 2001 From: Denis Manherz Date: Mon, 27 Nov 2023 14:37:04 +0100 Subject: [PATCH 11/35] Update --- projects/automatic1111/nixos/default.nix | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/projects/automatic1111/nixos/default.nix b/projects/automatic1111/nixos/default.nix index 7b6d999..6859eb4 100644 --- a/projects/automatic1111/nixos/default.nix +++ b/projects/automatic1111/nixos/default.nix @@ -51,11 +51,11 @@ in ]); in attrsOf (either atom (listOf atom)); options = { - listen = mkOption { - description = "Launch gradio with 0.0.0.0 as server name, allowing to respond to network requests."; - default = false; - type = types.bool; - }; + #listen = mkOption { + # description = "Launch gradio with 0.0.0.0 as server name, allowing to respond to network requests."; + # default = false; + # type = types.bool; + #}; port = mkOption { description = "Launch gradio with given server port, you need root/admin rights for ports < 1024; defaults to 7860 if available."; From b1aa03d2015ad985d4cc4358ecbe359227ca8129 Mon Sep 17 00:00:00 2001 From: Denis Manherz Date: Mon, 27 Nov 2023 14:38:19 +0100 Subject: [PATCH 12/35] Update --- projects/automatic1111/nixos/default.nix | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/projects/automatic1111/nixos/default.nix b/projects/automatic1111/nixos/default.nix index 6859eb4..19f1e9e 100644 --- a/projects/automatic1111/nixos/default.nix +++ b/projects/automatic1111/nixos/default.nix @@ -105,7 +105,7 @@ in after = [ "network.target" ]; wantedBy = [ "multi-user.target" ]; environment = { - HOME = "${cfg.settings.root}/.home"; + HOME = "${cfg.settings.data-dir}/.home"; NIXIFIED_AI_NONINTERACTIVE = "1"; }; serviceConfig = { @@ -116,9 +116,9 @@ in }; }; systemd.tmpfiles.rules = [ - "d '${cfg.settings.root}' 0755 ${cfg.user} ${cfg.group} - -" - "d '${cfg.settings.root}/configs' 0755 ${cfg.user} ${cfg.group} - -" - "d '${cfg.settings.root}/.home' 0750 ${cfg.user} ${cfg.group} - -" + "d '${cfg.settings.data-dir}' 0755 ${cfg.user} ${cfg.group} - -" + "d '${cfg.settings.data-dir}/configs' 0755 ${cfg.user} ${cfg.group} - -" + "d '${cfg.settings.data-dir}/.home' 0750 ${cfg.user} ${cfg.group} - -" ]; }; } From b6f8ee2420323a0854ad0bcb5c380c62a886b41c Mon Sep 17 00:00:00 2001 From: Denis Manherz Date: Mon, 27 Nov 2023 14:56:07 +0100 Subject: [PATCH 13/35] Update --- projects/automatic1111/nixos/default.nix | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/projects/automatic1111/nixos/default.nix b/projects/automatic1111/nixos/default.nix index 19f1e9e..f75703e 100644 --- a/projects/automatic1111/nixos/default.nix +++ b/projects/automatic1111/nixos/default.nix @@ -106,12 +106,13 @@ in wantedBy = [ "multi-user.target" ]; environment = { HOME = "${cfg.settings.data-dir}/.home"; + COMMANDLINE_ARGS = ''${cliArgs}''; NIXIFIED_AI_NONINTERACTIVE = "1"; }; serviceConfig = { User = cfg.user; Group = cfg.group; - ExecStart = "${getExe cfg.package} ${escapeShellArgs cliArgs}"; + ExecStart = "${getExe cfg.package} ${escapeShellArgs}"; PrivateTmp = true; }; }; From 811b606bac3f94f4b5c5c23a421607e34129a08c Mon Sep 17 00:00:00 2001 From: Denis Manherz Date: Mon, 27 Nov 2023 14:58:33 +0100 Subject: [PATCH 14/35] Update --- projects/automatic1111/nixos/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/automatic1111/nixos/default.nix b/projects/automatic1111/nixos/default.nix index f75703e..33da86f 100644 --- a/projects/automatic1111/nixos/default.nix +++ b/projects/automatic1111/nixos/default.nix @@ -112,7 +112,7 @@ in serviceConfig = { User = cfg.user; Group = cfg.group; - ExecStart = "${getExe cfg.package} ${escapeShellArgs}"; + ExecStart = "${getExe cfg.package}"; PrivateTmp = true; }; }; From 201072da3d28bb2b68a90f488115da0ac0876a8d Mon Sep 17 00:00:00 2001 From: Denis Manherz Date: Mon, 27 Nov 2023 15:00:06 +0100 Subject: [PATCH 15/35] Update --- projects/automatic1111/nixos/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/automatic1111/nixos/default.nix b/projects/automatic1111/nixos/default.nix index 33da86f..9e91164 100644 --- a/projects/automatic1111/nixos/default.nix +++ b/projects/automatic1111/nixos/default.nix @@ -106,7 +106,7 @@ in wantedBy = [ "multi-user.target" ]; environment = { HOME = "${cfg.settings.data-dir}/.home"; - COMMANDLINE_ARGS = ''${cliArgs}''; + COMMANDLINE_ARGS = escapShellArgs cliArgs; NIXIFIED_AI_NONINTERACTIVE = "1"; }; serviceConfig = { From 3122edf0c96990af0901b0e55816e83bd33038f9 Mon Sep 17 00:00:00 2001 From: Denis Manherz Date: Mon, 27 Nov 2023 15:00:36 +0100 Subject: [PATCH 16/35] Update --- projects/automatic1111/nixos/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/automatic1111/nixos/default.nix b/projects/automatic1111/nixos/default.nix index 9e91164..ef42ce6 100644 --- a/projects/automatic1111/nixos/default.nix +++ b/projects/automatic1111/nixos/default.nix @@ -106,7 +106,7 @@ in wantedBy = [ "multi-user.target" ]; environment = { HOME = "${cfg.settings.data-dir}/.home"; - COMMANDLINE_ARGS = escapShellArgs cliArgs; + COMMANDLINE_ARGS = escapeShellArgs cliArgs; NIXIFIED_AI_NONINTERACTIVE = "1"; }; serviceConfig = { From d6a880fefbcaa0cbfb5c9bcf69711c585e84041f Mon Sep 17 00:00:00 2001 From: Denis Manherz Date: Mon, 27 Nov 2023 15:20:37 +0100 Subject: [PATCH 17/35] Update --- projects/automatic1111/nixos/default.nix | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/projects/automatic1111/nixos/default.nix b/projects/automatic1111/nixos/default.nix index ef42ce6..f13294b 100644 --- a/projects/automatic1111/nixos/default.nix +++ b/projects/automatic1111/nixos/default.nix @@ -68,6 +68,12 @@ in default = "/var/lib/a1111"; type = types.path; }; + + data-dir = mkOption { + description = "Path to A1111's SD models."; + default = "/var/lib/models/ckpt"; + type = types.path; + }; }; }; }; From 902151b0ad4e1504dd85dcf702c7c62bd5ad6e98 Mon Sep 17 00:00:00 2001 From: Denis Manherz Date: Mon, 27 Nov 2023 15:22:38 +0100 Subject: [PATCH 18/35] Update --- projects/automatic1111/nixos/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/automatic1111/nixos/default.nix b/projects/automatic1111/nixos/default.nix index f13294b..a8bf63a 100644 --- a/projects/automatic1111/nixos/default.nix +++ b/projects/automatic1111/nixos/default.nix @@ -69,7 +69,7 @@ in type = types.path; }; - data-dir = mkOption { + ckpt-dir = mkOption { description = "Path to A1111's SD models."; default = "/var/lib/models/ckpt"; type = types.path; From b5f9fb6f0dcb373bc4de8713c1f94837aa3511a2 Mon Sep 17 00:00:00 2001 From: Denis Manherz Date: Mon, 27 Nov 2023 17:54:32 +0100 Subject: [PATCH 19/35] Update --- projects/automatic1111/nixos/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/automatic1111/nixos/default.nix b/projects/automatic1111/nixos/default.nix index a8bf63a..312d69e 100644 --- a/projects/automatic1111/nixos/default.nix +++ b/projects/automatic1111/nixos/default.nix @@ -123,7 +123,7 @@ in }; }; systemd.tmpfiles.rules = [ - "d '${cfg.settings.data-dir}' 0755 ${cfg.user} ${cfg.group} - -" + "d '${cfg.settings.data-dir}/*' 0755 ${cfg.user} ${cfg.group} - -" "d '${cfg.settings.data-dir}/configs' 0755 ${cfg.user} ${cfg.group} - -" "d '${cfg.settings.data-dir}/.home' 0750 ${cfg.user} ${cfg.group} - -" ]; From d896b23f4817d49563ca49e68923ad669158a174 Mon Sep 17 00:00:00 2001 From: Denis Manherz Date: Mon, 27 Nov 2023 17:59:48 +0100 Subject: [PATCH 20/35] Update --- projects/automatic1111/nixos/default.nix | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/projects/automatic1111/nixos/default.nix b/projects/automatic1111/nixos/default.nix index 312d69e..71a1ba4 100644 --- a/projects/automatic1111/nixos/default.nix +++ b/projects/automatic1111/nixos/default.nix @@ -123,9 +123,10 @@ in }; }; systemd.tmpfiles.rules = [ - "d '${cfg.settings.data-dir}/*' 0755 ${cfg.user} ${cfg.group} - -" + "d '${cfg.settings.data-dir}/' 0755 ${cfg.user} ${cfg.group} - -" "d '${cfg.settings.data-dir}/configs' 0755 ${cfg.user} ${cfg.group} - -" "d '${cfg.settings.data-dir}/.home' 0750 ${cfg.user} ${cfg.group} - -" + "chmod -R 0755 '${cfg.settings.data-dir}'" ]; }; } From 1eb72237158cdebc12d9a3fac974ae00da59290f Mon Sep 17 00:00:00 2001 From: Denis Manherz Date: Mon, 27 Nov 2023 18:03:04 +0100 Subject: [PATCH 21/35] Revert "Update" This reverts commit d896b23f4817d49563ca49e68923ad669158a174. --- projects/automatic1111/nixos/default.nix | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/projects/automatic1111/nixos/default.nix b/projects/automatic1111/nixos/default.nix index 71a1ba4..312d69e 100644 --- a/projects/automatic1111/nixos/default.nix +++ b/projects/automatic1111/nixos/default.nix @@ -123,10 +123,9 @@ in }; }; systemd.tmpfiles.rules = [ - "d '${cfg.settings.data-dir}/' 0755 ${cfg.user} ${cfg.group} - -" + "d '${cfg.settings.data-dir}/*' 0755 ${cfg.user} ${cfg.group} - -" "d '${cfg.settings.data-dir}/configs' 0755 ${cfg.user} ${cfg.group} - -" "d '${cfg.settings.data-dir}/.home' 0750 ${cfg.user} ${cfg.group} - -" - "chmod -R 0755 '${cfg.settings.data-dir}'" ]; }; } From 426c5d444ada622710d5934769f85b5dc5f294b0 Mon Sep 17 00:00:00 2001 From: Denis Manherz Date: Mon, 27 Nov 2023 18:06:14 +0100 Subject: [PATCH 22/35] Update --- projects/automatic1111/nixos/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/automatic1111/nixos/default.nix b/projects/automatic1111/nixos/default.nix index 312d69e..f28afc5 100644 --- a/projects/automatic1111/nixos/default.nix +++ b/projects/automatic1111/nixos/default.nix @@ -123,7 +123,7 @@ in }; }; systemd.tmpfiles.rules = [ - "d '${cfg.settings.data-dir}/*' 0755 ${cfg.user} ${cfg.group} - -" + "d '${cfg.settings.data-dir}/' 0755 ${cfg.user} ${cfg.group} - -" "d '${cfg.settings.data-dir}/configs' 0755 ${cfg.user} ${cfg.group} - -" "d '${cfg.settings.data-dir}/.home' 0750 ${cfg.user} ${cfg.group} - -" ]; From 20bfaab47eac347b5227d83b02f6082c4a732167 Mon Sep 17 00:00:00 2001 From: Denis Manherz Date: Wed, 29 Nov 2023 22:15:27 +0100 Subject: [PATCH 23/35] Infinite Image Browser deps --- projects/automatic1111/package.nix | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/projects/automatic1111/package.nix b/projects/automatic1111/package.nix index faa8fac..2199779 100644 --- a/projects/automatic1111/package.nix +++ b/projects/automatic1111/package.nix @@ -39,6 +39,12 @@ python3Packages.buildPythonPackage { torch transformers xformers + + #For Extensions + #pyfunctional #infinite image browser + python-dotenv #infinite image browser + fastapi #infinite image browser + uvicorn #infinite image browser ]; patches = [ ./_outputpaths.patch ]; @@ -111,4 +117,7 @@ python3Packages.buildPythonPackage { homepage = "https://github.com/AUTOMATIC1111/stable-diffusion-webui"; mainProgram = "launch-wrapped.py"; }; + + #Tiled VAE supported without additional dependencies + #Infinit image browser } From ac32c8a937b5e038967854b193980d3a52eb5b07 Mon Sep 17 00:00:00 2001 From: Denis Manherz Date: Wed, 29 Nov 2023 22:29:53 +0100 Subject: [PATCH 24/35] Infinite image browser deps --- packages/pyfunctional/default.nix | 24 ++++++++++++++++++++++++ projects/automatic1111/default.nix | 1 + projects/automatic1111/package.nix | 2 +- 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 packages/pyfunctional/default.nix diff --git a/packages/pyfunctional/default.nix b/packages/pyfunctional/default.nix new file mode 100644 index 0000000..7a95608 --- /dev/null +++ b/packages/pyfunctional/default.nix @@ -0,0 +1,24 @@ + +{ buildPythonPackage, lib, fetchPypi +}: + +buildPythonPackage rec { + pname = "PyFunctional"; + version = "1.4.3"; + + src = fetchPypi { + inherit pname version; + sha256 = "sha256-EcMT/iUbJpxlBmiRNUVqBbxab6EpydArRF84PU9BHhA="; + }; + + propagatedBuildInputs = [ + ]; + + # TODO FIXME + doCheck = false; + + meta = with lib; { + description = "PyFunctional makes creating data pipelines easy by using chained functional operators."; + homepage = "https://github.com/EntilZha/PyFunctional"; + }; +} diff --git a/projects/automatic1111/default.nix b/projects/automatic1111/default.nix index 0891904..21a17d2 100644 --- a/projects/automatic1111/default.nix +++ b/projects/automatic1111/default.nix @@ -38,6 +38,7 @@ in ../../packages/lpips ../../packages/openclip ../../packages/pillow + ../../packages/pyfunctional ../../packages/pytorch-lightning ../../packages/realesrgan ../../packages/taming-transformers-rom1504 diff --git a/projects/automatic1111/package.nix b/projects/automatic1111/package.nix index 2199779..613303e 100644 --- a/projects/automatic1111/package.nix +++ b/projects/automatic1111/package.nix @@ -41,7 +41,7 @@ python3Packages.buildPythonPackage { xformers #For Extensions - #pyfunctional #infinite image browser + pyfunctional #infinite image browser python-dotenv #infinite image browser fastapi #infinite image browser uvicorn #infinite image browser From 14315178ef9cf1b3f13517a87a13042a4c6f9b01 Mon Sep 17 00:00:00 2001 From: Denis Manherz Date: Wed, 29 Nov 2023 22:46:28 +0100 Subject: [PATCH 25/35] Infinite image browser deps done --- projects/automatic1111/package.nix | 2 ++ 1 file changed, 2 insertions(+) diff --git a/projects/automatic1111/package.nix b/projects/automatic1111/package.nix index 613303e..998ac17 100644 --- a/projects/automatic1111/package.nix +++ b/projects/automatic1111/package.nix @@ -42,9 +42,11 @@ python3Packages.buildPythonPackage { #For Extensions pyfunctional #infinite image browser + dill #infinite image browser python-dotenv #infinite image browser fastapi #infinite image browser uvicorn #infinite image browser + tabulate #infinite image browser ]; patches = [ ./_outputpaths.patch ]; From f8f97aad01ec34643d0249e37cf79f0138c6d5ca Mon Sep 17 00:00:00 2001 From: Denis Manherz Date: Wed, 29 Nov 2023 23:02:44 +0100 Subject: [PATCH 26/35] +deps for civitai browser + --- projects/automatic1111/default.nix | 1 + projects/automatic1111/package.nix | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/projects/automatic1111/default.nix b/projects/automatic1111/default.nix index 21a17d2..c89fcd0 100644 --- a/projects/automatic1111/default.nix +++ b/projects/automatic1111/default.nix @@ -46,6 +46,7 @@ in ../../packages/torch-fidelity ../../packages/torch-grammar ../../packages/xformers + ../../packages/zipunicode ]) (final: prev: lib.mapAttrs (_: pkg: pkg.overrideAttrs (old: { diff --git a/projects/automatic1111/package.nix b/projects/automatic1111/package.nix index 998ac17..8e8aad1 100644 --- a/projects/automatic1111/package.nix +++ b/projects/automatic1111/package.nix @@ -47,6 +47,10 @@ python3Packages.buildPythonPackage { fastapi #infinite image browser uvicorn #infinite image browser tabulate #infinite image browser + #infinite image browser sends dleted images to nirvana + + send2trash #civitai browser+ + zipunicode #civitai browser+ ]; patches = [ ./_outputpaths.patch ]; @@ -121,5 +125,6 @@ python3Packages.buildPythonPackage { }; #Tiled VAE supported without additional dependencies - #Infinit image browser + #Infinit image browser couple of deps + #civit-ai browser + couple of deps } From f3bd801137f70e365ec16143827583885bb874ce Mon Sep 17 00:00:00 2001 From: Denis Manherz Date: Wed, 29 Nov 2023 23:19:34 +0100 Subject: [PATCH 27/35] +deps Adetailer --- projects/automatic1111/default.nix | 2 ++ projects/automatic1111/package.nix | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/projects/automatic1111/default.nix b/projects/automatic1111/default.nix index c89fcd0..9f7b5af 100644 --- a/projects/automatic1111/default.nix +++ b/projects/automatic1111/default.nix @@ -36,6 +36,7 @@ in ../../packages/gradio-client ../../packages/k_diffusion ../../packages/lpips + ../../packages/mediapipe ../../packages/openclip ../../packages/pillow ../../packages/pyfunctional @@ -45,6 +46,7 @@ in ../../packages/tomesd ../../packages/torch-fidelity ../../packages/torch-grammar + ../../packages/ultralytics ../../packages/xformers ../../packages/zipunicode ]) diff --git a/projects/automatic1111/package.nix b/projects/automatic1111/package.nix index 8e8aad1..27b6241 100644 --- a/projects/automatic1111/package.nix +++ b/projects/automatic1111/package.nix @@ -40,7 +40,7 @@ python3Packages.buildPythonPackage { transformers xformers - #For Extensions + #For Extensions -- dont know if e.g you dont install image browser then maybe lack of dep for civitai browser pyfunctional #infinite image browser dill #infinite image browser python-dotenv #infinite image browser @@ -51,6 +51,11 @@ python3Packages.buildPythonPackage { send2trash #civitai browser+ zipunicode #civitai browser+ + + rich #adetailer + ultralytics #adetailer + py-cpuinfo #adetailer + mediapipe #adeteailer ]; patches = [ ./_outputpaths.patch ]; From ad2f6121290239c4cbee62ca745d554fb107b21b Mon Sep 17 00:00:00 2001 From: Denis Manherz Date: Thu, 30 Nov 2023 12:04:35 +0100 Subject: [PATCH 28/35] +deps Civitai browser + --- projects/automatic1111/package.nix | 2 ++ 1 file changed, 2 insertions(+) diff --git a/projects/automatic1111/package.nix b/projects/automatic1111/package.nix index 27b6241..ea874c4 100644 --- a/projects/automatic1111/package.nix +++ b/projects/automatic1111/package.nix @@ -51,6 +51,7 @@ python3Packages.buildPythonPackage { send2trash #civitai browser+ zipunicode #civitai browser+ + fake-useragent #civitai browser+ rich #adetailer ultralytics #adetailer @@ -132,4 +133,5 @@ python3Packages.buildPythonPackage { #Tiled VAE supported without additional dependencies #Infinit image browser couple of deps #civit-ai browser + couple of deps + #animatediff } From f878b1291a3026b0f57b1b3061974061d09d49c4 Mon Sep 17 00:00:00 2001 From: Denis Manherz Date: Thu, 30 Nov 2023 12:38:08 +0100 Subject: [PATCH 29/35] +deps Animatediff, deforum --- projects/automatic1111/default.nix | 1 + projects/automatic1111/package.nix | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/projects/automatic1111/default.nix b/projects/automatic1111/default.nix index 9f7b5af..8ce53b7 100644 --- a/projects/automatic1111/default.nix +++ b/projects/automatic1111/default.nix @@ -30,6 +30,7 @@ in ../../packages/blendmodes ../../packages/blip ../../packages/codeformer + ../../packages/deforum ../../packages/facexlib ../../packages/gfpgan ../../packages/gradio diff --git a/projects/automatic1111/package.nix b/projects/automatic1111/package.nix index ea874c4..e07bf98 100644 --- a/projects/automatic1111/package.nix +++ b/projects/automatic1111/package.nix @@ -57,6 +57,11 @@ python3Packages.buildPythonPackage { ultralytics #adetailer py-cpuinfo #adetailer mediapipe #adeteailer + + av #animatediff to create webm and other fileformats + + numexpr #deforum + deforum #deforum ]; patches = [ ./_outputpaths.patch ]; @@ -133,5 +138,6 @@ python3Packages.buildPythonPackage { #Tiled VAE supported without additional dependencies #Infinit image browser couple of deps #civit-ai browser + couple of deps - #animatediff + #animatediff --> needs deforum for frame interpolation + #deforum } From fb68dcf306dd7c194e011a6aab035f4c4b5d14b4 Mon Sep 17 00:00:00 2001 From: Denis Manherz Date: Sat, 2 Dec 2023 01:26:06 +0100 Subject: [PATCH 30/35] Update --- projects/automatic1111/default.nix | 2 +- projects/automatic1111/package.nix | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/projects/automatic1111/default.nix b/projects/automatic1111/default.nix index 8ce53b7..a8efa3c 100644 --- a/projects/automatic1111/default.nix +++ b/projects/automatic1111/default.nix @@ -48,7 +48,7 @@ in ../../packages/torch-fidelity ../../packages/torch-grammar ../../packages/ultralytics - ../../packages/xformers +# ../../packages/xformers ../../packages/zipunicode ]) (final: prev: lib.mapAttrs diff --git a/projects/automatic1111/package.nix b/projects/automatic1111/package.nix index e07bf98..a487da1 100644 --- a/projects/automatic1111/package.nix +++ b/projects/automatic1111/package.nix @@ -140,4 +140,5 @@ python3Packages.buildPythonPackage { #civit-ai browser + couple of deps #animatediff --> needs deforum for frame interpolation #deforum + #controlnet } From 11df30301122e72b2dfc119779a3fcb9737c12f6 Mon Sep 17 00:00:00 2001 From: Denis Manherz Date: Sat, 2 Dec 2023 01:40:14 +0100 Subject: [PATCH 31/35] Update --- projects/automatic1111/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/automatic1111/default.nix b/projects/automatic1111/default.nix index a8efa3c..8ce53b7 100644 --- a/projects/automatic1111/default.nix +++ b/projects/automatic1111/default.nix @@ -48,7 +48,7 @@ in ../../packages/torch-fidelity ../../packages/torch-grammar ../../packages/ultralytics -# ../../packages/xformers + ../../packages/xformers ../../packages/zipunicode ]) (final: prev: lib.mapAttrs From d12a51a9d5d14253c17fb76ae829a516b4f84805 Mon Sep 17 00:00:00 2001 From: Denis Manherz Date: Sat, 2 Dec 2023 01:45:55 +0100 Subject: [PATCH 32/35] Update --- packages/xformers/default.nix | 4 ++-- projects/automatic1111/package.nix | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/xformers/default.nix b/packages/xformers/default.nix index f0a2eae..4040463 100644 --- a/packages/xformers/default.nix +++ b/packages/xformers/default.nix @@ -2,7 +2,7 @@ # If you run pynixify again, the file will be either overwritten or # deleted, and you will lose the changes you made to it. -{ buildPythonPackage, fetchPypi, lib, torch, numpy, pyre-extensions, pythonRelaxDepsHook, which }: +{ buildPythonPackage, fetchPypi, lib, torchWithCuda, numpy, pyre-extensions, pythonRelaxDepsHook, which }: buildPythonPackage rec { pname = "xformers"; @@ -14,7 +14,7 @@ buildPythonPackage rec { }; nativeBuildInputs = [ pythonRelaxDepsHook which ]; pythonRelaxDeps = [ "pyre-extensions" ]; - propagatedBuildInputs = [ torch numpy pyre-extensions /*triton*/ ]; + propagatedBuildInputs = [ torchWithCuda numpy pyre-extensions /*triton*/ ]; # TODO FIXME doCheck = false; diff --git a/projects/automatic1111/package.nix b/projects/automatic1111/package.nix index a487da1..8b8f224 100644 --- a/projects/automatic1111/package.nix +++ b/projects/automatic1111/package.nix @@ -36,7 +36,7 @@ python3Packages.buildPythonPackage { taming-transformers-rom1504 timm tomesd - torch + torchWithCuda transformers xformers From 28aff58462c5ec6bad0cfc57121e0e4afea41b9c Mon Sep 17 00:00:00 2001 From: Denis Manherz Date: Sat, 2 Dec 2023 12:44:48 +0000 Subject: [PATCH 33/35] Update default.nix xformers --- packages/xformers/default.nix | 101 ++++++++++++++++++++++++++++------ 1 file changed, 85 insertions(+), 16 deletions(-) diff --git a/packages/xformers/default.nix b/packages/xformers/default.nix index 4040463..bf2d415 100644 --- a/packages/xformers/default.nix +++ b/packages/xformers/default.nix @@ -1,23 +1,92 @@ -# WARNING: This file was automatically generated. You should avoid editing it. -# If you run pynixify again, the file will be either overwritten or -# deleted, and you will lose the changes you made to it. - -{ buildPythonPackage, fetchPypi, lib, torchWithCuda, numpy, pyre-extensions, pythonRelaxDepsHook, which }: - -buildPythonPackage rec { +{ lib +, buildPythonPackage +, pythonOlder +, fetchFromGitHub +, which +# runtime dependencies +, numpy +, torch +# check dependencies +, pytestCheckHook +, pytest-cov +# , pytest-mpi +, pytest-timeout +# , pytorch-image-models +, hydra-core +, fairscale +, scipy +, cmake +, openai-triton +, networkx +#, apex +, einops +, transformers +, timm +#, flash-attn +}: +let + version = "0.0.22.post7"; +in +buildPythonPackage { pname = "xformers"; - version = "0.0.16"; + inherit version; + format = "setuptools"; - src = fetchPypi { - inherit pname version; - sha256 = "sha256-ksfwVWpo9EhkkmkbP1ZxQO4ZK1Y9kEGFtmabH4u4rlM="; + disabled = pythonOlder "3.7"; + + src = fetchFromGitHub { + owner = "facebookresearch"; + repo = "xformers"; + rev = "refs/tags/v${version}"; + hash = "sha256-7lZi3+2dVDZJFYCUlxsyDU8t9qdnl+b2ERRXKA6Zp7U="; + fetchSubmodules = true; }; - nativeBuildInputs = [ pythonRelaxDepsHook which ]; - pythonRelaxDeps = [ "pyre-extensions" ]; - propagatedBuildInputs = [ torchWithCuda numpy pyre-extensions /*triton*/ ]; - # TODO FIXME + preBuild = '' + cat << EOF > ./xformers/version.py + # noqa: C801 + __version__ = "${version}" + EOF + ''; + + nativeBuildInputs = [ + which + ]; + + propagatedBuildInputs = [ + numpy + torch + ]; + + pythonImportsCheck = [ "xformers" ]; + + dontUseCmakeConfigure = true; + + # see commented out missing packages doCheck = false; - meta = with lib; { }; + nativeCheckInputs = [ + pytestCheckHook + pytest-cov + pytest-timeout + hydra-core + fairscale + scipy + cmake + networkx + openai-triton + # apex + einops + transformers + timm + # flash-attn + ]; + + meta = with lib; { + description = "XFormers: A collection of composable Transformer building blocks"; + homepage = "https://github.com/facebookresearch/xformers"; + changelog = "https://github.com/facebookresearch/xformers/blob/${version}/CHANGELOG.md"; + license = licenses.bsd3; + maintainers = with maintainers; [ happysalada ]; + }; } From f9fe0957dc683a0f2925e222ab4803a7632ea438 Mon Sep 17 00:00:00 2001 From: Denis Manherz Date: Sun, 17 Dec 2023 21:03:43 +0100 Subject: [PATCH 34/35] Update --- flake.nix | 2 +- projects/automatic1111/default.nix | 14 +++++++++++--- projects/automatic1111/package.nix | 7 +++++-- projects/invokeai/package.nix | 2 +- projects/textgen/package.nix | 2 ++ 5 files changed, 20 insertions(+), 7 deletions(-) diff --git a/flake.nix b/flake.nix index 2c738c1..d2d1b17 100644 --- a/flake.nix +++ b/flake.nix @@ -53,7 +53,7 @@ outputs = { flake-parts, invokeai-src, hercules-ci-effects, ... }@inputs: flake-parts.lib.mkFlake { inherit inputs; } { perSystem = { system, ... }:{ - _module.args.pkgs = import inputs.nixpkgs { config.allowUnfree = true; inherit system; }; + _module.args.pkgs = import inputs.nixpkgs { config.allowUnfree = true; inherit system; cudaSupport = true; }; legacyPackages = { koboldai = builtins.throw '' diff --git a/projects/automatic1111/default.nix b/projects/automatic1111/default.nix index 8ce53b7..a8696ea 100644 --- a/projects/automatic1111/default.nix +++ b/projects/automatic1111/default.nix @@ -45,8 +45,8 @@ in ../../packages/realesrgan ../../packages/taming-transformers-rom1504 ../../packages/tomesd - ../../packages/torch-fidelity - ../../packages/torch-grammar + #../../packages/torch-fidelity + #../../packages/torch-grammar ../../packages/ultralytics ../../packages/xformers ../../packages/zipunicode @@ -74,8 +74,16 @@ in ]); }; + stable-pkgs = import inputs.nixpkgs-stable { + allowUnfree = true; + cudaSupport = true; + inherit system; + }; + src = inputs.a1111-src; - mkAutomatic1111Variant = args: pkgs.callPackage ./package.nix ({ inherit src; sd-src = inputs.sd-src; sgm-src = inputs.sgm-src; } // args); + mkAutomatic1111Variant = args: pkgs.callPackage ./package.nix ({ + inherit src; sd-src = inputs.sd-src; sgm-src = inputs.sgm-src; inherit stable-pkgs pkgs; + } // args); in { packages = { diff --git a/projects/automatic1111/package.nix b/projects/automatic1111/package.nix index 8b8f224..fa065ce 100644 --- a/projects/automatic1111/package.nix +++ b/projects/automatic1111/package.nix @@ -4,6 +4,8 @@ , # misc lib , src +, stable-pkgs +, pkgs # extra deps }: python3Packages.buildPythonPackage { @@ -36,7 +38,8 @@ python3Packages.buildPythonPackage { taming-transformers-rom1504 timm tomesd - torchWithCuda + #torchWithCuda + #torch-bin transformers xformers @@ -62,7 +65,7 @@ python3Packages.buildPythonPackage { numexpr #deforum deforum #deforum - ]; + ]; patches = [ ./_outputpaths.patch ]; diff --git a/projects/invokeai/package.nix b/projects/invokeai/package.nix index 93e4ec8..3b72309 100644 --- a/projects/invokeai/package.nix +++ b/projects/invokeai/package.nix @@ -76,7 +76,7 @@ python3Packages.buildPythonPackage { huggingface-hub easing-functions dynamicprompts - torchvision + torchvision-bin test-tube ]; nativeBuildInputs = with python3Packages; [ pythonRelaxDepsHook pip ]; diff --git a/projects/textgen/package.nix b/projects/textgen/package.nix index face144..8b40e4c 100644 --- a/projects/textgen/package.nix +++ b/projects/textgen/package.nix @@ -76,12 +76,14 @@ let ln -s ${tmpDir}/presets/ $out/presets ''; textgenPython = python3Packages.python.withPackages (_: with python3Packages; [ + aiofiles accelerate bitsandbytes colorama datasets flexgen gradio + gradio-client llama-cpp-python markdown numpy From a227d57d285fffc261188ec244bda16a7b4ff0dd Mon Sep 17 00:00:00 2001 From: Denis Manherz Date: Thu, 11 Jan 2024 18:13:38 +0100 Subject: [PATCH 35/35] Update --- flake.lock | 17 ++++ flake.nix | 44 ++++++++-- packages/xformers/default.nix | 89 +++++++++++++++++++- projects/automatic1111/default.nix | 3 +- projects/automatic1111/package.nix | 9 +- projects/bark-gui/package.nix | 6 +- projects/comfyui/default.nix | 40 +++++++++ projects/comfyui/nixos/default.nix | 131 +++++++++++++++++++++++++++++ projects/comfyui/package.nix | 70 +++++++++++++++ projects/invokeai/package.nix | 1 + 10 files changed, 389 insertions(+), 21 deletions(-) create mode 100644 projects/comfyui/default.nix create mode 100644 projects/comfyui/nixos/default.nix create mode 100644 projects/comfyui/package.nix diff --git a/flake.lock b/flake.lock index a596135..fadc031 100644 --- a/flake.lock +++ b/flake.lock @@ -32,6 +32,22 @@ "type": "github" } }, + "comfyui-src": { + "flake": false, + "locked": { + "lastModified": 1702736172, + "narHash": "sha256-BYZHfnhdubasOAhUyq/iW4HvYKPiqBwiXY3ozZXU1Oc=", + "owner": "comfyanonymous", + "repo": "ComfyUI", + "rev": "6453dc1ca2d98d89af7cf312bb48d1e3fd2ca27f", + "type": "github" + }, + "original": { + "owner": "comfyanonymous", + "repo": "ComfyUI", + "type": "github" + } + }, "flake-parts": { "inputs": { "nixpkgs-lib": [ @@ -251,6 +267,7 @@ "inputs": { "a1111-src": "a1111-src", "bark-gui-src": "bark-gui-src", + "comfyui-src": "comfyui-src", "flake-parts": "flake-parts", "hercules-ci-effects": "hercules-ci-effects", "invokeai-src": "invokeai-src", diff --git a/flake.nix b/flake.nix index d2d1b17..e5adfce 100644 --- a/flake.nix +++ b/flake.nix @@ -7,6 +7,10 @@ description = "A Nix Flake that makes AI reproducible and easy to run"; inputs = { + comfyui-src = { + url = github:comfyanonymous/ComfyUI; + flake = false; + }; nixpkgs-stable = { url = github:NixOS/nixpkgs/nixos-23.05; }; @@ -52,17 +56,38 @@ }; outputs = { flake-parts, invokeai-src, hercules-ci-effects, ... }@inputs: flake-parts.lib.mkFlake { inherit inputs; } { - perSystem = { system, ... }:{ - _module.args.pkgs = import inputs.nixpkgs { config.allowUnfree = true; inherit system; cudaSupport = true; }; + perSystem = { system, ... }: { + # _module.args.pkgs = import inputs.nixpkgs { config.allowUnfree = true; inherit system; config.cudaSupport = true; }; + _module.args.pkgs = import inputs.nixpkgs { + inherit system; + /*overlays = [ + ( + final: prev: { + final.python310 = prev.python310.override { + enableOptimizations = true; + reproducibleBuild = false; + self = final.python310; + buildInputs = [ final.ffmpeg-full ]; + }; + pythonPackagesExtensions = prev.pythonPackagesExtensions ++ [ + ( + python-final: python-prev: { + torch = python-prev.torch-bin; + } + ) + ]; + } + ) + ];*/ + config = { allowUnfree = true; cudaSupport = true; }; + }; legacyPackages = { koboldai = builtins.throw '' + koboldai has been dropped from nixified.ai due to lack of upstream development, + try textgen instead which is better maintained. If you would like to use the last + available version of koboldai with nixified.ai, then run: - - koboldai has been dropped from nixified.ai due to lack of upstream development, - try textgen instead which is better maintained. If you would like to use the last - available version of koboldai with nixified.ai, then run: - - nix run github:nixified.ai/flake/0c58f8cba3fb42c54f2a7bf9bd45ee4cbc9f2477#koboldai + nix run github:nixified.ai/flake/0c58f8cba3fb42c54f2a7bf9bd45ee4cbc9f2477#koboldai ''; }; }; @@ -72,8 +97,9 @@ debug = true; imports = [ hercules-ci-effects.flakeModule -# ./modules/nixpkgs-config + # ./modules/nixpkgs-config ./overlays + ./projects/comfyui ./projects/automatic1111 ./projects/invokeai ./projects/textgen diff --git a/packages/xformers/default.nix b/packages/xformers/default.nix index bf2d415..1f251d0 100644 --- a/packages/xformers/default.nix +++ b/packages/xformers/default.nix @@ -23,8 +23,53 @@ , transformers , timm #, flash-attn +, cudaPackages +, stable-pkgs }: let + inherit (cudaPackages) cudaFlags cudnn; + + # Some packages are not available on all platforms + nccl = cudaPackages.nccl or null; + + setBool = v: if v then "1" else "0"; + + # https://github.com/pytorch/pytorch/blob/v2.0.1/torch/utils/cpp_extension.py#L1744 + supportedTorchCudaCapabilities = + let + real = ["3.5" "3.7" "5.0" "5.2" "5.3" "6.0" "6.1" "6.2" "7.0" "7.2" "7.5" "8.0" "8.6" "8.7" "8.9" "9.0"]; + ptx = lists.map (x: "${x}+PTX") real; + in + real ++ ptx; + + # NOTE: The lists.subtractLists function is perhaps a bit unintuitive. It subtracts the elements + # of the first list *from* the second list. That means: + # lists.subtractLists a b = b - a + + # For CUDA + supportedCudaCapabilities = lists.intersectLists cudaFlags.cudaCapabilities supportedTorchCudaCapabilities; + unsupportedCudaCapabilities = lists.subtractLists supportedCudaCapabilities cudaFlags.cudaCapabilities; + + # Use trivial.warnIf to print a warning if any unsupported GPU targets are specified. + gpuArchWarner = supported: unsupported: + trivial.throwIf (supported == [ ]) + ( + "No supported GPU targets specified. Requested GPU targets: " + + strings.concatStringsSep ", " unsupported + ) + supported; + + # Create the gpuTargetString. + gpuTargetString = strings.concatStringsSep ";" ( + if gpuTargets != [ ] then + # If gpuTargets is specified, it always takes priority. + gpuTargets + else if rocmSupport then + rocmPackages.clr.gpuTargets + else + gpuArchWarner supportedCudaCapabilities unsupportedCudaCapabilities + ); + version = "0.0.22.post7"; in buildPythonPackage { @@ -42,6 +87,16 @@ buildPythonPackage { fetchSubmodules = true; }; + preConfigure = '' + export TORCH_CUDA_ARCH_LIST="${gpuTargetString}" + export CUDNN_INCLUDE_DIR=${cudnn.dev}/include + export CUDNN_LIB_DIR=${cudnn.lib}/lib + export CUPTI_INCLUDE_DIR=${cudaPackages.cuda_cupti.dev}/include + export CUPTI_LIBRARY_DIR=${cudaPackages.cuda_cupti.lib}/lib + export CUDA_PATH=${stable-packages.cudatoolkit} + export EXTRA_LD_FLAGS="-L${stable-pkgs.linuxPackages.nvidia_x11_production}/lib" + ''; + preBuild = '' cat << EOF > ./xformers/version.py # noqa: C801 @@ -51,13 +106,43 @@ buildPythonPackage { nativeBuildInputs = [ which - ]; + ] ++ (with cudaPackages; [ + autoAddOpenGLRunpathHook + cuda_nvcc + ]); propagatedBuildInputs = [ numpy torch ]; + buildInputs = with cudaPackages; [ + cuda_cccl.dev # + cuda_cudart # cuda_runtime.h and libraries + cuda_cupti.dev # For kineto + cuda_cupti.lib # For kineto + cuda_nvcc.dev # crt/host_config.h; even though we include this in nativeBuildinputs, it's needed here too + cuda_nvml_dev.dev # + cuda_nvrtc.dev + cuda_nvrtc.lib + cuda_nvtx.dev + cuda_nvtx.lib # -llibNVToolsExt + cudnn.dev + cudnn.lib + libcublas.dev + libcublas.lib + libcufft.dev + libcufft.lib + libcurand.dev + libcurand.lib + libcusolver.dev + libcusolver.lib + libcusparse.dev + libcusparse.lib + effectiveMagma + numactl + ] ++ [stable-pkgs.linuxPackages.nvidia_x11_production gcc stable-packages.cudatoolkit]; + pythonImportsCheck = [ "xformers" ]; dontUseCmakeConfigure = true; @@ -89,4 +174,4 @@ buildPythonPackage { license = licenses.bsd3; maintainers = with maintainers; [ happysalada ]; }; -} +} \ No newline at end of file diff --git a/projects/automatic1111/default.nix b/projects/automatic1111/default.nix index a8696ea..df9d281 100644 --- a/projects/automatic1111/default.nix +++ b/projects/automatic1111/default.nix @@ -13,11 +13,11 @@ in #cant i do like only for this for invoke other version? ( final: prev: { - pillow = pkgs.python3.pkgs.callPackage ../../packages/pillow { }; pythonPackagesExtensions = prev.pythonPackagesExtensions ++ [ ( python-final: python-prev: { pillow = python-final.callPackage ../../packages/pillow { }; + xformers = python-final.callPackage ../../packages/xformers { inherit stable-pkgs; }; } ) ]; @@ -48,7 +48,6 @@ in #../../packages/torch-fidelity #../../packages/torch-grammar ../../packages/ultralytics - ../../packages/xformers ../../packages/zipunicode ]) (final: prev: lib.mapAttrs diff --git a/projects/automatic1111/package.nix b/projects/automatic1111/package.nix index fa065ce..0ed4bd9 100644 --- a/projects/automatic1111/package.nix +++ b/projects/automatic1111/package.nix @@ -38,8 +38,7 @@ python3Packages.buildPythonPackage { taming-transformers-rom1504 timm tomesd - #torchWithCuda - #torch-bin + torchWithCuda transformers xformers @@ -69,6 +68,8 @@ python3Packages.buildPythonPackage { patches = [ ./_outputpaths.patch ]; + nativeBuildInputs = [ pkgs.cudatoolkit ]; + buildPhase = '' runHook preBuild @@ -96,12 +97,12 @@ python3Packages.buildPythonPackage { chmod +x launch.py makeWrapper "$out/launch.py" $out/bin/launch-wrapped.py \ --run 'export COMMANDLINE_ARGS="''${COMMANDLINE_ARGS:-\ - --data-dir $HOME/webui --skip-install \ + --data-dir $HOME/webui --skip-install --xformers \ --theme dark --ckpt-dir $HOME/webui/models/ckpt \ --embeddings-dir $HOME/webui/models/embeddings \ --medvram --no-half-vae}"' \ --set-default PYTHONPATH $PYTHONPATH \ - --chdir $out + --chdir $out --set-default CUDA_PATH ${pkgs.cudatoolkit} rm -rf dist diff --git a/projects/bark-gui/package.nix b/projects/bark-gui/package.nix index 3c88e3c..e80a7e2 100644 --- a/projects/bark-gui/package.nix +++ b/projects/bark-gui/package.nix @@ -20,15 +20,13 @@ python3Packages.buildPythonPackage { pytorch-seed safetensors scipy - torch-bin - torchaudio-bin + torch + torchaudio transformers vector-quantize-pytorch ]; #nativeBuildInputs = with python3Packages; [ pythonRelaxDepsHook pip ]; nativeBuildInputs = with python3Packages; [ setuptools pip ]; - #pythonRemoveDeps = [ "clip" "pyreadline3" "flaskwebgui" "opencv-python" ]; - pythonRelaxDeps = [ "dnspython" "flask" "requests" "numpy" "pytorch-lightning" "torchsde" "uvicorn" "invisible-watermark" "accelerate" "scikit-image" "safetensors" "torchvision" "test-tube" "fastapi" ]; makeWrapperArgs = [ '' --set-default PYTHONPATH=$PYTHONPATH '' diff --git a/projects/comfyui/default.nix b/projects/comfyui/default.nix new file mode 100644 index 0000000..0750e0d --- /dev/null +++ b/projects/comfyui/default.nix @@ -0,0 +1,40 @@ +{ config, inputs, lib, withSystem, ... }: +{ + perSystem = { config, pkgs, system, ... }: + let + src = inputs.comfyui-src; + + stable-pkgs = import inputs.nixpkgs-stable { + allowUnfree = true; + cudaSupport = true; + inherit system; + }; + + mkComfyUIVariant = args: pkgs.python310Packages.callPackage ./package.nix ({ + inherit src; + } // args); + in + { + packages = { + comfyui-nvidia = mkComfyUIVariant { }; + }; + }; + + #flake.nixosModules = + /* let + packageModule = pkgAttrName: { pkgs, ... }: { + services.comfyui.package = withSystem pkgs.system ( + { config, ... }: lib.mkOptionDefault config.packages.${pkgAttrName} + ); + }; + in + { + comfyui = ./nixos; + comfyui-nvidia = { + imports = [ + config.flake.nixosModules.a1111 + (packageModule "comfyui-nvidia") + ]; + }; + };*/ +} diff --git a/projects/comfyui/nixos/default.nix b/projects/comfyui/nixos/default.nix new file mode 100644 index 0000000..efbede4 --- /dev/null +++ b/projects/comfyui/nixos/default.nix @@ -0,0 +1,131 @@ +{ config, lib, ... }: + +let + inherit (lib) + mkIf mkOption mkEnableOption mkRenamedOptionModule types + escapeShellArgs flatten getExe mapAttrsToList + isBool isFloat isInt isList isString + floatToString optionalString + ; + + cfg = config.services.comfyui; +in + +{ + imports = map ({ old, new ? old }: mkRenamedOptionModule [ "services" "comfyui" old ] [ "services" "comfyui" "settings" new ]) [ + { old = "host"; } + { old = "port"; } + { old = "dataDir"; new = "root"; } + { old = "precision"; } + ]; + options.services.a1111 = { + enable = mkEnableOption "Automatic1111 UI for Stable Diffusion"; + + package = mkOption { + description = "Which Automatic1111 package to use."; + type = types.package; + }; + + user = mkOption { + description = "Which user to run A1111 as."; + default = "a1111"; + type = types.str; + }; + + group = mkOption { + description = "Which group to run A1111 as."; + default = "a1111"; + type = types.str; + }; + + settings = mkOption { + description = "Structured command line arguments."; + default = { }; + type = types.submodule { + freeformType = with types; let + atom = nullOr (oneOf [ + bool + str + int + float + ]); + in attrsOf (either atom (listOf atom)); + options = { + #listen = mkOption { + # description = "Launch gradio with 0.0.0.0 as server name, allowing to respond to network requests."; + # default = false; + # type = types.bool; + #}; + + port = mkOption { + description = "Launch gradio with given server port, you need root/admin rights for ports < 1024; defaults to 7860 if available."; + default = 7860; + type = types.port; + }; + + data-dir = mkOption { + description = "Where to store A1111's state."; + default = "/var/lib/a1111"; + type = types.path; + }; + + ckpt-dir = mkOption { + description = "Path to A1111's SD models."; + default = "/var/lib/models/ckpt"; + type = types.path; + }; + }; + }; + }; + + extraArgs = mkOption { + description = "Additional raw command line arguments."; + default = []; + type = with types; listOf str; + }; + }; + + config = let + + cliArgs = (flatten (mapAttrsToList (n: v: + if v == null then [] + #else if isBool v then [ "--${optionalString (!v) "no-"}${n}" ] + else if isInt v then [ "--${n}" "${toString v}" ] + else if isFloat v then [ "--${n}" "${floatToString v}" ] + else if isString v then ["--${n}" v ] + else if isList v then [ "--${n}" (toString v) ] + else throw "Unhandled type for setting \"${n}\"" + ) cfg.settings)) ++ cfg.extraArgs; + + in mkIf cfg.enable { + users.users = mkIf (cfg.user == "a1111") { + a1111 = { + isSystemUser = true; + inherit (cfg) group; + }; + }; + users.groups = mkIf (cfg.group == "a1111") { + a1111 = {}; + }; + systemd.services.a1111 = { + after = [ "network.target" ]; + wantedBy = [ "multi-user.target" ]; + environment = { + HOME = "${cfg.settings.data-dir}/.home"; + COMMANDLINE_ARGS = escapeShellArgs cliArgs; + NIXIFIED_AI_NONINTERACTIVE = "1"; + }; + serviceConfig = { + User = cfg.user; + Group = cfg.group; + ExecStart = "${getExe cfg.package}"; + PrivateTmp = true; + }; + }; + systemd.tmpfiles.rules = [ + "d '${cfg.settings.data-dir}/' 0755 ${cfg.user} ${cfg.group} - -" + "d '${cfg.settings.data-dir}/configs' 0755 ${cfg.user} ${cfg.group} - -" + "d '${cfg.settings.data-dir}/.home' 0750 ${cfg.user} ${cfg.group} - -" + ]; + }; +} diff --git a/projects/comfyui/package.nix b/projects/comfyui/package.nix new file mode 100644 index 0000000..dd06fe1 --- /dev/null +++ b/projects/comfyui/package.nix @@ -0,0 +1,70 @@ +{ src +, buildPythonPackage +, torchvision-bin +, torch-bin +, safetensors +, psutil +, einops +, transformers +, scipy +, torchsde +, pillow +, torch +, torchvision +, accelerate +}: +buildPythonPackage { + pname = "ComfyUI"; + format = "other"; + version = "latest"; + inherit src; + propagatedBuildInputs = [ + accelerate + torchvision + torch + safetensors + psutil + einops + transformers + scipy + pillow + torchsde + ]; + + buildPhase = + '' + runHook preBuild + + mkdir -p dist + cp -R . $out + chmod -R +w $out + cd $out + + #make main.py executable > shebang + mkdir -p $out/bin + cat <<-EOF > main.py + $(echo "#!/usr/bin/python") + $(cat main.py) + EOF + chmod +x main.py + makeWrapper "$out/main.py" $out/bin/main-wrapped.py \ + --set-default PYTHONPATH $PYTHONPATH \ + + rm -rf dist + + runHook postBuild + ''; + + meta = { + description = "The most powerful and modular stable diffusion GUI and backend."; + homepage = "https://github.com/comfyanonymous/ComfyUI.git"; + mainProgram = "main-wrapped.py"; + }; + + #Tiled VAE supported without additional dependencies + #Infinit image browser couple of deps + #civit-ai browser + couple of deps + #animatediff --> needs deforum for frame interpolation + #deforum + #controlnet +} diff --git a/projects/invokeai/package.nix b/projects/invokeai/package.nix index 3b72309..5da44b4 100644 --- a/projects/invokeai/package.nix +++ b/projects/invokeai/package.nix @@ -2,6 +2,7 @@ # misc , lib , src +, pkgs # extra deps }: