minor refactoring.

This commit is contained in:
Gabe Venberg 2025-04-28 13:24:07 +02:00
parent f85493942d
commit 2ab20df02c

View file

@ -238,7 +238,9 @@ in {
}; };
}; };
config = mkIf cfg.enable { config = mkIf cfg.enable (let
command = "${getExe cfg.package} -c ${runtimeConfigPath}";
in {
systemd.services.copyparty = { systemd.services.copyparty = {
description = "http file sharing hub"; description = "http file sharing hub";
wantedBy = ["multi-user.target"]; wantedBy = ["multi-user.target"];
@ -261,10 +263,7 @@ in {
serviceConfig = { serviceConfig = {
Type = "simple"; Type = "simple";
ExecStart = '' ExecStart = command;
${getExe cfg.package} -c ${runtimeConfigPath}
'';
# Hardening options # Hardening options
User = cfg.user; User = cfg.user;
Group = cfg.group; Group = cfg.group;
@ -324,15 +323,17 @@ in {
# ensure volumes exist: # ensure volumes exist:
systemd.tmpfiles.settings."copyparty" = ( systemd.tmpfiles.settings."copyparty" = (
lib.attrsets.mapAttrs' ( lib.attrsets.mapAttrs' (
name: value: lib.attrsets.nameValuePair (value.path) ({ name: value:
d={ lib.attrsets.nameValuePair (value.path) {
#: in front of things means it wont change it if the directory already exists. d = {
group = ":${cfg.group}"; #: in front of things means it wont change it if the directory already exists.
user = ":${cfg.user}"; group = ":${cfg.group}";
mode = ":755"; user = ":${cfg.user}";
}; mode = ":755";
}) };
) cfg.volumes }
)
cfg.volumes
); );
users.groups.copyparty = lib.mkIf (cfg.user == "copyparty" && cfg.group == "copyparty") {}; users.groups.copyparty = lib.mkIf (cfg.user == "copyparty" && cfg.group == "copyparty") {};
@ -343,26 +344,20 @@ in {
isSystemUser = true; isSystemUser = true;
}; };
environment.systemPackages = lib.mkIf cfg.mkHashWrapper [ environment.systemPackages = lib.mkIf cfg.mkHashWrapper [
( pkgs.writeShellScriptBin
let "copyparty-hash"
command = '' ''
${getExe cfg.package} -c ${runtimeConfigPath} \ set -a # automatically export variables
--ah-cli \ # set same environment variables as the systemd service
''; ${lib.pipe config.systemd.services.copyparty.environment [
in (lib.filterAttrs (n: v: v != null && n != "PATH"))
pkgs.writeShellScriptBin "copyparty-hash" '' (lib.mapAttrs (_: v: "${v}"))
set -a # automatically export variables (lib.toShellVars)
# set same environment variables as the systemd service ]}
${lib.pipe config.systemd.services.copyparty.environment [ PATH=${config.systemd.services.copyparty.environment.PATH}:$PATH
(lib.filterAttrs (n: v: v != null && n != "PATH"))
(lib.mapAttrs (_: v: "${v}"))
(lib.toShellVars)
]}
PATH=${config.systemd.services.copyparty.environment.PATH}:$PATH
exec ${command} exec ${command} --ah-cli
'' ''
)
]; ];
}; });
} }