mirror of
https://github.com/nix-community/home-manager.git
synced 2025-11-08 19:46:05 +01:00
local-ai: init module (#6718)
This commit is contained in:
parent
50a5766d51
commit
61f2cc5908
5 changed files with 92 additions and 0 deletions
9
modules/misc/news/2025/10/2025-10-31_12-00-00.nix
Normal file
9
modules/misc/news/2025/10/2025-10-31_12-00-00.nix
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
time = "2025-10-31T12:00:00+00:00";
|
||||
condition = true;
|
||||
message = ''
|
||||
services.local-ai: new module
|
||||
|
||||
Added LocalAI, a free, Open Source OpenAI alternative.
|
||||
'';
|
||||
}
|
||||
48
modules/services/local-ai.nix
Normal file
48
modules/services/local-ai.nix
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
{
|
||||
pkgs,
|
||||
config,
|
||||
lib,
|
||||
...
|
||||
}:
|
||||
|
||||
let
|
||||
inherit (lib) types;
|
||||
cfg = config.services.local-ai;
|
||||
in
|
||||
{
|
||||
meta.maintainers = [ lib.maintainers.ipsavitsky ];
|
||||
|
||||
options.services.local-ai = {
|
||||
enable = lib.mkEnableOption "LocalAI is the free, Open Source OpenAI alternative.";
|
||||
|
||||
package = lib.mkPackageOption pkgs "local-ai" { };
|
||||
|
||||
environment = lib.mkOption {
|
||||
type = types.attrsOf types.string;
|
||||
default = { };
|
||||
description = ''
|
||||
Additional environment passed to local-ai service. Used to configure local-ai
|
||||
|
||||
See <https://localai.io/basics> for available options.
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
config = lib.mkIf cfg.enable {
|
||||
systemd.user.services.local-ai = {
|
||||
Unit = {
|
||||
Description = "Server for local large language models";
|
||||
After = [ "network.target" ];
|
||||
};
|
||||
|
||||
Service = {
|
||||
ExecStart = lib.getExe cfg.package;
|
||||
Environment = lib.mapAttrsToList (key: val: "${key}=${val}") cfg.environment;
|
||||
};
|
||||
|
||||
Install = {
|
||||
WantedBy = [ "default.target" ];
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
6
tests/modules/services/local-ai/default.nix
Normal file
6
tests/modules/services/local-ai/default.nix
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
{ lib, pkgs, ... }:
|
||||
|
||||
lib.optionalAttrs pkgs.stdenv.hostPlatform.isLinux {
|
||||
local-ai-enabled = ./enabled.nix;
|
||||
local-ai-enabled-with-environment = ./enabled-with-environment.nix;
|
||||
}
|
||||
20
tests/modules/services/local-ai/enabled-with-environment.nix
Normal file
20
tests/modules/services/local-ai/enabled-with-environment.nix
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
{ ... }:
|
||||
|
||||
{
|
||||
services.local-ai = {
|
||||
enable = true;
|
||||
environment = {
|
||||
MODELS_PATH = "/tmp/models";
|
||||
PRELOAD_MODELS = "[{ \"url\": \"https://huggingface.co/TheBloke/Mistral-7B-Instruct-v0.2-GGUF/resolve/main/mistral-7b-instruct-v0.2.Q4_K_M.gguf\", \"name\": \"mistral-7b-instruct-v0.2.Q4_K_M.gguf\" }]";
|
||||
};
|
||||
};
|
||||
|
||||
nmt.script = ''
|
||||
assertFileContains \
|
||||
home-files/.config/systemd/user/local-ai.service \
|
||||
"Environment=MODELS_PATH=/tmp/models"
|
||||
assertFileContains \
|
||||
home-files/.config/systemd/user/local-ai.service \
|
||||
"Environment=PRELOAD_MODELS=[{ \"url\": \"https://huggingface.co/TheBloke/Mistral-7B-Instruct-v0.2-GGUF/resolve/main/mistral-7b-instruct-v0.2.Q4_K_M.gguf\", \"name\": \"mistral-7b-instruct-v0.2.Q4_K_M.gguf\" }]"
|
||||
'';
|
||||
}
|
||||
9
tests/modules/services/local-ai/enabled.nix
Normal file
9
tests/modules/services/local-ai/enabled.nix
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
{ ... }:
|
||||
|
||||
{
|
||||
services.local-ai.enable = true;
|
||||
|
||||
nmt.script = ''
|
||||
assertFileExists home-files/.config/systemd/user/local-ai.service
|
||||
'';
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue