nixos/navidrome: add user/group options

This commit is contained in:
nu-nu-ko 2024-03-01 12:27:02 +13:00 committed by nuko
parent bbba2bde44
commit 4987663e27
No known key found for this signature in database

View file

@ -12,7 +12,7 @@ let
mkOption mkOption
recursiveUpdate recursiveUpdate
; ;
inherit (lib.types) bool; inherit (lib.types) bool str;
cfg = config.services.navidrome; cfg = config.services.navidrome;
settingsFormat = pkgs.formats.json { }; settingsFormat = pkgs.formats.json { };
in in
@ -37,6 +37,18 @@ in
description = "Configuration for Navidrome, see <https://www.navidrome.org/docs/usage/configuration-options/> for supported values."; description = "Configuration for Navidrome, see <https://www.navidrome.org/docs/usage/configuration-options/> for supported values.";
}; };
user = mkOption {
type = str;
default = "navidrome";
description = "User under which Navidrome runs.";
};
group = mkOption {
type = str;
default = "navidrome";
description = "Group under which Navidrome runs.";
};
openFirewall = mkOption { openFirewall = mkOption {
type = bool; type = bool;
default = false; default = false;
@ -58,7 +70,8 @@ in
ExecStart = '' ExecStart = ''
${cfg.package}/bin/navidrome --configfile ${settingsFormat.generate "navidrome.json" cfg.settings} ${cfg.package}/bin/navidrome --configfile ${settingsFormat.generate "navidrome.json" cfg.settings}
''; '';
DynamicUser = true; User = cfg.user;
Group = cfg.group;
StateDirectory = "navidrome"; StateDirectory = "navidrome";
WorkingDirectory = "/var/lib/navidrome"; WorkingDirectory = "/var/lib/navidrome";
RuntimeDirectory = "navidrome"; RuntimeDirectory = "navidrome";
@ -100,6 +113,16 @@ in
ProtectHostname = true; ProtectHostname = true;
}; };
}; };
users.users = mkIf (cfg.user == "navidrome") {
navidrome = {
inherit (cfg) group;
isSystemUser = true;
};
};
users.groups = mkIf (cfg.group == "navidrome") { navidrome = { }; };
networking.firewall.allowedTCPPorts = mkIf cfg.openFirewall [ cfg.settings.Port ]; networking.firewall.allowedTCPPorts = mkIf cfg.openFirewall [ cfg.settings.Port ];
}; };
} }