| 
									
										
										
										
											2014-05-05 14:58:51 -04:00
										 |  |  | { config, pkgs, lib, ... }: | 
					
						
							| 
									
										
										
										
											2009-09-16 11:22:45 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | let | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-05 14:58:51 -04:00
										 |  |  |   inherit (lib) mkOption mkIf singleton; | 
					
						
							| 
									
										
										
										
											2009-09-16 11:22:45 +00:00
										 |  |  |   inherit (pkgs) ddclient; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   stateDir = "/var/spool/ddclient"; | 
					
						
							|  |  |  |   ddclientUser = "ddclient"; | 
					
						
							| 
									
										
										
										
											2016-06-19 21:51:05 +02:00
										 |  |  |   ddclientFlags = "-foreground -verbose -noquiet -file /etc/ddclient.conf"; | 
					
						
							| 
									
										
										
										
											2015-02-18 23:44:29 -05:00
										 |  |  |   ddclientPIDFile = "${stateDir}/ddclient.pid"; | 
					
						
							| 
									
										
										
										
											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-18 23:44:29 -05:00
										 |  |  |     services.ddclient = with lib.types; { | 
					
						
							| 
									
										
										
										
											2009-09-16 11:22:45 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |       enable = mkOption { | 
					
						
							|  |  |  |         default = false; | 
					
						
							| 
									
										
										
										
											2015-02-18 23:44:29 -05: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-18 23:44:29 -05:00
										 |  |  |         type = str; | 
					
						
							| 
									
										
										
										
											2009-09-16 11:22:45 +00:00
										 |  |  |         description = ''
 | 
					
						
							|  |  |  |           Domain name to synchronize. | 
					
						
							|  |  |  |         '';
 | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       username = mkOption { | 
					
						
							|  |  |  |         default = ""; | 
					
						
							| 
									
										
										
										
											2015-02-18 23:44:29 -05:00
										 |  |  |         type = str; | 
					
						
							| 
									
										
										
										
											2009-09-16 11:22:45 +00:00
										 |  |  |         description = ''
 | 
					
						
							|  |  |  |           Username. | 
					
						
							|  |  |  |         '';
 | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       password = mkOption { | 
					
						
							| 
									
										
										
										
											2015-02-18 23:44:29 -05:00
										 |  |  |         default = ""; | 
					
						
							|  |  |  |         type = str; | 
					
						
							| 
									
										
										
										
											2009-09-16 11:22:45 +00:00
										 |  |  |         description = ''
 | 
					
						
							| 
									
										
										
										
											2016-07-19 16:49:46 +02:00
										 |  |  |           Password. WARNING: The password becomes world readable in the Nix store. | 
					
						
							| 
									
										
										
										
											2009-09-16 11:22:45 +00:00
										 |  |  |         '';
 | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       protocol = mkOption { | 
					
						
							| 
									
										
										
										
											2015-02-18 23:44:29 -05:00
										 |  |  |         default = "dyndns2"; | 
					
						
							|  |  |  |         type = str; | 
					
						
							| 
									
										
										
										
											2009-09-16 11:22:45 +00:00
										 |  |  |         description = ''
 | 
					
						
							| 
									
										
										
										
											2015-02-18 23:44:29 -05: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-18 23:44:29 -05:00
										 |  |  |         default = ""; | 
					
						
							|  |  |  |         type = str; | 
					
						
							| 
									
										
										
										
											2009-09-16 11:22:45 +00:00
										 |  |  |         description = ''
 | 
					
						
							| 
									
										
										
										
											2015-02-18 23:44:29 -05: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-18 23:44:29 -05: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-18 23:44:29 -05: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-18 23:44:29 -05:00
										 |  |  |     environment.systemPackages = [ ddclient ]; | 
					
						
							| 
									
										
										
										
											2009-09-16 11:22:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-18 23:44:29 -05: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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-19 21:51:05 +02:00
										 |  |  |     environment.etc."ddclient.conf" = { | 
					
						
							|  |  |  |       uid = config.ids.uids.ddclient; | 
					
						
							|  |  |  |       mode = "0600"; | 
					
						
							|  |  |  |       text = ''
 | 
					
						
							|  |  |  |         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} | 
					
						
							|  |  |  |         server=${config.services.ddclient.server} | 
					
						
							|  |  |  |         ssl=${if config.services.ddclient.ssl then "yes" else "no"} | 
					
						
							|  |  |  |         wildcard=YES | 
					
						
							|  |  |  |         ${config.services.ddclient.domain} | 
					
						
							|  |  |  |         ${config.services.ddclient.extraConfig} | 
					
						
							|  |  |  |       '';
 | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-18 23:44:29 -05:00
										 |  |  |     systemd.services.ddclient = { | 
					
						
							|  |  |  |       description = "Dynamic DNS Client"; | 
					
						
							|  |  |  |       wantedBy = [ "multi-user.target" ]; | 
					
						
							|  |  |  |       after = [ "network.target" ]; | 
					
						
							| 
									
										
										
										
											2016-06-19 21:51:05 +02:00
										 |  |  |       restartTriggers = [ config.environment.etc."ddclient.conf".source ]; | 
					
						
							| 
									
										
										
										
											2015-05-26 06:45:25 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-18 23:44:29 -05:00
										 |  |  |       serviceConfig = { | 
					
						
							| 
									
										
										
										
											2015-04-19 11:00:04 +03:00
										 |  |  |         # Uncomment this if too many problems occur: | 
					
						
							|  |  |  |         # Type = "forking"; | 
					
						
							| 
									
										
										
										
											2015-02-18 23:44:29 -05: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-18 23:44:29 -05:00
										 |  |  |     }; | 
					
						
							| 
									
										
										
										
											2009-09-16 11:22:45 +00:00
										 |  |  |   }; | 
					
						
							|  |  |  | } |