1{ config, lib, pkgs, ... }:
2
3with pkgs;
4with lib;
5
6let
7 cfg = config.networking.connman;
8 configFile = pkgs.writeText "connman.conf" ''
9 [General]
10 NetworkInterfaceBlacklist=${concatStringsSep "," cfg.networkInterfaceBlacklist}
11
12 ${cfg.extraConfig}
13 '';
14in {
15
16 ###### interface
17
18 options = {
19
20 networking.connman = {
21
22 enable = mkOption {
23 type = types.bool;
24 default = false;
25 description = ''
26 Whether to use ConnMan for managing your network connections.
27 '';
28 };
29
30 enableVPN = mkOption {
31 type = types.bool;
32 default = true;
33 description = ''
34 Whether to enable ConnMan VPN service.
35 '';
36 };
37
38 extraConfig = mkOption {
39 type = types.lines;
40 default = ''
41 '';
42 description = ''
43 Configuration lines appended to the generated connman configuration file.
44 '';
45 };
46
47 networkInterfaceBlacklist = mkOption {
48 type = with types; listOf string;
49 default = [ "vmnet" "vboxnet" "virbr" "ifb" "ve" ];
50 description = ''
51 Default blacklisted interfaces, this includes NixOS containers interfaces (ve).
52 '';
53 };
54
55 extraFlags = mkOption {
56 type = with types; listOf string;
57 default = [ ];
58 example = [ "--nodnsproxy" ];
59 description = ''
60 Extra flags to pass to connmand
61 '';
62 };
63
64 };
65
66 };
67
68 ###### implementation
69
70 config = mkIf cfg.enable {
71
72 assertions = [{
73 assertion = !config.networking.useDHCP;
74 message = "You can not use services.networking.connman with services.networking.useDHCP";
75 }{
76 assertion = config.networking.wireless.enable;
77 message = "You must use services.networking.connman with services.networking.wireless";
78 }{
79 assertion = !config.networking.networkmanager.enable;
80 message = "You can not use services.networking.connman with services.networking.networkmanager";
81 }];
82
83 environment.systemPackages = [ connman ];
84
85 systemd.services."connman" = {
86 description = "Connection service";
87 wantedBy = [ "multi-user.target" ];
88 after = [ "syslog.target" ];
89 serviceConfig = {
90 Type = "dbus";
91 BusName = "net.connman";
92 Restart = "on-failure";
93 ExecStart = "${pkgs.connman}/sbin/connmand --config=${configFile} --nodaemon ${toString cfg.extraFlags}";
94 StandardOutput = "null";
95 };
96 };
97
98 systemd.services."connman-vpn" = mkIf cfg.enableVPN {
99 description = "ConnMan VPN service";
100 wantedBy = [ "multi-user.target" ];
101 after = [ "syslog.target" ];
102 before = [ "connman" ];
103 serviceConfig = {
104 Type = "dbus";
105 BusName = "net.connman.vpn";
106 ExecStart = "${pkgs.connman}/sbin/connman-vpnd -n";
107 StandardOutput = "null";
108 };
109 };
110
111 systemd.services."net-connman-vpn" = mkIf cfg.enableVPN {
112 description = "D-BUS Service";
113 serviceConfig = {
114 Name = "net.connman.vpn";
115 before = [ "connman" ];
116 ExecStart = "${pkgs.connman}/sbin/connman-vpnd -n";
117 User = "root";
118 SystemdService = "connman-vpn.service";
119 };
120 };
121
122 networking = {
123 useDHCP = false;
124 wireless.enable = true;
125 networkmanager.enable = false;
126 };
127 };
128}