2014-05-05 20:58:51 +02:00
|
|
|
{ config, pkgs, lib, ... }:
|
2009-09-16 13:22:45 +02:00
|
|
|
|
|
|
|
let
|
2017-08-13 15:46:13 +02:00
|
|
|
cfg = config.services.ddclient;
|
|
|
|
boolToStr = bool: if bool then "yes" else "no";
|
2018-03-12 16:25:28 +01:00
|
|
|
dataDir = "/var/lib/ddclient";
|
2021-10-29 19:08:14 +02:00
|
|
|
StateDirectory = builtins.baseNameOf dataDir;
|
|
|
|
RuntimeDirectory = StateDirectory;
|
2017-08-13 15:46:13 +02:00
|
|
|
|
2021-10-29 19:08:14 +02:00
|
|
|
configFile' = pkgs.writeText "ddclient.conf" ''
|
2017-08-13 15:46:13 +02:00
|
|
|
# This file can be used as a template for configFile or is automatically generated by Nix options.
|
2018-03-12 16:25:28 +01:00
|
|
|
cache=${dataDir}/ddclient.cache
|
|
|
|
foreground=YES
|
2017-08-13 15:46:13 +02:00
|
|
|
use=${cfg.use}
|
|
|
|
login=${cfg.username}
|
2021-10-29 19:08:14 +02:00
|
|
|
password=
|
2017-08-13 15:46:13 +02:00
|
|
|
protocol=${cfg.protocol}
|
2018-03-12 16:25:28 +01:00
|
|
|
${lib.optionalString (cfg.script != "") "script=${cfg.script}"}
|
|
|
|
${lib.optionalString (cfg.server != "") "server=${cfg.server}"}
|
|
|
|
${lib.optionalString (cfg.zone != "") "zone=${cfg.zone}"}
|
2017-08-13 15:46:13 +02:00
|
|
|
ssl=${boolToStr cfg.ssl}
|
|
|
|
wildcard=YES
|
2021-04-17 16:40:49 +02:00
|
|
|
ipv6=${boolToStr cfg.ipv6}
|
2017-08-13 15:46:13 +02:00
|
|
|
quiet=${boolToStr cfg.quiet}
|
|
|
|
verbose=${boolToStr cfg.verbose}
|
|
|
|
${cfg.extraConfig}
|
2018-04-18 01:00:25 +02:00
|
|
|
${lib.concatStringsSep "," cfg.domains}
|
2017-08-13 15:46:13 +02:00
|
|
|
'';
|
2021-10-29 19:08:14 +02:00
|
|
|
configFile = if (cfg.configFile != null) then cfg.configFile else configFile';
|
2009-09-16 13:22:45 +02:00
|
|
|
|
|
|
|
in
|
|
|
|
|
2017-08-13 15:46:13 +02:00
|
|
|
with lib;
|
|
|
|
|
2009-09-16 13:22:45 +02:00
|
|
|
{
|
|
|
|
|
2019-12-10 02:51:19 +01:00
|
|
|
imports = [
|
|
|
|
(mkChangedOptionModule [ "services" "ddclient" "domain" ] [ "services" "ddclient" "domains" ]
|
|
|
|
(config:
|
|
|
|
let value = getAttrFromPath [ "services" "ddclient" "domain" ] config;
|
|
|
|
in if value != "" then [ value ] else []))
|
|
|
|
(mkRemovedOptionModule [ "services" "ddclient" "homeDir" ] "")
|
2021-10-29 19:08:14 +02:00
|
|
|
(mkRemovedOptionModule [ "services" "ddclient" "password" ] "Use services.ddclient.passwordFile instead.")
|
2019-12-10 02:51:19 +01:00
|
|
|
];
|
|
|
|
|
2009-09-16 13:22:45 +02:00
|
|
|
###### interface
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2009-09-16 13:22:45 +02:00
|
|
|
options = {
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2015-02-19 05:44:29 +01:00
|
|
|
services.ddclient = with lib.types; {
|
2009-09-16 13:22:45 +02:00
|
|
|
|
|
|
|
enable = mkOption {
|
|
|
|
default = false;
|
2015-02-19 05:44:29 +01:00
|
|
|
type = bool;
|
2009-09-16 13:22:45 +02:00
|
|
|
description = ''
|
|
|
|
Whether to synchronise your machine's IP address with a dynamic DNS provider (e.g. dyndns.org).
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2018-03-12 16:25:28 +01:00
|
|
|
domains = mkOption {
|
|
|
|
default = [ "" ];
|
|
|
|
type = listOf str;
|
2009-09-16 13:22:45 +02:00
|
|
|
description = ''
|
2018-03-12 16:25:28 +01:00
|
|
|
Domain name(s) to synchronize.
|
2009-09-16 13:22:45 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
username = mkOption {
|
|
|
|
default = "";
|
2015-02-19 05:44:29 +01:00
|
|
|
type = str;
|
2009-09-16 13:22:45 +02:00
|
|
|
description = ''
|
2018-03-12 16:25:28 +01:00
|
|
|
User name.
|
2009-09-16 13:22:45 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2021-10-29 19:08:14 +02:00
|
|
|
passwordFile = mkOption {
|
|
|
|
default = null;
|
|
|
|
type = nullOr str;
|
2009-09-16 13:22:45 +02:00
|
|
|
description = ''
|
2021-10-29 19:08:14 +02:00
|
|
|
A file containing the password.
|
2009-09-16 13:22:45 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2017-08-13 15:46:13 +02:00
|
|
|
interval = mkOption {
|
2018-03-12 16:25:28 +01:00
|
|
|
default = "10min";
|
|
|
|
type = str;
|
|
|
|
description = ''
|
|
|
|
The interval at which to run the check and update.
|
|
|
|
See <command>man 7 systemd.time</command> for the format.
|
|
|
|
'';
|
2017-08-13 15:46:13 +02:00
|
|
|
};
|
|
|
|
|
2016-08-20 09:39:52 +02:00
|
|
|
configFile = mkOption {
|
2021-10-29 19:08:14 +02:00
|
|
|
default = null;
|
|
|
|
type = nullOr path;
|
2016-08-20 09:39:52 +02:00
|
|
|
description = ''
|
|
|
|
Path to configuration file.
|
2021-10-29 19:08:14 +02:00
|
|
|
When set this overrides the generated configuration from module options.
|
2016-08-20 09:39:52 +02:00
|
|
|
'';
|
|
|
|
example = "/root/nixos/secrets/ddclient.conf";
|
|
|
|
};
|
|
|
|
|
2009-09-16 13:22:45 +02:00
|
|
|
protocol = mkOption {
|
2015-02-19 05:44:29 +01:00
|
|
|
default = "dyndns2";
|
|
|
|
type = str;
|
2009-09-16 13:22:45 +02:00
|
|
|
description = ''
|
2018-03-12 16:25:28 +01:00
|
|
|
Protocol to use with dynamic DNS provider (see https://sourceforge.net/p/ddclient/wiki/protocols).
|
2009-09-16 13:22:45 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
server = mkOption {
|
2015-02-19 05:44:29 +01:00
|
|
|
default = "";
|
|
|
|
type = str;
|
2009-09-16 13:22:45 +02:00
|
|
|
description = ''
|
2015-02-19 05:44:29 +01:00
|
|
|
Server address.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
ssl = mkOption {
|
|
|
|
default = true;
|
|
|
|
type = bool;
|
|
|
|
description = ''
|
2021-04-17 16:40:49 +02:00
|
|
|
Whether to use SSL/TLS to connect to dynamic DNS provider.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
ipv6 = mkOption {
|
|
|
|
default = false;
|
|
|
|
type = bool;
|
|
|
|
description = ''
|
|
|
|
Whether to use IPv6.
|
2009-09-16 13:22:45 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2018-03-12 16:25:28 +01:00
|
|
|
|
|
|
|
quiet = mkOption {
|
|
|
|
default = false;
|
|
|
|
type = bool;
|
|
|
|
description = ''
|
|
|
|
Print no messages for unnecessary updates.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
script = mkOption {
|
2015-02-19 05:44:29 +01:00
|
|
|
default = "";
|
2018-03-12 16:25:28 +01:00
|
|
|
type = str;
|
2009-09-16 13:22:45 +02:00
|
|
|
description = ''
|
2018-03-12 16:25:28 +01:00
|
|
|
script as required by some providers.
|
2009-09-16 13:22:45 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2015-02-19 05:44:29 +01:00
|
|
|
use = mkOption {
|
|
|
|
default = "web, web=checkip.dyndns.com/, web-skip='Current IP Address: '";
|
|
|
|
type = str;
|
|
|
|
description = ''
|
2016-09-30 19:25:20 +02:00
|
|
|
Method to determine the IP address to send to the dynamic DNS provider.
|
2015-02-19 05:44:29 +01:00
|
|
|
'';
|
2009-09-16 13:22:45 +02:00
|
|
|
};
|
2017-03-06 16:41:02 +01:00
|
|
|
|
|
|
|
verbose = mkOption {
|
|
|
|
default = true;
|
|
|
|
type = bool;
|
|
|
|
description = ''
|
|
|
|
Print verbose information.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2018-03-12 16:25:28 +01:00
|
|
|
zone = mkOption {
|
|
|
|
default = "";
|
|
|
|
type = str;
|
2017-03-06 16:41:02 +01:00
|
|
|
description = ''
|
2018-03-12 16:25:28 +01:00
|
|
|
zone as required by some providers.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
extraConfig = mkOption {
|
|
|
|
default = "";
|
|
|
|
type = lines;
|
|
|
|
description = ''
|
|
|
|
Extra configuration. Contents will be added verbatim to the configuration file.
|
2017-03-06 16:41:02 +01:00
|
|
|
'';
|
|
|
|
};
|
2009-09-16 13:22:45 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
|
|
|
config = mkIf config.services.ddclient.enable {
|
2015-02-19 05:44:29 +01:00
|
|
|
systemd.services.ddclient = {
|
|
|
|
description = "Dynamic DNS Client";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
after = [ "network.target" ];
|
2021-10-29 19:08:14 +02:00
|
|
|
restartTriggers = optional (cfg.configFile != null) cfg.configFile;
|
2015-05-26 05:45:25 +02:00
|
|
|
|
2021-10-29 19:08:14 +02:00
|
|
|
serviceConfig = {
|
2018-03-12 16:25:28 +01:00
|
|
|
DynamicUser = true;
|
2021-10-29 19:08:14 +02:00
|
|
|
inherit RuntimeDirectory;
|
|
|
|
inherit StateDirectory;
|
2018-03-12 16:25:28 +01:00
|
|
|
Type = "oneshot";
|
|
|
|
ExecStart = "${lib.getBin pkgs.ddclient}/bin/ddclient -file /run/${RuntimeDirectory}/ddclient.conf";
|
|
|
|
};
|
2021-10-29 19:08:14 +02:00
|
|
|
preStart = ''
|
|
|
|
install -m 600 ${configFile} /run/${RuntimeDirectory}/ddclient.conf
|
|
|
|
${optionalString (cfg.configFile == null) (if (cfg.passwordFile != null) then ''
|
|
|
|
password=$(head -n 1 ${cfg.passwordFile})
|
|
|
|
sed -i "s/^password=$/password=$password/" /run/${RuntimeDirectory}/ddclient.conf
|
|
|
|
'' else ''
|
|
|
|
sed -i '/^password=$/d' /run/${RuntimeDirectory}/ddclient.conf
|
|
|
|
'')}
|
|
|
|
'';
|
2018-03-12 16:25:28 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
systemd.timers.ddclient = {
|
|
|
|
description = "Run ddclient";
|
|
|
|
wantedBy = [ "timers.target" ];
|
|
|
|
timerConfig = {
|
|
|
|
OnBootSec = cfg.interval;
|
|
|
|
OnUnitInactiveSec = cfg.interval;
|
2009-10-12 19:27:57 +02:00
|
|
|
};
|
2015-02-19 05:44:29 +01:00
|
|
|
};
|
2009-09-16 13:22:45 +02:00
|
|
|
};
|
|
|
|
}
|