@@ -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;
@@ -57,6 +67,15 @@ with lib;
5767 '';
5868 };
5969
70+ package = mkOption {
71+ type = package;
72+ default = pkgs.ddclient;
73+ defaultText = "pkgs.ddclient";
74+ description = ''
75+ The ddclient executable package run by the service.
76+ '';
77+ };
78+
6079 domains = mkOption {
6180 default = [ "" ];
6281 type = listOf str;
@@ -195,20 +214,13 @@ with lib;
195214
196215 serviceConfig = {
197216 DynamicUser = true;
217+ RuntimeDirectoryMode = "0700";
198218 inherit RuntimeDirectory;
199219 inherit StateDirectory;
200220 Type = "oneshot";
201− ExecStart = "${lib.getBin pkgs.ddclient}/bin/ddclient -file /run/${RuntimeDirectory}/ddclient.conf";
202− };
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− '';
221+ ExecStartPre = "!${pkgs.writeShellScript "ddclient-prestart" preStart}";
222+ ExecStart = "${lib.getBin cfg.package}/bin/ddclient -file /run/${RuntimeDirectory}/ddclient.conf";
223+ };
212224 };
213225
214226 systemd.timers.ddclient = {