nixos ddclient: support multiple domains and run via systemd timer
a) Some providers can update multiple domains - support that. b) Make "zone" and "script" configurable. Some providers require these. c) Instead of leaving the ddclient daemon running all the time, use a systemd timer to kick it off. d) Don't use a predefined user - run everything via DynamicUser e) Add documentation
This commit is contained in:
parent
cc4677c36e
commit
642c8a8d8d
@ -56,7 +56,7 @@
|
|||||||
#dialout = 27; # unused
|
#dialout = 27; # unused
|
||||||
polkituser = 28;
|
polkituser = 28;
|
||||||
#utmp = 29; # unused
|
#utmp = 29; # unused
|
||||||
ddclient = 30;
|
# ddclient = 30; # converted to DynamicUser = true
|
||||||
davfs2 = 31;
|
davfs2 = 31;
|
||||||
#disnix = 33; # unused
|
#disnix = 33; # unused
|
||||||
osgi = 34;
|
osgi = 34;
|
||||||
@ -343,7 +343,7 @@
|
|||||||
dialout = 27;
|
dialout = 27;
|
||||||
#polkituser = 28; # currently unused, polkitd doesn't need a group
|
#polkituser = 28; # currently unused, polkitd doesn't need a group
|
||||||
utmp = 29;
|
utmp = 29;
|
||||||
ddclient = 30;
|
# ddclient = 30; # converted to DynamicUser = true
|
||||||
davfs2 = 31;
|
davfs2 = 31;
|
||||||
disnix = 33;
|
disnix = 33;
|
||||||
osgi = 34;
|
osgi = 34;
|
||||||
|
@ -22,6 +22,8 @@ with lib;
|
|||||||
(config:
|
(config:
|
||||||
let enabled = getAttrFromPath [ "services" "printing" "gutenprint" ] config;
|
let enabled = getAttrFromPath [ "services" "printing" "gutenprint" ] config;
|
||||||
in if enabled then [ pkgs.gutenprint ] else [ ]))
|
in if enabled then [ pkgs.gutenprint ] else [ ]))
|
||||||
|
(mkRenamedOptionModule [ "services" "ddclient" "domain" ] [ "services" "ddclient" "domains" ])
|
||||||
|
(mkRemovedOptionModule [ "services" "ddclient" "homeDir" ] "")
|
||||||
(mkRenamedOptionModule [ "services" "elasticsearch" "host" ] [ "services" "elasticsearch" "listenAddress" ])
|
(mkRenamedOptionModule [ "services" "elasticsearch" "host" ] [ "services" "elasticsearch" "listenAddress" ])
|
||||||
(mkRenamedOptionModule [ "services" "graphite" "api" "host" ] [ "services" "graphite" "api" "listenAddress" ])
|
(mkRenamedOptionModule [ "services" "graphite" "api" "host" ] [ "services" "graphite" "api" "listenAddress" ])
|
||||||
(mkRenamedOptionModule [ "services" "graphite" "web" "host" ] [ "services" "graphite" "web" "listenAddress" ])
|
(mkRenamedOptionModule [ "services" "graphite" "web" "host" ] [ "services" "graphite" "web" "listenAddress" ])
|
||||||
|
@ -3,24 +3,24 @@
|
|||||||
let
|
let
|
||||||
cfg = config.services.ddclient;
|
cfg = config.services.ddclient;
|
||||||
boolToStr = bool: if bool then "yes" else "no";
|
boolToStr = bool: if bool then "yes" else "no";
|
||||||
|
dataDir = "/var/lib/ddclient";
|
||||||
|
|
||||||
configText = ''
|
configText = ''
|
||||||
# This file can be used as a template for configFile or is automatically generated by Nix options.
|
# This file can be used as a template for configFile or is automatically generated by Nix options.
|
||||||
daemon=${toString cfg.interval}
|
cache=${dataDir}/ddclient.cache
|
||||||
cache=${cfg.homeDir}/ddclient.cache
|
foreground=YES
|
||||||
pid=/run/ddclient/ddclient.pid
|
|
||||||
foreground=NO
|
|
||||||
use=${cfg.use}
|
use=${cfg.use}
|
||||||
login=${cfg.username}
|
login=${cfg.username}
|
||||||
password=${cfg.password}
|
password=${cfg.password}
|
||||||
protocol=${cfg.protocol}
|
protocol=${cfg.protocol}
|
||||||
${let server = cfg.server; in
|
${lib.optionalString (cfg.script != "") "script=${cfg.script}"}
|
||||||
lib.optionalString (server != "") "server=${server}"}
|
${lib.optionalString (cfg.server != "") "server=${cfg.server}"}
|
||||||
|
${lib.optionalString (cfg.zone != "") "zone=${cfg.zone}"}
|
||||||
ssl=${boolToStr cfg.ssl}
|
ssl=${boolToStr cfg.ssl}
|
||||||
wildcard=YES
|
wildcard=YES
|
||||||
quiet=${boolToStr cfg.quiet}
|
quiet=${boolToStr cfg.quiet}
|
||||||
verbose=${boolToStr cfg.verbose}
|
verbose=${boolToStr cfg.verbose}
|
||||||
${cfg.domain}
|
${lib.concatStringsSep "," cfg.domains}
|
||||||
${cfg.extraConfig}
|
${cfg.extraConfig}
|
||||||
'';
|
'';
|
||||||
|
|
||||||
@ -44,17 +44,11 @@ with lib;
|
|||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
homeDir = mkOption {
|
domains = mkOption {
|
||||||
default = "/var/lib/ddclient";
|
default = [ "" ];
|
||||||
type = str;
|
type = listOf str;
|
||||||
description = "Home directory for the daemon user.";
|
|
||||||
};
|
|
||||||
|
|
||||||
domain = mkOption {
|
|
||||||
default = "";
|
|
||||||
type = str;
|
|
||||||
description = ''
|
description = ''
|
||||||
Domain name to synchronize.
|
Domain name(s) to synchronize.
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -75,9 +69,12 @@ with lib;
|
|||||||
};
|
};
|
||||||
|
|
||||||
interval = mkOption {
|
interval = mkOption {
|
||||||
default = 600;
|
default = "10min";
|
||||||
type = int;
|
type = str;
|
||||||
description = "The interval at which to run the check and update.";
|
description = ''
|
||||||
|
The interval at which to run the check and update.
|
||||||
|
See <command>man 7 systemd.time</command> for the format.
|
||||||
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
configFile = mkOption {
|
configFile = mkOption {
|
||||||
@ -95,7 +92,7 @@ with lib;
|
|||||||
default = "dyndns2";
|
default = "dyndns2";
|
||||||
type = str;
|
type = str;
|
||||||
description = ''
|
description = ''
|
||||||
Protocol to use with dynamic DNS provider (see http://sourceforge.net/apps/trac/ddclient/wiki/Protocols).
|
Protocol to use with dynamic DNS provider (see https://sourceforge.net/p/ddclient/wiki/protocols).
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -115,11 +112,20 @@ with lib;
|
|||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
extraConfig = mkOption {
|
|
||||||
default = "";
|
quiet = mkOption {
|
||||||
type = lines;
|
default = false;
|
||||||
|
type = bool;
|
||||||
description = ''
|
description = ''
|
||||||
Extra configuration. Contents will be added verbatim to the configuration file.
|
Print no messages for unnecessary updates.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
script = mkOption {
|
||||||
|
default = "";
|
||||||
|
type = str;
|
||||||
|
description = ''
|
||||||
|
script as required by some providers.
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -139,11 +145,19 @@ with lib;
|
|||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
quiet = mkOption {
|
zone = mkOption {
|
||||||
default = false;
|
default = "";
|
||||||
type = bool;
|
type = str;
|
||||||
description = ''
|
description = ''
|
||||||
Print no messages for unnecessary updates.
|
zone as required by some providers.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
extraConfig = mkOption {
|
||||||
|
default = "";
|
||||||
|
type = lines;
|
||||||
|
description = ''
|
||||||
|
Extra configuration. Contents will be added verbatim to the configuration file.
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@ -153,23 +167,8 @@ with lib;
|
|||||||
###### implementation
|
###### implementation
|
||||||
|
|
||||||
config = mkIf config.services.ddclient.enable {
|
config = mkIf config.services.ddclient.enable {
|
||||||
|
|
||||||
users = {
|
|
||||||
extraGroups.ddclient.gid = config.ids.gids.ddclient;
|
|
||||||
|
|
||||||
extraUsers.ddclient = {
|
|
||||||
uid = config.ids.uids.ddclient;
|
|
||||||
description = "ddclient daemon user";
|
|
||||||
group = "ddclient";
|
|
||||||
home = cfg.homeDir;
|
|
||||||
createHome = true;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
environment.etc."ddclient.conf" = {
|
environment.etc."ddclient.conf" = {
|
||||||
enable = cfg.configFile == "/etc/ddclient.conf";
|
enable = cfg.configFile == "/etc/ddclient.conf";
|
||||||
uid = config.ids.uids.ddclient;
|
|
||||||
gid = config.ids.gids.ddclient;
|
|
||||||
mode = "0600";
|
mode = "0600";
|
||||||
text = configText;
|
text = configText;
|
||||||
};
|
};
|
||||||
@ -180,15 +179,22 @@ with lib;
|
|||||||
after = [ "network.target" ];
|
after = [ "network.target" ];
|
||||||
restartTriggers = [ config.environment.etc."ddclient.conf".source ];
|
restartTriggers = [ config.environment.etc."ddclient.conf".source ];
|
||||||
|
|
||||||
serviceConfig = {
|
serviceConfig = rec {
|
||||||
RuntimeDirectory = "ddclient";
|
DynamicUser = true;
|
||||||
# we cannot run in forking mode as it swallows all the program output
|
RuntimeDirectory = StateDirectory;
|
||||||
Type = "simple";
|
StateDirectory = builtins.baseNameOf dataDir;
|
||||||
User = "ddclient";
|
Type = "oneshot";
|
||||||
Group = "ddclient";
|
ExecStartPre = "!${lib.getBin pkgs.coreutils}/bin/install -m666 ${cfg.configFile} /run/${RuntimeDirectory}/ddclient.conf";
|
||||||
ExecStart = "${lib.getBin pkgs.ddclient}/bin/ddclient -foreground -file ${cfg.configFile}";
|
ExecStart = "${lib.getBin pkgs.ddclient}/bin/ddclient -file /run/${RuntimeDirectory}/ddclient.conf";
|
||||||
ProtectSystem = "full";
|
};
|
||||||
PrivateTmp = true;
|
};
|
||||||
|
|
||||||
|
systemd.timers.ddclient = {
|
||||||
|
description = "Run ddclient";
|
||||||
|
wantedBy = [ "timers.target" ];
|
||||||
|
timerConfig = {
|
||||||
|
OnBootSec = cfg.interval;
|
||||||
|
OnUnitInactiveSec = cfg.interval;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -9,6 +9,7 @@ buildPerlPackage rec {
|
|||||||
sha256 = "1j8zdn7fy7i0bjk3jf0hxnbnshc2yf054vxq64imxdpfd7n5zgfy";
|
sha256 = "1j8zdn7fy7i0bjk3jf0hxnbnshc2yf054vxq64imxdpfd7n5zgfy";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
# perl packages by default get devdoc which isn't present
|
||||||
outputs = [ "out" ];
|
outputs = [ "out" ];
|
||||||
|
|
||||||
buildInputs = with perlPackages; [ IOSocketSSL DigestSHA1 ];
|
buildInputs = with perlPackages; [ IOSocketSSL DigestSHA1 ];
|
||||||
@ -25,7 +26,12 @@ buildPerlPackage rec {
|
|||||||
'';
|
'';
|
||||||
|
|
||||||
installPhase = ''
|
installPhase = ''
|
||||||
|
runHook preInstall
|
||||||
|
|
||||||
install -Dm755 ddclient $out/bin/ddclient
|
install -Dm755 ddclient $out/bin/ddclient
|
||||||
|
install -Dm644 -t $out/share/doc/ddclient COP* ChangeLog README.* RELEASENOTE
|
||||||
|
|
||||||
|
runHook postInstall
|
||||||
'';
|
'';
|
||||||
|
|
||||||
# there are no tests distributed with ddclient
|
# there are no tests distributed with ddclient
|
||||||
|
Loading…
Reference in New Issue
Block a user