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:
lib.attrsets.nameValuePair (value.path) {
d = { d = {
#: in front of things means it wont change it if the directory already exists. #: in front of things means it wont change it if the directory already exists.
group = ":${cfg.group}"; group = ":${cfg.group}";
user = ":${cfg.user}"; user = ":${cfg.user}";
mode = ":755"; 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,14 +344,9 @@ 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} \
--ah-cli \
'';
in
pkgs.writeShellScriptBin "copyparty-hash" ''
set -a # automatically export variables set -a # automatically export variables
# set same environment variables as the systemd service # set same environment variables as the systemd service
${lib.pipe config.systemd.services.copyparty.environment [ ${lib.pipe config.systemd.services.copyparty.environment [
@ -360,9 +356,8 @@ in {
]} ]}
PATH=${config.systemd.services.copyparty.environment.PATH}:$PATH PATH=${config.systemd.services.copyparty.environment.PATH}:$PATH
exec ${command} exec ${command} --ah-cli
'' ''
)
]; ];
}; });
} }