services/yt-dlp: fix service working directory

There is the `--paths` option for that purpose. It also eliminates the
workaround for creating the directory before starting the service for
newly-bootstrapped systems.

The several hardening options have also been corrected.
This commit is contained in:
Gabriel Arazas 2022-04-22 13:10:33 +08:00
parent da25de06ee
commit c0dd8ab1a8
2 changed files with 8 additions and 7 deletions

View File

@ -127,7 +127,6 @@ in {
}; };
Service = { Service = {
WorkingDirectory = cfg.archivePath;
ExecStartPre = '' ExecStartPre = ''
${pkgs.bash}/bin/bash -c "${pkgs.coreutils}/bin/mkdir -p ${ ${pkgs.bash}/bin/bash -c "${pkgs.coreutils}/bin/mkdir -p ${
lib.escapeShellArg cfg.archivePath lib.escapeShellArg cfg.archivePath
@ -141,7 +140,7 @@ in {
lib.concatStringsSep " " cfg.extraArgs lib.concatStringsSep " " cfg.extraArgs
} ${lib.concatStringsSep " " value.extraArgs} ${ } ${lib.concatStringsSep " " value.extraArgs} ${
lib.escapeShellArgs value.urls lib.escapeShellArgs value.urls
} } --paths ${lib.escapeShellArg cfg.archivePath}
''; '';
in "${archiveScript}/bin/${scriptName}"; in "${archiveScript}/bin/${scriptName}";
}; };

View File

@ -119,19 +119,21 @@ in {
documentation = [ "man:yt-dlp(1)" ]; documentation = [ "man:yt-dlp(1)" ];
enable = true; enable = true;
path = [ cfg.package pkgs.coreutils ]; path = [ cfg.package pkgs.coreutils ];
preStart = ''
mkdir -p ${lib.escapeShellArg cfg.archivePath}
'';
script = '' script = ''
mkdir -p ${lib.escapeShellArg cfg.archivePath} \ yt-dlp ${lib.concatStringsSep " " cfg.extraArgs} ${
&& yt-dlp ${lib.concatStringsSep " " cfg.extraArgs} ${
lib.concatStringsSep " " value.extraArgs lib.concatStringsSep " " value.extraArgs
} ${lib.escapeShellArgs value.urls} } ${lib.escapeShellArgs value.urls} --paths ${cfg.archivePath}
''; '';
startAt = value.startAt; startAt = value.startAt;
serviceConfig = { serviceConfig = {
NoNewPrivileges = true; NoNewPrivileges = true;
PrivateTmp = true; PrivateTmp = true;
ProtectControlGroup = true; ProtectControlGroups = true;
ProtectClock = true; ProtectClock = true;
ProtectKernelModule = true; ProtectKernelModules = true;
ProtectKernelLogs = true; ProtectKernelLogs = true;
}; };
}) cfg.jobs; }) cfg.jobs;