1{
2 config,
3 lib,
4 pkgs,
5 ...
6}:
7
8let
9 cfg = config.services.connman;
10 configFile = pkgs.writeText "connman.conf" ''
11 [General]
12 NetworkInterfaceBlacklist=${lib.concatStringsSep "," cfg.networkInterfaceBlacklist}
13
14 ${cfg.extraConfig}
15 '';
16 enableIwd = cfg.wifi.backend == "iwd";
17in
18{
19 meta.maintainers = with lib.maintainers; [ ];
20
21 imports = [
22 (lib.mkRenamedOptionModule [ "networking" "connman" ] [ "services" "connman" ])
23 ];
24
25 ###### interface
26
27 options = {
28 services.connman = {
29 enable = lib.mkOption {
30 type = lib.types.bool;
31 default = false;
32 description = ''
33 Whether to use ConnMan for managing your network connections.
34 '';
35 };
36
37 package = lib.mkOption {
38 type = lib.types.package;
39 description = "The connman package / build flavor";
40 default = pkgs.connman;
41 defaultText = lib.literalExpression "pkgs.connman";
42 example = lib.literalExpression "pkgs.connmanFull";
43 };
44
45 enableVPN = lib.mkOption {
46 type = lib.types.bool;
47 default = true;
48 description = ''
49 Whether to enable ConnMan VPN service.
50 '';
51 };
52
53 extraConfig = lib.mkOption {
54 type = lib.types.lines;
55 default = "";
56 description = ''
57 Configuration lines appended to the generated connman configuration file.
58 '';
59 };
60
61 networkInterfaceBlacklist = lib.mkOption {
62 type = with lib.types; listOf str;
63 default = [
64 "vmnet"
65 "vboxnet"
66 "virbr"
67 "ifb"
68 "ve"
69 ];
70 description = ''
71 Default blacklisted interfaces, this includes NixOS containers interfaces (ve).
72 '';
73 };
74
75 wifi = {
76 backend = lib.mkOption {
77 type = lib.types.enum [
78 "wpa_supplicant"
79 "iwd"
80 ];
81 default = "wpa_supplicant";
82 description = ''
83 Specify the Wi-Fi backend used.
84 Currently supported are {option}`wpa_supplicant` or {option}`iwd`.
85 '';
86 };
87 };
88
89 extraFlags = lib.mkOption {
90 type = with lib.types; listOf str;
91 default = [ ];
92 example = [ "--nodnsproxy" ];
93 description = ''
94 Extra flags to pass to connmand
95 '';
96 };
97 };
98 };
99
100 ###### implementation
101
102 config = lib.mkIf cfg.enable {
103 assertions = [
104 {
105 assertion = !config.networking.useDHCP;
106 message = "You can not use services.connman with networking.useDHCP";
107 }
108 {
109 # TODO: connman seemingly can be used along network manager and
110 # connmanFull supports this - so this should be worked out somehow
111 assertion = !config.networking.networkmanager.enable;
112 message = "You can not use services.connman with networking.networkmanager";
113 }
114 ];
115
116 environment.systemPackages = [ cfg.package ];
117
118 systemd.services.connman = {
119 description = "Connection service";
120 wantedBy = [ "multi-user.target" ];
121 after = lib.optional enableIwd "iwd.service";
122 requires = lib.optional enableIwd "iwd.service";
123 serviceConfig = {
124 Type = "dbus";
125 BusName = "net.connman";
126 Restart = "on-failure";
127 ExecStart = toString (
128 [
129 "${cfg.package}/sbin/connmand"
130 "--config=${configFile}"
131 "--nodaemon"
132 ]
133 ++ lib.optional enableIwd "--wifi=iwd_agent"
134 ++ cfg.extraFlags
135 );
136 StandardOutput = "null";
137 };
138 };
139
140 systemd.services.connman-vpn = lib.mkIf cfg.enableVPN {
141 description = "ConnMan VPN service";
142 wantedBy = [ "multi-user.target" ];
143 before = [ "connman.service" ];
144 serviceConfig = {
145 Type = "dbus";
146 BusName = "net.connman.vpn";
147 ExecStart = "${cfg.package}/sbin/connman-vpnd -n";
148 StandardOutput = "null";
149 };
150 };
151
152 systemd.services.net-connman-vpn = lib.mkIf cfg.enableVPN {
153 description = "D-BUS Service";
154 serviceConfig = {
155 Name = "net.connman.vpn";
156 before = [ "connman.service" ];
157 ExecStart = "${cfg.package}/sbin/connman-vpnd -n";
158 User = "root";
159 SystemdService = "connman-vpn.service";
160 };
161 };
162
163 networking = {
164 useDHCP = false;
165 wireless = {
166 enable = lib.mkIf (!enableIwd) true;
167 dbusControlled = true;
168 iwd = lib.mkIf enableIwd {
169 enable = true;
170 };
171 };
172 networkmanager.enable = false;
173 };
174 };
175}