refactor(nixos): use mkWebApp module to simplify web app definitions

This commit is contained in:
Mohammad Rafiq 2025-06-16 14:55:00 +08:00
parent 2292baecf6
commit a5d8bfcdd5
No known key found for this signature in database
8 changed files with 81 additions and 91 deletions

View file

@ -1,26 +1,26 @@
{ config, lib, ... }:
let
inherit (lib) singleton mkEnableOption mkIf;
cfg = config.server.sd-webui-forge;
inherit (lib) singleton;
inherit (lib.pantheon.modules) mkWebApp;
cfg = config.server.web-apps.sd-webui-forge;
upstreamCfg = config.services.sd-webui-forge;
in
{
options.server.sd-webui-forge = {
enable = mkEnableOption "";
mkWebApp {
inherit config;
name = "sd-webui-forge";
defaultPort = 7860;
persistDirs = singleton {
directory = upstreamCfg.dataDir;
inherit (upstreamCfg) user group;
};
config = mkIf cfg.enable {
extraConfig = {
assertions = singleton {
assertion = config.hardware.gpu == "nvidia";
message = "You must run the sd-webui-forge service only with an nvidia gpu.";
};
persistDirs = singleton {
directory = upstreamCfg.dataDir;
inherit (upstreamCfg) user group;
};
services.sd-webui-forge = {
enable = true;
listen = true;
listen = cfg.openFirewall;
extraArgs = "--cuda-malloc";
};
};