git.iko.soy/typeable/nixpkgs
on master help sign in
nixos/ddclient: fix privs when loading password
commit7deb5247a5da4f468a0abe464275f6c913c5f33f authorarcnmx <arcnmx@users.noreply.github.com> dateSat 6 Nov 2021, 08:31 (5 years ago) parent0d5b444
1 file changed+12−9
nixos/modules/services/networking/ddclient.nix+12−9
nixos/modules/services/networking/ddclient.nix+12−9
@@ -28,6 +28,16 @@ let
2828 '';
2929 configFile = if (cfg.configFile != null) then cfg.configFile else configFile';
3030
31+ preStart = ''
32+ install ${configFile} /run/${RuntimeDirectory}/ddclient.conf
33+ ${lib.optionalString (cfg.configFile == null) (if (cfg.passwordFile != null) then ''
34+ password=$(head -n 1 ${cfg.passwordFile})
35+ sed -i "s/^password=$/password=$password/" /run/${RuntimeDirectory}/ddclient.conf
36+ '' else ''
37+ sed -i '/^password=$/d' /run/${RuntimeDirectory}/ddclient.conf
38+ '')}
39+ '';
40+
3141in
3242
3343with lib;
@@ -195,20 +205,13 @@ with lib;
195205
196206 serviceConfig = {
197207 DynamicUser = true;
208+ RuntimeDirectoryMode = "0700";
198209 inherit RuntimeDirectory;
199210 inherit StateDirectory;
200211 Type = "oneshot";
212+ ExecStartPre = "!${pkgs.writeShellScript "ddclient-prestart" preStart}";
201213 ExecStart = "${lib.getBin pkgs.ddclient}/bin/ddclient -file /run/${RuntimeDirectory}/ddclient.conf";
202214 };
203− preStart = ''
204− install -m 600 ${configFile} /run/${RuntimeDirectory}/ddclient.conf
205− ${optionalString (cfg.configFile == null) (if (cfg.passwordFile != null) then ''
206− password=$(head -n 1 ${cfg.passwordFile})
207− sed -i "s/^password=$/password=$password/" /run/${RuntimeDirectory}/ddclient.conf
208− '' else ''
209− sed -i '/^password=$/d' /run/${RuntimeDirectory}/ddclient.conf
210− '')}
211− '';
212215 };
213216
214217 systemd.timers.ddclient = {