diff options
author | Pol Dellaiera <pol.dellaiera@protonmail.com> | 2024-06-26 22:56:56 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-26 22:56:56 +0200 |
commit | 908c90cd18d5d7d782bb0b895de7fcb6a30b813e (patch) | |
tree | 2485388b7d44c14fe7ee97f1bb7015042e9c3d0c /nixos/modules/services | |
parent | 5b81c5568c0fa7b34778ad8d72d9cd7b094a9b9c (diff) | |
parent | f6727a9e3ee8365e1af3f94931f113fb0c6d37d6 (diff) |
Merge pull request #313606 from drupol/ollama-add-preLoadedModels
nixos/ollama: add `loadModels` config option
Diffstat (limited to 'nixos/modules/services')
-rw-r--r-- | nixos/modules/services/misc/ollama.nix | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/nixos/modules/services/misc/ollama.nix b/nixos/modules/services/misc/ollama.nix index 1467c3f93bc8..c460514783ef 100644 --- a/nixos/modules/services/misc/ollama.nix +++ b/nixos/modules/services/misc/ollama.nix @@ -1,6 +1,6 @@ { config, lib, pkgs, ... }: let - inherit (lib) types; + inherit (lib) types mkBefore; cfg = config.services.ollama; ollamaPackage = cfg.package.override { @@ -132,6 +132,14 @@ in Since `ollama run` is mostly a shell around the ollama server, this is usually sufficient. ''; }; + loadModels = lib.mkOption { + type = types.listOf types.str; + default = [ ]; + description = '' + The models to download as soon as the service starts. + Search for models of your choice from: https://ollama.com/library + ''; + }; openFirewall = lib.mkOption { type = types.bool; default = false; @@ -161,6 +169,14 @@ in DynamicUser = cfg.sandbox; ReadWritePaths = cfg.writablePaths; }; + postStart = mkBefore '' + set -x + export OLLAMA_HOST=${lib.escapeShellArg cfg.host}:${builtins.toString cfg.port} + for model in ${lib.escapeShellArgs cfg.loadModels} + do + ${lib.escapeShellArg (lib.getExe ollamaPackage)} pull "$model" + done + ''; }; networking.firewall = lib.mkIf cfg.openFirewall { allowedTCPPorts = [ cfg.port ]; }; |