Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add textgen nixos module #79

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion projects/textgen/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ in
flake.nixosModules = let
packageModule = pkgAttrName: { pkgs, ... }: {
services.textgen.package = withSystem pkgs.system (
{ config, ... }: lib.mkOptionDefault config.packages.${pkgAttrName}
{ config, ... }:
lib.mkOptionDefault (config.packages.${pkgAttrName}.override {
stateDir = "/var/lib/textgen";
})
);
};
in {
Expand Down
102 changes: 102 additions & 0 deletions projects/textgen/nixos/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
{ config, lib, ... }:
with lib;
let
cfg = config.services.textgen;
in
{
options.services.textgen = {
enable = mkEnableOption (mdDoc "A WebUI for LLMs and LoRA training");
package = mkOption {
description = "textgen package to use.";
type = types.package;
};
user = mkOption {
type = types.str;
default = "textgen";
description = mdDoc "User account under which textgen runs.";
};
group = mkOption {
type = types.str;
default = "textgen";
description = mdDoc "Group under which textgen runs.";
};
settings = mkOption {
description = mdDoc ''
Attrset that is converted to settings.yaml.
See: <https://github.com/oobabooga/text-generation-webui/blob/main/settings-template.yaml>
'';
type = types.attrs;
default = { };
};
settingsFile = mkOption {
description = mdDoc ''
Path to settings.yaml.
This will override {option}`services.textgen.settings`.
'';
type = with types; nullOr path;
# Error when settings.yaml is empty.
default = if cfg.setting == { } then null else toYAML cfg.settings;
};
extraArgs = mkOption {
description = "Additional command line arguments.";
default = [ ];
type = with types; listOf str;
};
};

config = mkIf cfg.enable {
systemd.services.textgen = {
description = "A WebUI for LLMs and LoRA training";
wantedBy = [ "multi-user.target" ];
after = [ "network.target" ];
serviceConfig = {
Restart = "on-failure";
MountAPIVFS = true;
ProtectProc = "invisible";
User = cfg.user;
Group = cfg.group;
CapabilityBoundingSet = [ "" ];
NoNewPrivileges = true;
ProtectSystem = "strict";
ProtectHome = "yes";
RuntimeDirectory = "textgen";
StateDirectory = "textgen";
CacheDirectory = "textgen";
PrivateTmp = true;
PrivateIPC = true;
PrivateUsers = true;
ProtectHostname = true;
ProtectClock = true;
ProtectKernelTunables = true;
ProtectKernelModules = true;
ProtectKernelLogs = true;
ProtectControlGroups = true;
RestrictNamespaces = true;
LockPersonality = true;
MemoryDenyWriteExecute = true;
RestrictRealtime = true;
RestrictSUIDSGID = true;
RemoveIPC = true;
PrivateMounts = true;
SystemCallArchitectures = [ "native" ];
SystemCallFilter = [ "@system-service" ];
ExecStart = let
args = cfg.extraArgs ++ mkIf (cfg.settingsFile != null)
[ "--settings" "${cfg.settingsFile}" ];
in "${cfg.package}/bin/textgen ${escapeShellArgs cfg.extraArgs}";
};
};

users.users = mkIf (cfg.user == "textgen") {
textgen = {
description = "textgen Service";
inherit (cfg) group;
isSystemUser = true;
};
};

users.groups = mkIf (cfg.group == "textgen") {
textgen = {};
};
};
}