| 
									
										
										
										
											2014-04-14 16:26:48 +02:00
										 |  |  | { config, lib, pkgs, ... }: | 
					
						
							| 
									
										
										
										
											2014-01-04 01:13:26 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | with pkgs; | 
					
						
							| 
									
										
										
										
											2014-05-05 14:58:51 -04:00
										 |  |  | with lib; | 
					
						
							| 
									
										
										
										
											2014-01-04 01:13:26 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | let | 
					
						
							| 
									
										
										
										
											2019-11-24 12:56:44 +01:00
										 |  |  |   cfg = config.services.connman; | 
					
						
							| 
									
										
										
										
											2015-09-12 21:28:53 +09:00
										 |  |  |   configFile = pkgs.writeText "connman.conf" ''
 | 
					
						
							|  |  |  |     [General] | 
					
						
							|  |  |  |     NetworkInterfaceBlacklist=${concatStringsSep "," cfg.networkInterfaceBlacklist} | 
					
						
							| 
									
										
										
										
											2014-01-04 01:13:26 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-12 21:28:53 +09:00
										 |  |  |     ${cfg.extraConfig} | 
					
						
							|  |  |  |   '';
 | 
					
						
							| 
									
										
										
										
											2019-12-21 13:48:15 -08:00
										 |  |  |   enableIwd = cfg.wifi.backend == "iwd"; | 
					
						
							| 
									
										
										
										
											2014-01-04 01:13:26 +01:00
										 |  |  | in { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-10 02:51:19 +01:00
										 |  |  |   imports = [ | 
					
						
							|  |  |  |     (mkRenamedOptionModule [ "networking" "connman" ] [ "services" "connman" ]) | 
					
						
							|  |  |  |   ]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-04 01:13:26 +01:00
										 |  |  |   ###### interface | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   options = { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-24 12:56:44 +01:00
										 |  |  |     services.connman = { | 
					
						
							| 
									
										
										
										
											2014-01-04 01:13:26 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |       enable = mkOption { | 
					
						
							|  |  |  |         type = types.bool; | 
					
						
							|  |  |  |         default = false; | 
					
						
							|  |  |  |         description = ''
 | 
					
						
							|  |  |  |           Whether to use ConnMan for managing your network connections. | 
					
						
							|  |  |  |         '';
 | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-25 08:02:29 +02:00
										 |  |  |       enableVPN = mkOption { | 
					
						
							|  |  |  |         type = types.bool; | 
					
						
							|  |  |  |         default = true; | 
					
						
							|  |  |  |         description = ''
 | 
					
						
							|  |  |  |           Whether to enable ConnMan VPN service. | 
					
						
							|  |  |  |         '';
 | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-12 21:28:53 +09:00
										 |  |  |       extraConfig = mkOption { | 
					
						
							|  |  |  |         type = types.lines; | 
					
						
							|  |  |  |         default = ''
 | 
					
						
							|  |  |  |         '';
 | 
					
						
							|  |  |  |         description = ''
 | 
					
						
							|  |  |  |           Configuration lines appended to the generated connman configuration file. | 
					
						
							|  |  |  |         '';
 | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       networkInterfaceBlacklist = mkOption { | 
					
						
							| 
									
										
										
										
											2019-08-08 22:48:27 +02:00
										 |  |  |         type = with types; listOf str; | 
					
						
							| 
									
										
										
										
											2015-09-12 21:28:53 +09:00
										 |  |  |         default = [ "vmnet" "vboxnet" "virbr" "ifb" "ve" ]; | 
					
						
							|  |  |  |         description = ''
 | 
					
						
							|  |  |  |           Default blacklisted interfaces, this includes NixOS containers interfaces (ve). | 
					
						
							|  |  |  |         '';
 | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-21 13:48:15 -08:00
										 |  |  |       wifi = { | 
					
						
							|  |  |  |         backend = mkOption { | 
					
						
							|  |  |  |           type = types.enum [ "wpa_supplicant" "iwd" ]; | 
					
						
							|  |  |  |           default = "wpa_supplicant"; | 
					
						
							|  |  |  |           description = ''
 | 
					
						
							|  |  |  |             Specify the Wi-Fi backend used. | 
					
						
							|  |  |  |             Currently supported are <option>wpa_supplicant</option> or <option>iwd</option>. | 
					
						
							|  |  |  |           '';
 | 
					
						
							|  |  |  |         }; | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-13 20:10:03 +02:00
										 |  |  |       extraFlags = mkOption { | 
					
						
							| 
									
										
										
										
											2019-08-08 22:48:27 +02:00
										 |  |  |         type = with types; listOf str; | 
					
						
							| 
									
										
										
										
											2016-09-13 20:10:03 +02:00
										 |  |  |         default = [ ]; | 
					
						
							|  |  |  |         example = [ "--nodnsproxy" ]; | 
					
						
							|  |  |  |         description = ''
 | 
					
						
							|  |  |  |           Extra flags to pass to connmand | 
					
						
							|  |  |  |         '';
 | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-28 12:06:54 +03:00
										 |  |  |       package = mkOption { | 
					
						
							|  |  |  |         type = types.path; | 
					
						
							|  |  |  |         description = "The connman package / build flavor"; | 
					
						
							|  |  |  |         default = connman; | 
					
						
							|  |  |  |         example = literalExample "pkgs.connmanFull"; | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-04 01:13:26 +01:00
										 |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   ###### implementation | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   config = mkIf cfg.enable { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     assertions = [{ | 
					
						
							| 
									
										
										
										
											2016-02-01 17:51:04 +01:00
										 |  |  |       assertion = !config.networking.useDHCP; | 
					
						
							| 
									
										
										
										
											2019-11-24 12:56:44 +01:00
										 |  |  |       message = "You can not use services.connman with networking.useDHCP"; | 
					
						
							| 
									
										
										
										
											2014-01-04 01:13:26 +01:00
										 |  |  |     }{ | 
					
						
							| 
									
										
										
										
											2020-03-28 12:28:29 +03:00
										 |  |  |       # TODO: connman seemingly can be used along network manager and | 
					
						
							|  |  |  |       # connmanFull supports this - so this should be worked out somehow | 
					
						
							| 
									
										
										
										
											2016-02-01 19:33:50 +01:00
										 |  |  |       assertion = !config.networking.networkmanager.enable; | 
					
						
							| 
									
										
										
										
											2019-11-24 12:56:44 +01:00
										 |  |  |       message = "You can not use services.connman with networking.networkmanager"; | 
					
						
							| 
									
										
										
										
											2014-01-04 01:13:26 +01:00
										 |  |  |     }]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-28 12:06:54 +03:00
										 |  |  |     environment.systemPackages = [ cfg.package ]; | 
					
						
							| 
									
										
										
										
											2014-01-04 01:13:26 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-13 21:52:01 +00:00
										 |  |  |     systemd.services.connman = { | 
					
						
							| 
									
										
										
										
											2014-01-04 01:13:26 +01:00
										 |  |  |       description = "Connection service"; | 
					
						
							|  |  |  |       wantedBy = [ "multi-user.target" ]; | 
					
						
							| 
									
										
										
										
											2019-12-21 13:48:15 -08:00
										 |  |  |       after = [ "syslog.target" ] ++ optional enableIwd "iwd.service"; | 
					
						
							|  |  |  |       requires = optional enableIwd "iwd.service"; | 
					
						
							| 
									
										
										
										
											2014-01-04 01:13:26 +01:00
										 |  |  |       serviceConfig = { | 
					
						
							|  |  |  |         Type = "dbus"; | 
					
						
							|  |  |  |         BusName = "net.connman"; | 
					
						
							|  |  |  |         Restart = "on-failure"; | 
					
						
							| 
									
										
										
										
											2019-12-21 13:48:15 -08:00
										 |  |  |         ExecStart = toString ([ | 
					
						
							| 
									
										
										
										
											2020-03-28 12:06:54 +03:00
										 |  |  |           "${cfg.package}/sbin/connmand" | 
					
						
							| 
									
										
										
										
											2019-12-21 13:48:15 -08:00
										 |  |  |           "--config=${configFile}" | 
					
						
							|  |  |  |           "--nodaemon" | 
					
						
							|  |  |  |         ] ++ optional enableIwd "--wifi=iwd_agent" | 
					
						
							|  |  |  |           ++ cfg.extraFlags); | 
					
						
							| 
									
										
										
										
											2014-01-04 01:13:26 +01:00
										 |  |  |         StandardOutput = "null"; | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-13 21:52:01 +00:00
										 |  |  |     systemd.services.connman-vpn = mkIf cfg.enableVPN { | 
					
						
							| 
									
										
										
										
											2014-01-04 01:13:26 +01:00
										 |  |  |       description = "ConnMan VPN service"; | 
					
						
							|  |  |  |       wantedBy = [ "multi-user.target" ]; | 
					
						
							|  |  |  |       after = [ "syslog.target" ]; | 
					
						
							| 
									
										
										
										
											2014-01-11 21:17:17 +01:00
										 |  |  |       before = [ "connman" ]; | 
					
						
							| 
									
										
										
										
											2014-01-04 01:13:26 +01:00
										 |  |  |       serviceConfig = { | 
					
						
							|  |  |  |         Type = "dbus"; | 
					
						
							|  |  |  |         BusName = "net.connman.vpn"; | 
					
						
							| 
									
										
										
										
											2020-03-28 12:06:54 +03:00
										 |  |  |         ExecStart = "${cfg.package}/sbin/connman-vpnd -n"; | 
					
						
							| 
									
										
										
										
											2014-01-04 01:13:26 +01:00
										 |  |  |         StandardOutput = "null"; | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-13 21:52:01 +00:00
										 |  |  |     systemd.services.net-connman-vpn = mkIf cfg.enableVPN { | 
					
						
							| 
									
										
										
										
											2014-01-04 01:13:26 +01:00
										 |  |  |       description = "D-BUS Service"; | 
					
						
							|  |  |  |       serviceConfig = { | 
					
						
							|  |  |  |         Name = "net.connman.vpn"; | 
					
						
							| 
									
										
										
										
											2014-01-11 21:17:17 +01:00
										 |  |  |         before = [ "connman" ]; | 
					
						
							| 
									
										
										
										
											2020-03-28 12:06:54 +03:00
										 |  |  |         ExecStart = "${cfg.package}/sbin/connman-vpnd -n"; | 
					
						
							| 
									
										
										
										
											2014-01-04 01:13:26 +01:00
										 |  |  |         User = "root"; | 
					
						
							|  |  |  |         SystemdService = "connman-vpn.service"; | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     networking = { | 
					
						
							|  |  |  |       useDHCP = false; | 
					
						
							| 
									
										
										
										
											2019-12-21 13:48:15 -08:00
										 |  |  |       wireless = { | 
					
						
							|  |  |  |         enable = mkIf (!enableIwd) true; | 
					
						
							|  |  |  |         iwd = mkIf enableIwd { | 
					
						
							|  |  |  |           enable = true; | 
					
						
							|  |  |  |         }; | 
					
						
							|  |  |  |       }; | 
					
						
							| 
									
										
										
										
											2014-01-04 01:13:26 +01:00
										 |  |  |       networkmanager.enable = false; | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | } |