2014-05-05 18:58:51 +00:00
|
|
|
{ config, pkgs, lib, ... }:
|
2009-09-16 11:22:45 +00:00
|
|
|
|
|
|
|
let
|
|
|
|
|
2014-05-05 18:58:51 +00:00
|
|
|
inherit (lib) mkOption mkIf singleton;
|
2009-09-16 11:22:45 +00:00
|
|
|
inherit (pkgs) ddclient;
|
|
|
|
|
|
|
|
stateDir = "/var/spool/ddclient";
|
|
|
|
ddclientUser = "ddclient";
|
2015-02-19 04:44:29 +00:00
|
|
|
ddclientFlags = "-foreground -verbose -noquiet -file ${ddclientCfg}";
|
|
|
|
ddclientPIDFile = "${stateDir}/ddclient.pid";
|
2009-09-16 11:22:45 +00:00
|
|
|
ddclientCfg = pkgs.writeText "ddclient.conf" ''
|
2009-09-16 11:57:41 +00:00
|
|
|
daemon=600
|
|
|
|
cache=${stateDir}/ddclient.cache
|
2015-02-19 04:44:29 +00:00
|
|
|
pid=${ddclientPIDFile}
|
|
|
|
use=${config.services.ddclient.use}
|
2009-09-16 11:57:41 +00:00
|
|
|
login=${config.services.ddclient.username}
|
|
|
|
password=${config.services.ddclient.password}
|
|
|
|
protocol=${config.services.ddclient.protocol}
|
|
|
|
server=${config.services.ddclient.server}
|
2015-12-08 10:11:14 +00:00
|
|
|
ssl=${if config.services.ddclient.ssl then "yes" else "no"}
|
2009-09-16 11:57:41 +00:00
|
|
|
wildcard=YES
|
|
|
|
${config.services.ddclient.domain}
|
|
|
|
${config.services.ddclient.extraConfig}
|
|
|
|
'';
|
2009-09-16 11:22:45 +00:00
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
###### interface
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2009-09-16 11:22:45 +00:00
|
|
|
options = {
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2015-02-19 04:44:29 +00:00
|
|
|
services.ddclient = with lib.types; {
|
2009-09-16 11:22:45 +00:00
|
|
|
|
|
|
|
enable = mkOption {
|
|
|
|
default = false;
|
2015-02-19 04:44:29 +00:00
|
|
|
type = bool;
|
2009-09-16 11:22:45 +00: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 11:22:45 +00:00
|
|
|
description = ''
|
|
|
|
Domain name to synchronize.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
username = mkOption {
|
|
|
|
default = "";
|
2015-02-19 04:44:29 +00:00
|
|
|
type = str;
|
2009-09-16 11:22:45 +00:00
|
|
|
description = ''
|
|
|
|
Username.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
password = mkOption {
|
2015-02-19 04:44:29 +00:00
|
|
|
default = "";
|
|
|
|
type = str;
|
2009-09-16 11:22:45 +00:00
|
|
|
description = ''
|
|
|
|
Password.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
protocol = mkOption {
|
2015-02-19 04:44:29 +00:00
|
|
|
default = "dyndns2";
|
|
|
|
type = str;
|
2009-09-16 11:22:45 +00: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 11:22:45 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
server = mkOption {
|
2015-02-19 04:44:29 +00:00
|
|
|
default = "";
|
|
|
|
type = str;
|
2009-09-16 11:22:45 +00: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 11:22:45 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
extraConfig = mkOption {
|
2015-02-19 04:44:29 +00:00
|
|
|
default = "";
|
|
|
|
type = str;
|
2009-09-16 11:22:45 +00: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 = ''
|
|
|
|
Method to determine the IP address to send to the dymanic DNS provider.
|
|
|
|
'';
|
2009-09-16 11:22:45 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
|
|
|
config = mkIf config.services.ddclient.enable {
|
|
|
|
|
2015-02-19 04:44:29 +00:00
|
|
|
environment.systemPackages = [ ddclient ];
|
2009-09-16 11:22:45 +00: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 11:22:45 +00:00
|
|
|
|
2015-02-19 04:44:29 +00:00
|
|
|
systemd.services.ddclient = {
|
|
|
|
description = "Dynamic DNS Client";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
after = [ "network.target" ];
|
2015-05-26 03:45:25 +00:00
|
|
|
|
2015-02-19 04:44:29 +00:00
|
|
|
serviceConfig = {
|
2015-04-19 08:00:04 +00: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 17:27:57 +00:00
|
|
|
};
|
2015-02-19 04:44:29 +00:00
|
|
|
};
|
2009-09-16 11:22:45 +00:00
|
|
|
};
|
|
|
|
}
|