| 
									
										
										
										
											2019-07-17 14:19:18 +02:00
										 |  |  | { config, lib, pkgs, options }: | 
					
						
							| 
									
										
										
										
											2019-06-02 03:13:53 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | with lib; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | let | 
					
						
							|  |  |  |   cfg = config.services.prometheus.exporters.wireguard; | 
					
						
							|  |  |  | in { | 
					
						
							|  |  |  |   port = 9586; | 
					
						
							| 
									
										
										
										
											2019-10-13 12:12:58 +02:00
										 |  |  |   imports = [ | 
					
						
							|  |  |  |     (mkRenamedOptionModule [ "addr" ] [ "listenAddress" ]) | 
					
						
							|  |  |  |     ({ options.warnings = options.warnings; options.assertions = options.assertions; }) | 
					
						
							|  |  |  |   ]; | 
					
						
							| 
									
										
										
										
											2019-06-02 03:13:53 +02:00
										 |  |  |   extraOpts = { | 
					
						
							|  |  |  |     verbose = mkEnableOption "Verbose logging mode for prometheus-wireguard-exporter"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     wireguardConfig = mkOption { | 
					
						
							|  |  |  |       type = with types; nullOr (either path str); | 
					
						
							|  |  |  |       default = null; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       description = ''
 | 
					
						
							|  |  |  |         Path to the Wireguard Config to | 
					
						
							|  |  |  |         <link xlink:href="https://github.com/MindFlavor/prometheus_wireguard_exporter/tree/2.0.0#usage">add the peer's name to the stats of a peer</link>. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         Please note that <literal>networking.wg-quick</literal> is required for this feature | 
					
						
							|  |  |  |         as <literal>networking.wireguard</literal> uses | 
					
						
							|  |  |  |         <citerefentry><refentrytitle>wg</refentrytitle><manvolnum>8</manvolnum></citerefentry> | 
					
						
							|  |  |  |         to set the peers up. | 
					
						
							|  |  |  |       '';
 | 
					
						
							|  |  |  |     }; | 
					
						
							| 
									
										
										
										
											2019-07-21 15:41:51 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     singleSubnetPerField = mkOption { | 
					
						
							|  |  |  |       type = types.bool; | 
					
						
							|  |  |  |       default = false; | 
					
						
							|  |  |  |       description = ''
 | 
					
						
							|  |  |  |         By default, all allowed IPs and subnets are comma-separated in the | 
					
						
							|  |  |  |         <literal>allowed_ips</literal> field. With this option enabled, | 
					
						
							|  |  |  |         a single IP and subnet will be listed in fields like <literal>allowed_ip_0</literal>, | 
					
						
							|  |  |  |         <literal>allowed_ip_1</literal> and so on. | 
					
						
							|  |  |  |       '';
 | 
					
						
							|  |  |  |     }; | 
					
						
							| 
									
										
										
										
											2019-08-08 21:54:49 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     withRemoteIp = mkOption { | 
					
						
							|  |  |  |       type = types.bool; | 
					
						
							|  |  |  |       default = false; | 
					
						
							|  |  |  |       description = ''
 | 
					
						
							|  |  |  |         Whether or not the remote IP of a WireGuard peer should be exposed via prometheus. | 
					
						
							|  |  |  |       '';
 | 
					
						
							|  |  |  |     }; | 
					
						
							| 
									
										
										
										
											2019-06-02 03:13:53 +02:00
										 |  |  |   }; | 
					
						
							|  |  |  |   serviceOpts = { | 
					
						
							|  |  |  |     path = [ pkgs.wireguard-tools ]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     serviceConfig = { | 
					
						
							|  |  |  |       AmbientCapabilities = [ "CAP_NET_ADMIN" ]; | 
					
						
							| 
									
										
										
										
											2019-08-02 15:34:19 +02:00
										 |  |  |       ExecStart = ''
 | 
					
						
							|  |  |  |         ${pkgs.prometheus-wireguard-exporter}/bin/prometheus_wireguard_exporter \ | 
					
						
							|  |  |  |           -p ${toString cfg.port} \ | 
					
						
							| 
									
										
										
										
											2019-10-13 12:12:58 +02:00
										 |  |  |           -l ${cfg.listenAddress} \ | 
					
						
							| 
									
										
										
										
											2019-08-02 15:34:19 +02:00
										 |  |  |           ${optionalString cfg.verbose "-v"} \ | 
					
						
							|  |  |  |           ${optionalString cfg.singleSubnetPerField "-s"} \ | 
					
						
							| 
									
										
										
										
											2019-08-08 21:54:49 +02:00
										 |  |  |           ${optionalString cfg.withRemoteIp "-r"} \ | 
					
						
							| 
									
										
										
										
											2019-08-02 15:34:19 +02:00
										 |  |  |           ${optionalString (cfg.wireguardConfig != null) "-n ${cfg.wireguardConfig}"} | 
					
						
							|  |  |  |       '';
 | 
					
						
							| 
									
										
										
										
											2019-06-02 03:13:53 +02:00
										 |  |  |     }; | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | } |