| 
									
										
										
										
											2014-04-14 16:26:48 +02:00
										 |  |  | { config, lib, pkgs, ... }: | 
					
						
							| 
									
										
										
										
											2011-04-13 14:09:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-14 16:26:48 +02:00
										 |  |  | with lib; | 
					
						
							| 
									
										
										
										
											2011-04-13 14:09:02 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | let | 
					
						
							|  |  |  |   cfg = config.services.dnsmasq; | 
					
						
							|  |  |  |   dnsmasq = pkgs.dnsmasq; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-12 17:58:48 +01:00
										 |  |  |   dnsmasqConf = pkgs.writeText "dnsmasq.conf" ''
 | 
					
						
							| 
									
										
										
										
											2014-07-03 01:59:35 +03:00
										 |  |  |     ${optionalString cfg.resolveLocalQueries ''
 | 
					
						
							|  |  |  |       conf-file=/etc/dnsmasq-conf.conf | 
					
						
							|  |  |  |       resolv-file=/etc/dnsmasq-resolv.conf | 
					
						
							|  |  |  |     ''}
 | 
					
						
							| 
									
										
										
										
											2014-09-02 15:36:25 -07:00
										 |  |  |     ${flip concatMapStrings cfg.servers (server: ''
 | 
					
						
							|  |  |  |       server=${server} | 
					
						
							|  |  |  |     '')}
 | 
					
						
							|  |  |  |     ${cfg.extraConfig} | 
					
						
							| 
									
										
										
										
											2012-11-12 17:58:48 +01:00
										 |  |  |   '';
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-13 14:09:02 +00:00
										 |  |  | in | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   ###### interface | 
					
						
							| 
									
										
										
										
											2011-09-14 18:20:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-13 14:09:02 +00:00
										 |  |  |   options = { | 
					
						
							| 
									
										
										
										
											2011-09-14 18:20:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-13 14:09:02 +00:00
										 |  |  |     services.dnsmasq = { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       enable = mkOption { | 
					
						
							| 
									
										
										
										
											2011-04-19 13:37:31 +00:00
										 |  |  |         default = false; | 
					
						
							| 
									
										
										
										
											2011-04-13 14:09:02 +00:00
										 |  |  |         description = ''
 | 
					
						
							|  |  |  |           Whether to run dnsmasq. | 
					
						
							|  |  |  |         '';
 | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-03 01:59:35 +03:00
										 |  |  |       resolveLocalQueries = mkOption { | 
					
						
							|  |  |  |         default = true; | 
					
						
							|  |  |  |         description = ''
 | 
					
						
							|  |  |  |           Whether dnsmasq should resolve local queries (i.e. add 127.0.0.1 to | 
					
						
							|  |  |  |           /etc/resolv.conf) | 
					
						
							|  |  |  |         '';
 | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-13 14:09:02 +00:00
										 |  |  |       servers = mkOption { | 
					
						
							|  |  |  |         default = []; | 
					
						
							|  |  |  |         example = [ "8.8.8.8" "8.8.4.4" ]; | 
					
						
							|  |  |  |         description = ''
 | 
					
						
							| 
									
										
										
										
											2014-09-03 20:03:03 +04:00
										 |  |  |           The DNS servers which dnsmasq should query. | 
					
						
							| 
									
										
										
										
											2011-04-13 14:09:02 +00:00
										 |  |  |         '';
 | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-12 17:58:48 +01:00
										 |  |  |       extraConfig = mkOption { | 
					
						
							|  |  |  |         type = types.string; | 
					
						
							|  |  |  |         default = ""; | 
					
						
							|  |  |  |         description = ''
 | 
					
						
							|  |  |  |           Extra configuration directives that should be added to | 
					
						
							|  |  |  |           <literal>dnsmasq.conf</literal> | 
					
						
							|  |  |  |         '';
 | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-13 14:09:02 +00:00
										 |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   ###### implementation | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   config = mkIf config.services.dnsmasq.enable { | 
					
						
							| 
									
										
										
										
											2011-09-14 18:20:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-02 15:36:25 -07:00
										 |  |  |     networking.nameservers = | 
					
						
							|  |  |  |       optional cfg.resolveLocalQueries "127.0.0.1"; | 
					
						
							| 
									
										
										
										
											2011-04-13 14:09:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-03 01:59:35 +03:00
										 |  |  |     services.dbus.packages = [ dnsmasq ]; | 
					
						
							| 
									
										
										
										
											2011-04-13 14:09:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-03 01:59:35 +03:00
										 |  |  |     users.extraUsers = singleton | 
					
						
							|  |  |  |       { name = "dnsmasq"; | 
					
						
							|  |  |  |         uid = config.ids.uids.dnsmasq; | 
					
						
							|  |  |  |         description = "Dnsmasq daemon user"; | 
					
						
							|  |  |  |         home = "/var/empty"; | 
					
						
							| 
									
										
										
										
											2011-04-13 14:09:02 +00:00
										 |  |  |       }; | 
					
						
							| 
									
										
										
										
											2011-09-14 18:20:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-03 01:59:35 +03:00
										 |  |  |     systemd.services.dnsmasq = { | 
					
						
							|  |  |  |         description = "dnsmasq daemon"; | 
					
						
							| 
									
										
										
										
											2015-02-25 09:22:16 -08:00
										 |  |  |         after = [ "network.target" "systemd-resolved.service" ]; | 
					
						
							| 
									
										
										
										
											2014-07-03 01:59:35 +03:00
										 |  |  |         wantedBy = [ "multi-user.target" ]; | 
					
						
							| 
									
										
										
										
											2014-09-02 15:36:25 -07:00
										 |  |  |         path = [ dnsmasq ]; | 
					
						
							|  |  |  |         preStart = ''
 | 
					
						
							|  |  |  |           touch /etc/dnsmasq-{conf,resolv}.conf | 
					
						
							|  |  |  |           dnsmasq --test | 
					
						
							|  |  |  |         '';
 | 
					
						
							| 
									
										
										
										
											2014-07-03 01:59:35 +03:00
										 |  |  |         serviceConfig = { | 
					
						
							|  |  |  |           Type = "dbus"; | 
					
						
							|  |  |  |           BusName = "uk.org.thekelleys.dnsmasq"; | 
					
						
							|  |  |  |           ExecStart = "${dnsmasq}/bin/dnsmasq -k --enable-dbus --user=dnsmasq -C ${dnsmasqConf}"; | 
					
						
							|  |  |  |           ExecReload = "${dnsmasq}/bin/kill -HUP $MAINPID"; | 
					
						
							|  |  |  |         }; | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-13 14:09:02 +00:00
										 |  |  |   }; | 
					
						
							| 
									
										
										
										
											2011-09-14 18:20:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-13 14:09:02 +00:00
										 |  |  | } |