2014-05-05 19:58:51 +01:00
|
|
|
{ config, pkgs, lib, ... }:
|
2009-09-16 12:22:45 +01:00
|
|
|
|
|
|
|
let
|
|
|
|
|
2014-05-05 19:58:51 +01:00
|
|
|
inherit (lib) mkOption mkIf singleton;
|
2009-09-16 12:22:45 +01:00
|
|
|
inherit (pkgs) ddclient;
|
|
|
|
|
|
|
|
stateDir = "/var/spool/ddclient";
|
|
|
|
ddclientUser = "ddclient";
|
2017-03-06 15:41:02 +00:00
|
|
|
ddclientFlags = "-foreground -file ${config.services.ddclient.configFile}";
|
2015-02-19 04:44:29 +00:00
|
|
|
ddclientPIDFile = "${stateDir}/ddclient.pid";
|
2009-09-16 12:22:45 +01:00
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
###### 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).
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
domain = mkOption {
|
|
|
|
default = "";
|
2015-02-19 04:44:29 +00:00
|
|
|
type = str;
|
2009-09-16 12:22:45 +01:00
|
|
|
description = ''
|
|
|
|
Domain name to synchronize.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
username = mkOption {
|
|
|
|
default = "";
|
2015-02-19 04:44:29 +00:00
|
|
|
type = str;
|
2009-09-16 12:22:45 +01:00
|
|
|
description = ''
|
|
|
|
Username.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
password = mkOption {
|
2015-02-19 04:44:29 +00:00
|
|
|
default = "";
|
|
|
|
type = str;
|
2009-09-16 12:22:45 +01:00
|
|
|
description = ''
|
2016-07-19 15:49:46 +01:00
|
|
|
Password. WARNING: The password becomes world readable in the Nix store.
|
2009-09-16 12:22:45 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2016-08-20 08:39:52 +01:00
|
|
|
configFile = mkOption {
|
|
|
|
default = "/etc/ddclient.conf";
|
|
|
|
type = path;
|
|
|
|
description = ''
|
|
|
|
Path to configuration file.
|
|
|
|
When set to the default '/etc/ddclient.conf' it will be populated with the various other options in this module. When it is changed (for example: '/root/nixos/secrets/ddclient.conf') the file read directly to configure ddclient. This is a source of impurity.
|
|
|
|
The purpose of this is to avoid placing secrets into the store.
|
|
|
|
'';
|
|
|
|
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 = ''
|
2015-02-19 04:44:29 +00:00
|
|
|
Protocol to use with dynamic DNS provider (see http://sourceforge.net/apps/trac/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 = ''
|
|
|
|
Whether to use to use SSL/TLS to connect to dynamic DNS provider.
|
2009-09-16 12:22:45 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
extraConfig = mkOption {
|
2015-02-19 04:44:29 +00:00
|
|
|
default = "";
|
2016-10-23 18:33:41 +01:00
|
|
|
type = lines;
|
2009-09-16 12:22:45 +01:00
|
|
|
description = ''
|
|
|
|
Extra configuration. Contents will be added verbatim to the configuration file.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
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.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
quiet = mkOption {
|
|
|
|
default = false;
|
|
|
|
type = bool;
|
|
|
|
description = ''
|
|
|
|
Print no messages for unnecessary updates.
|
|
|
|
'';
|
|
|
|
};
|
2009-09-16 12:22:45 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
|
|
|
config = mkIf config.services.ddclient.enable {
|
|
|
|
|
2015-02-19 04:44:29 +00:00
|
|
|
environment.systemPackages = [ ddclient ];
|
2009-09-16 12:22:45 +01:00
|
|
|
|
2015-02-19 04:44:29 +00:00
|
|
|
users.extraUsers = singleton {
|
|
|
|
name = ddclientUser;
|
|
|
|
uid = config.ids.uids.ddclient;
|
|
|
|
description = "ddclient daemon user";
|
|
|
|
home = stateDir;
|
|
|
|
};
|
2009-09-16 12:22:45 +01:00
|
|
|
|
2016-06-19 20:51:05 +01:00
|
|
|
environment.etc."ddclient.conf" = {
|
2016-12-25 22:32:23 +00:00
|
|
|
enable = config.services.ddclient.configFile == "/etc/ddclient.conf";
|
2016-06-19 20:51:05 +01:00
|
|
|
uid = config.ids.uids.ddclient;
|
|
|
|
mode = "0600";
|
|
|
|
text = ''
|
2016-08-20 08:39:52 +01:00
|
|
|
# This file can be used as a template for configFile or is automatically generated by Nix options.
|
2016-06-19 20:51:05 +01:00
|
|
|
daemon=600
|
|
|
|
cache=${stateDir}/ddclient.cache
|
|
|
|
pid=${ddclientPIDFile}
|
|
|
|
use=${config.services.ddclient.use}
|
|
|
|
login=${config.services.ddclient.username}
|
|
|
|
password=${config.services.ddclient.password}
|
|
|
|
protocol=${config.services.ddclient.protocol}
|
2016-12-25 22:32:40 +00:00
|
|
|
${let server = config.services.ddclient.server; in
|
|
|
|
lib.optionalString (server != "") "server=${server}"}
|
2016-06-19 20:51:05 +01:00
|
|
|
ssl=${if config.services.ddclient.ssl then "yes" else "no"}
|
|
|
|
wildcard=YES
|
2017-03-06 15:41:02 +00:00
|
|
|
quiet=${if config.services.ddclient.quiet then "yes" else "no"}
|
|
|
|
verbose=${if config.services.ddclient.verbose then "yes" else "no"}
|
2016-06-19 20:51:05 +01:00
|
|
|
${config.services.ddclient.domain}
|
|
|
|
${config.services.ddclient.extraConfig}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2015-02-19 04:44:29 +00:00
|
|
|
systemd.services.ddclient = {
|
|
|
|
description = "Dynamic DNS Client";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
after = [ "network.target" ];
|
2016-06-19 20:51:05 +01:00
|
|
|
restartTriggers = [ config.environment.etc."ddclient.conf".source ];
|
2015-05-26 04:45:25 +01:00
|
|
|
|
2015-02-19 04:44:29 +00:00
|
|
|
serviceConfig = {
|
2015-04-19 09:00:04 +01:00
|
|
|
# Uncomment this if too many problems occur:
|
|
|
|
# Type = "forking";
|
2015-02-19 04:44:29 +00:00
|
|
|
User = ddclientUser;
|
|
|
|
Group = "nogroup"; #TODO get this to work
|
|
|
|
PermissionsStartOnly = "true";
|
|
|
|
PIDFile = ddclientPIDFile;
|
|
|
|
ExecStartPre = ''
|
|
|
|
${pkgs.stdenv.shell} -c "${pkgs.coreutils}/bin/mkdir -m 0755 -p ${stateDir} && ${pkgs.coreutils}/bin/chown ${ddclientUser} ${stateDir}"
|
|
|
|
'';
|
|
|
|
ExecStart = "${ddclient}/bin/ddclient ${ddclientFlags}";
|
|
|
|
#ExecStartPost = "${pkgs.coreutils}/bin/rm -r ${stateDir}"; # Should we have this?
|
2009-10-12 18:27:57 +01:00
|
|
|
};
|
2015-02-19 04:44:29 +00:00
|
|
|
};
|
2009-09-16 12:22:45 +01:00
|
|
|
};
|
|
|
|
}
|