diff --git a/flake.nix b/flake.nix index c4f6b8c..fb98040 100644 --- a/flake.nix +++ b/flake.nix @@ -20,71 +20,83 @@ inputs.process-compose-flake.flakeModule ]; debug = true; - perSystem = { self', pkgs, config, system, ... }: { - _module.args.pkgs = import inputs.nixpkgs { - inherit system; - # Required for CUDA - config.allowUnfree = true; - overlays = [ - (self: _: with self; { - open-webui-frontend = callPackage (import ./nix/open-webui-frontend.nix { inherit inputs; }) { }; - }) - ]; - }; - packages.open-webui-backend = inputs.dream2nix.lib.evalModules { - packageSets.nixpkgs = inputs.dream2nix.inputs.nixpkgs.legacyPackages.${system}; - specialArgs = { inherit inputs; }; - modules = [ - ./nix/open-webui-backend + perSystem = { self', pkgs, config, system, ... }: + let + open-webui-backend-module = inputs.dream2nix.lib.evalModules { + packageSets.nixpkgs = inputs.dream2nix.inputs.nixpkgs.legacyPackages.${system}; + specialArgs = { inherit inputs; }; + modules = [ + ./nix/open-webui-backend + { + paths.projectRoot = ./.; + # can be changed to ".git" or "flake.nix" to get rid of .project-root + paths.projectRootFile = "flake.nix"; + paths.package = ./nix/open-webui-backend; + } + ]; + }; + in + { + _module.args.pkgs = import inputs.nixpkgs { + inherit system; + # Required for CUDA + config.allowUnfree = true; + overlays = [ + (self: _: with self; { + open-webui-frontend = callPackage (import ./nix/open-webui-frontend.nix { inherit inputs; }) { }; + }) + ]; + }; + + packages = { + # Generate the `pdm.lock` file in `nix/open-webui-backend` + open-webui-backend-lock = open-webui-backend-module.lock; + # Generate the `pyproject.toml` file in `nix/open-webui-backend` + open-webui-backend-req2py = open-webui-backend-module.req2py; + open-webui-backend-pyEnv = open-webui-backend-module.pyEnv; + }; + + process-compose = + let + common = { ... }: { + imports = [ + inputs.services-flake.processComposeModules.default + (import ./nix/ollama.nix { inherit self' inputs; }) + ]; + services.ollama-stack.enable = true; + }; + in { - paths.projectRoot = ./.; - # can be changed to ".git" or "flake.nix" to get rid of .project-root - paths.projectRootFile = "flake.nix"; - paths.package = ./nix/open-webui-backend; - } - ]; - }; - process-compose = - let - common = { ... }: { - imports = [ - inputs.services-flake.processComposeModules.default - (import ./nix/ollama.nix { inherit self' inputs; }) - ]; - services.ollama-stack.enable = true; - }; - in - { - default = { - imports = [ common ]; - services.ollama-stack.open-webui.enable = true; - }; - cuda = { - imports = [ common ]; - services.ollama-stack.extraOllamaConfig = { - package = pkgs.ollama.override { acceleration = "cuda"; }; - extraEnvs = { - # # See https://github.com/ollama/ollama/blob/9768e2dc7574c36608bb04ac39a3b79e639a837f/docs/gpu.md?plain=1#L32-L38 - # CUDA_VISIBLE_DEVICES = "0,2"; + default = { + imports = [ common ]; + services.ollama-stack.open-webui.enable = true; + }; + cuda = { + imports = [ common ]; + services.ollama-stack.extraOllamaConfig = { + package = pkgs.ollama.override { acceleration = "cuda"; }; + extraEnvs = { + # # See https://github.com/ollama/ollama/blob/9768e2dc7574c36608bb04ac39a3b79e639a837f/docs/gpu.md?plain=1#L32-L38 + # CUDA_VISIBLE_DEVICES = "0,2"; + }; }; }; - }; - rocm = { - imports = [ common ]; - services.ollama-stack.extraOllamaConfig = { - package = pkgs.ollama.override { acceleration = "rocm"; }; - extraEnvs = { - # # See https://github.com/ollama/ollama/blob/9768e2dc7574c36608bb04ac39a3b79e639a837f/docs/gpu.md?plain=1#L55-L86 - # HSA_OVERRIDE_GFX_VERSION = “10.3.0”; - # # See docs: https://rocm.docs.amd.com/en/latest/conceptual/gpu-isolation.html#rocr-visible-devices - # ROCR_VISIBLE_DEVICES = "0,GPU-DEADBEEFDEADBEEF"; - # # See https://rocm.docs.amd.com/en/latest/conceptual/gpu-isolation.html#hip-visible-devices - # HIP_VISIBLE_DEVICES = "0,2"; + rocm = { + imports = [ common ]; + services.ollama-stack.extraOllamaConfig = { + package = pkgs.ollama.override { acceleration = "rocm"; }; + extraEnvs = { + # # See https://github.com/ollama/ollama/blob/9768e2dc7574c36608bb04ac39a3b79e639a837f/docs/gpu.md?plain=1#L55-L86 + # HSA_OVERRIDE_GFX_VERSION = “10.3.0”; + # # See docs: https://rocm.docs.amd.com/en/latest/conceptual/gpu-isolation.html#rocr-visible-devices + # ROCR_VISIBLE_DEVICES = "0,GPU-DEADBEEFDEADBEEF"; + # # See https://rocm.docs.amd.com/en/latest/conceptual/gpu-isolation.html#hip-visible-devices + # HIP_VISIBLE_DEVICES = "0,2"; + }; }; }; }; - }; - }; + }; }; } diff --git a/garnix.yaml b/garnix.yaml new file mode 100644 index 0000000..d98688d --- /dev/null +++ b/garnix.yaml @@ -0,0 +1,4 @@ +builds: + include: + - "*.aarch64-darwin.*" + - "*.x86_64-linux.*" diff --git a/nix/ollama.nix b/nix/ollama.nix index 39dbc35..e859489 100644 --- a/nix/ollama.nix +++ b/nix/ollama.nix @@ -49,7 +49,7 @@ { command = pkgs.writeShellApplication { name = "open-webui"; - runtimeInputs = [ self'.packages.open-webui-backend.pyEnv ]; + runtimeInputs = [ self'.packages.open-webui-backend-pyEnv ]; text = '' set -x # TODO: make a service and give it a dataDir option diff --git a/nix/open-webui-backend/README.md b/nix/open-webui-backend/README.md index 660c2bd..53ea2b4 100644 --- a/nix/open-webui-backend/README.md +++ b/nix/open-webui-backend/README.md @@ -5,12 +5,12 @@ This package depends on `pyproject.toml` and `pdm.lock` file. The `pyproject.tom To generate the `pyproject.toml` run: ```sh -nix run .#open-webui-backend.req2py +nix run .#open-webui-backend-req2py ``` And to generate the `pdm.lock` file: ```sh -nix run .#open-webui-backend.lock +nix run .#open-webui-backend-lock ```