about summary refs log tree commit diff
path: root/nixos/modules/services/networking
diff options
context:
space:
mode:
authorlethalman <lucabru@src.gnome.org>2015-03-17 12:38:12 +0100
committerlethalman <lucabru@src.gnome.org>2015-03-17 12:38:12 +0100
commit359bc60ec817f9e019e0f86e22e1ad8a6aaf48e8 (patch)
tree2103eaadd5ba7ea751cac0f972777540fc00320e /nixos/modules/services/networking
parentc812ded1eadb575e15dfee3a62f95b52afc7df5c (diff)
parent4bf66ba89caacc99605aea46fe937a2acb31c446 (diff)
downloadnixlib-359bc60ec817f9e019e0f86e22e1ad8a6aaf48e8.tar
nixlib-359bc60ec817f9e019e0f86e22e1ad8a6aaf48e8.tar.gz
nixlib-359bc60ec817f9e019e0f86e22e1ad8a6aaf48e8.tar.bz2
nixlib-359bc60ec817f9e019e0f86e22e1ad8a6aaf48e8.tar.lz
nixlib-359bc60ec817f9e019e0f86e22e1ad8a6aaf48e8.tar.xz
nixlib-359bc60ec817f9e019e0f86e22e1ad8a6aaf48e8.tar.zst
nixlib-359bc60ec817f9e019e0f86e22e1ad8a6aaf48e8.zip
Merge pull request #6448 from eduarrrd/ddclient
ddclient module: fix module
Diffstat (limited to 'nixos/modules/services/networking')
-rw-r--r--nixos/modules/services/networking/ddclient.nix97
1 files changed, 57 insertions, 40 deletions
diff --git a/nixos/modules/services/networking/ddclient.nix b/nixos/modules/services/networking/ddclient.nix
index bb94a8dacfa2..f01deb6ee7c8 100644
--- a/nixos/modules/services/networking/ddclient.nix
+++ b/nixos/modules/services/networking/ddclient.nix
@@ -3,24 +3,22 @@
 let
 
   inherit (lib) mkOption mkIf singleton;
-
   inherit (pkgs) ddclient;
 
   stateDir = "/var/spool/ddclient";
-
   ddclientUser = "ddclient";
-
-  ddclientFlags = "-foreground -file ${ddclientCfg}";
-
+  ddclientFlags = "-foreground -verbose -noquiet -file ${ddclientCfg}";
+  ddclientPIDFile = "${stateDir}/ddclient.pid";
   ddclientCfg = pkgs.writeText "ddclient.conf" ''
     daemon=600
     cache=${stateDir}/ddclient.cache
-    pid=${stateDir}/ddclient.pid
-    use=${config.services.ddclient.web}
+    pid=${ddclientPIDFile}
+    use=${config.services.ddclient.use}
     login=${config.services.ddclient.username}
     password=${config.services.ddclient.password}
     protocol=${config.services.ddclient.protocol}
     server=${config.services.ddclient.server}
+    ssl=${if config.services.ddclient.ssl then "yes" else "yes"}
     wildcard=YES
     ${config.services.ddclient.domain}
     ${config.services.ddclient.extraConfig}
@@ -34,10 +32,11 @@ in
 
   options = {
 
-    services.ddclient = {
+    services.ddclient = with lib.types; {
 
       enable = mkOption {
         default = false;
+        type = bool;
         description = ''
           Whether to synchronise your machine's IP address with a dynamic DNS provider (e.g. dyndns.org).
         '';
@@ -45,6 +44,7 @@ in
 
       domain = mkOption {
         default = "";
+        type = str;
         description = ''
           Domain name to synchronize.
         '';
@@ -52,76 +52,93 @@ in
 
       username = mkOption {
         default = "";
+        type = str;
         description = ''
           Username.
         '';
       };
 
       password = mkOption {
-        default = "" ;
+        default = "";
+        type = str;
         description = ''
           Password.
         '';
       };
 
       protocol = mkOption {
-        default = "dyndns2" ;
+        default = "dyndns2";
+        type = str;
         description = ''
-          Protocol to use with dynamic DNS provider. (see also, http://sourceforge.net/apps/trac/ddclient/wiki/Protocols)
+          Protocol to use with dynamic DNS provider (see http://sourceforge.net/apps/trac/ddclient/wiki/Protocols).
         '';
       };
 
       server = mkOption {
-        default = "members.dyndns.org" ;
+        default = "";
+        type = str;
         description = ''
-          Server
+          Server address.
+        '';
+      };
+
+      ssl = mkOption {
+        default = true;
+        type = bool;
+        description = ''
+          Whether to use to use SSL/TLS to connect to dynamic DNS provider.
         '';
       };
 
       extraConfig = mkOption {
-        default = "" ;
+        default = "";
+        type = str;
         description = ''
           Extra configuration. Contents will be added verbatim to the configuration file.
         '';
       };
 
-      web = mkOption {
-        default = "web, web=checkip.dyndns.com/, web-skip='Current IP Address: '" ;
-        description = "";
+      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.
+        '';
       };
-
     };
-
   };
 
 
   ###### 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";
+    environment.systemPackages = [ ddclient ];
 
-        preStart =
-          ''
-            mkdir -m 0755 -p ${stateDir}
-            chown ${ddclientUser} ${stateDir}
-          '';
+    users.extraUsers = singleton {
+      name = ddclientUser;
+      uid = config.ids.uids.ddclient;
+      description = "ddclient daemon user";
+      home = stateDir;
+    };
 
-        exec = "${ddclient}/bin/ddclient ${ddclientFlags}";
+    systemd.services.ddclient = {
+      description = "Dynamic DNS Client";
+      wantedBy = [ "multi-user.target" ];
+      after = [ "network.target" ];
+      serviceConfig = {
+        # This may change back to forking if too many problems occur:
+        type = "simple";
+        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?
       };
-
+    };
   };
-
 }