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