nixpkgs/pkgs/by-name/lo/local-ai/module.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

78 lines
1.6 KiB
Nix
Raw Permalink Normal View History

2024-08-23 15:06:08 -06:00
{
pkgs,
config,
lib,
...
}:
2024-04-26 11:40:55 -06:00
let
cfg = config.services.local-ai;
inherit (lib) mkOption types;
in
{
options.services.local-ai = {
enable = lib.mkEnableOption "local-ai";
2024-04-26 11:40:55 -06:00
package = lib.mkPackageOption pkgs "local-ai" { };
extraArgs = mkOption {
type = types.listOf types.str;
default = [ ];
};
port = mkOption {
type = types.port;
default = 8080;
};
threads = mkOption {
type = types.int;
default = 1;
};
models = mkOption {
type = types.either types.package types.str;
default = "models";
};
2024-05-05 23:46:03 -06:00
parallelRequests = mkOption {
type = types.int;
default = 1;
};
logLevel = mkOption {
2024-08-23 15:06:08 -06:00
type = types.enum [
"error"
"warn"
"info"
"debug"
"trace"
];
2024-05-05 23:46:03 -06:00
default = "warn";
};
2024-04-26 11:40:55 -06:00
};
config = lib.mkIf cfg.enable {
systemd.services.local-ai = {
wantedBy = [ "multi-user.target" ];
2024-05-05 23:46:03 -06:00
environment.LLAMACPP_PARALLEL = toString cfg.parallelRequests;
2024-04-26 11:40:55 -06:00
serviceConfig = {
DynamicUser = true;
2024-08-23 15:06:08 -06:00
ExecStart = lib.escapeShellArgs (
[
"${cfg.package}/bin/local-ai"
"--address=:${toString cfg.port}"
"--threads=${toString cfg.threads}"
"--localai-config-dir=."
"--models-path=${cfg.models}"
"--log-level=${cfg.logLevel}"
]
++ lib.optional (cfg.parallelRequests > 1) "--parallel-requests"
++ cfg.extraArgs
);
2024-04-26 11:40:55 -06:00
RuntimeDirectory = "local-ai";
WorkingDirectory = "%t/local-ai";
};
};
};
}