summary refs log tree commit diff
path: root/nixos/modules/services/networking/ddclient.nix
blob: 62709a040a1f3a117ea4c975355f14d55e1a1e02 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
{ config, pkgs, ... }:

let

  inherit (pkgs.lib) mkOption mkIf singleton;

  inherit (pkgs) ddclient;

  stateDir = "/var/spool/ddclient";

  ddclientUser = "ddclient";

  ddclientFlags = "-foreground -file ${ddclientCfg}";

  ddclientCfg = pkgs.writeText "ddclient.conf" ''
    daemon=600
    cache=${stateDir}/ddclient.cache
    pid=${stateDir}/ddclient.pid
    use=${config.services.ddclient.web}
    login=${config.services.ddclient.username}
    password=${config.services.ddclient.password}
    protocol=${config.services.ddclient.protocol}
    server=${config.services.ddclient.server}
    wildcard=YES
    ${config.services.ddclient.domain}
    ${config.services.ddclient.extraConfig}
  '';

in

{

  ###### interface

  options = {

    services.ddclient = {

      enable = mkOption {
        default = false;
        description = ''
          Whether to synchronise your machine's IP address with a dynamic DNS provider (e.g. dyndns.org).
        '';
      };

      domain = mkOption {
        default = "";
        description = ''
          Domain name to synchronize.
        '';
      };

      username = mkOption {
        default = "";
        description = ''
          Username.
        '';
      };

      password = mkOption {
        default = "" ;
        description = ''
          Password.
        '';
      };

      protocol = mkOption {
        default = "dyndns2" ;
        description = ''
          Protocol to use with dynamic DNS provider. (see also, http://sourceforge.net/apps/trac/ddclient/wiki/Protocols)
        '';
      };

      server = mkOption {
        default = "members.dyndns.org" ;
        description = ''
          Server
        '';
      };

      extraConfig = mkOption {
        default = "" ;
        description = ''
          Extra configuration. Contents will be added verbatim to the configuration file.
        '';
      };

      web = mkOption {
        default = "web, web=checkip.dyndns.com/, web-skip='IP Address'" ;
        description = "";
      };

    };

  };


  ###### implementation

  config = mkIf config.services.ddclient.enable {
  
    environment.systemPackages = [ ddclient ];

    users.extraUsers = singleton
      { name = ddclientUser;
        uid = config.ids.uids.ddclient;
        description = "ddclient daemon user";
        home = stateDir;
      };

    jobs.ddclient =
      { name = "ddclient";

        startOn = "startup";

        preStart =
          ''
            mkdir -m 0755 -p ${stateDir}
            chown ${ddclientUser} ${stateDir}
          '';

        exec = "${ddclient}/bin/ddclient ${ddclientFlags}";
      };

  };

}