2014-05-05 20:58:51 +02:00
|
|
|
{ config, pkgs, lib, ... }:
|
2009-09-16 13:22:45 +02:00
|
|
|
|
|
|
|
let
|
|
|
|
|
2014-05-05 20:58:51 +02:00
|
|
|
inherit (lib) mkOption mkIf singleton;
|
2009-09-16 13:22:45 +02:00
|
|
|
inherit (pkgs) ddclient;
|
|
|
|
|
|
|
|
stateDir = "/var/spool/ddclient";
|
|
|
|
ddclientUser = "ddclient";
|
2015-02-19 05:44:29 +01:00
|
|
|
ddclientFlags = "-foreground -verbose -noquiet -file ${ddclientCfg}";
|
|
|
|
ddclientPIDFile = "${stateDir}/ddclient.pid";
|
2009-09-16 13:22:45 +02:00
|
|
|
ddclientCfg = pkgs.writeText "ddclient.conf" ''
|
2009-09-16 13:57:41 +02:00
|
|
|
daemon=600
|
|
|
|
cache=${stateDir}/ddclient.cache
|
2015-02-19 05:44:29 +01:00
|
|
|
pid=${ddclientPIDFile}
|
|
|
|
use=${config.services.ddclient.use}
|
2009-09-16 13:57:41 +02:00
|
|
|
login=${config.services.ddclient.username}
|
|
|
|
password=${config.services.ddclient.password}
|
|
|
|
protocol=${config.services.ddclient.protocol}
|
|
|
|
server=${config.services.ddclient.server}
|
2015-02-19 05:44:29 +01:00
|
|
|
ssl=${if config.services.ddclient.ssl then "yes" else "yes"}
|
2009-09-16 13:57:41 +02:00
|
|
|
wildcard=YES
|
|
|
|
${config.services.ddclient.domain}
|
|
|
|
${config.services.ddclient.extraConfig}
|
|
|
|
'';
|
2009-09-16 13:22:45 +02:00
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
###### 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).
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
domain = mkOption {
|
|
|
|
default = "";
|
2015-02-19 05:44:29 +01:00
|
|
|
type = str;
|
2009-09-16 13:22:45 +02:00
|
|
|
description = ''
|
|
|
|
Domain name to synchronize.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
username = mkOption {
|
|
|
|
default = "";
|
2015-02-19 05:44:29 +01:00
|
|
|
type = str;
|
2009-09-16 13:22:45 +02:00
|
|
|
description = ''
|
|
|
|
Username.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
password = mkOption {
|
2015-02-19 05:44:29 +01:00
|
|
|
default = "";
|
|
|
|
type = str;
|
2009-09-16 13:22:45 +02:00
|
|
|
description = ''
|
|
|
|
Password.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
protocol = mkOption {
|
2015-02-19 05:44:29 +01:00
|
|
|
default = "dyndns2";
|
|
|
|
type = str;
|
2009-09-16 13:22:45 +02:00
|
|
|
description = ''
|
2015-02-19 05:44:29 +01:00
|
|
|
Protocol to use with dynamic DNS provider (see http://sourceforge.net/apps/trac/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 = ''
|
|
|
|
Whether to use to use SSL/TLS to connect to dynamic DNS provider.
|
2009-09-16 13:22:45 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
extraConfig = mkOption {
|
2015-02-19 05:44:29 +01:00
|
|
|
default = "";
|
|
|
|
type = str;
|
2009-09-16 13:22:45 +02:00
|
|
|
description = ''
|
|
|
|
Extra configuration. Contents will be added verbatim to the configuration file.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2015-02-19 05:44:29 +01:00
|
|
|
use = mkOption {
|
|
|
|
default = "web, web=checkip.dyndns.com/, web-skip='Current IP Address: '";
|
|
|
|
type = str;
|
|
|
|
description = ''
|
|
|
|
Method to determine the IP address to send to the dymanic DNS provider.
|
|
|
|
'';
|
2009-09-16 13:22:45 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
|
|
|
config = mkIf config.services.ddclient.enable {
|
|
|
|
|
2015-02-19 05:44:29 +01:00
|
|
|
environment.systemPackages = [ ddclient ];
|
2009-09-16 13:22:45 +02:00
|
|
|
|
2015-02-19 05:44:29 +01:00
|
|
|
users.extraUsers = singleton {
|
|
|
|
name = ddclientUser;
|
|
|
|
uid = config.ids.uids.ddclient;
|
|
|
|
description = "ddclient daemon user";
|
|
|
|
home = stateDir;
|
|
|
|
};
|
2009-09-16 13:22:45 +02:00
|
|
|
|
2015-02-19 05:44:29 +01:00
|
|
|
systemd.services.ddclient = {
|
|
|
|
description = "Dynamic DNS Client";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
after = [ "network.target" ];
|
2015-05-26 05:45:25 +02:00
|
|
|
|
|
|
|
environment.SSL_CERT_FILE = "/etc/ssl/certs/ca-bundle.crt";
|
2015-02-19 05:44:29 +01:00
|
|
|
serviceConfig = {
|
2015-04-19 10:00:04 +02:00
|
|
|
# Uncomment this if too many problems occur:
|
|
|
|
# Type = "forking";
|
2015-02-19 05:44:29 +01: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 19:27:57 +02:00
|
|
|
};
|
2015-02-19 05:44:29 +01:00
|
|
|
};
|
2009-09-16 13:22:45 +02:00
|
|
|
};
|
|
|
|
}
|