modules/betanin: spring cleaning prepping for upstream
Some checks failed
CI / checks (nur) (push) Successful in 3m24s
CI / build-and-update (xeals, xeals) (push) Successful in 18m39s
Update flake inputs / update-flake (push) Failing after 44s

This commit is contained in:
xeals 2024-08-15 15:24:13 +10:00
parent 706e911539
commit cf0dcee23f
Signed by: xeals
SSH Key Fingerprint: SHA256:pRv+8swQDA+/LuZ7NHj9m006BbKexlNK62OUA01ZZBc

View File

@ -6,15 +6,11 @@ let
cfg = config.services.betanin;
defaultUser = "betanin";
defaultGroup = "betanin";
settingsFormat = pkgs.formats.toml { };
beetsFormat = pkgs.formats.yaml { };
in
{
options = {
services.betanin = {
options.services.betanin = {
enable = lib.mkEnableOption "betanin";
package = mkOption {
@ -38,13 +34,13 @@ in
user = mkOption {
description = "User that the betanin program should run under.";
type = types.str;
default = defaultUser;
default = "betanin";
};
group = mkOption {
description = "Group that the betanin program should run under.";
type = types.str;
default = defaultGroup;
default = "betanin";
};
dataDir = mkOption {
@ -60,7 +56,7 @@ in
{
frontend = {
username = "foo";
password { _secret = "/run/secrets/betaninPasswordFile"; };
password = { _secret = "/run/secrets/betaninPasswordFile"; };
};
clients = {
api_key = { _secret = "/run/secrets/betaninApiKeyFile"; };
@ -70,7 +66,7 @@ in
};
}
'';
description = lib.mdDoc ''
description = ''
Configuration for betanin.
Options containing secret data should be set to an attribute set
@ -82,8 +78,7 @@ in
beets.settings = mkOption {
type = beetsFormat.type;
default = { };
description = lib.mdDoc "Configuration for beets used by betanin.";
};
description = "Configuration for beets used by betanin.";
};
};
@ -123,17 +118,14 @@ in
{
description = "Betanin service";
wantedBy = [ "multi-user.target" ];
after = [ "networking.target" ];
after = [ "network.target" ];
path = [ pkgs.replace-secret ];
environment = {
HOME = cfg.dataDir;
};
path = [ pkgs.replace-secret ];
script = ''
mkdir -p ${cfg.dataDir}/.config/betanin \
${cfg.dataDir}/.local/share/betanin \
${cfg.dataDir}/.config/beets
ln -sf ${beetsFile} ${cfg.dataDir}/.config/beets/config.yaml
cat ${settingsFile} > ${cfg.dataDir}/.config/betanin/config.toml
${secretReplacements}
@ -141,28 +133,34 @@ in
${cfg.package}/bin/betanin --port ${toString cfg.port}
'';
serviceConfig = lib.mkMerge [
{
serviceConfig = {
User = cfg.user;
Group = cfg.group;
PrivateTmp = true;
Restart = "always";
WorkingDirectory = cfg.dataDir;
}
(mkIf (cfg.dataDir == "/var/lib/betanin") {
StateDirectory = "betanin";
})
];
StateDirectory = mkIf (cfg.dataDir == "/var/lib/betanin") "betanin";
};
};
users.users = optionalAttrs (cfg.user == defaultUser) {
systemd.tmpfiles.rules = [
"d ${cfg.dataDir} 0710 ${cfg.user} ${cfg.group} - -"
"d ${cfg.dataDir}/.config 0750 ${cfg.user} ${cfg.group} - -"
"d ${cfg.dataDir}/.config/betanin 0750 ${cfg.user} ${cfg.group} - -"
"d ${cfg.dataDir}/.config/beets 0750 ${cfg.user} ${cfg.group} - -"
"d ${cfg.dataDir}/.local 0750 ${cfg.user} ${cfg.group} - -"
"d ${cfg.dataDir}/.local/share 0750 ${cfg.user} ${cfg.group} - -"
"d ${cfg.dataDir}/.local/share/betanin 0750 ${cfg.user} ${cfg.group} - -"
];
users.users = optionalAttrs (cfg.user == "betanin") {
${cfg.user} = {
isSystemUser = true;
group = cfg.group;
};
};
users.groups = optionalAttrs (cfg.group == defaultGroup) {
users.groups = optionalAttrs (cfg.group == "betanin") {
${cfg.group} = { };
};
};