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 };
56
57 };
58
59 ###### implementation
60
61 config = mkIf cfg.enable {
62
63 assertions = [{
64 assertion = !config.networking.useDHCP;
65 message = "You can not use services.networking.connman with services.networking.useDHCP";
66 }{
67 assertion = config.networking.wireless.enable;
68 message = "You must use services.networking.connman with services.networking.wireless";
69 }{
70 assertion = !config.networking.networkmanager.enable;
71 message = "You can not use services.networking.connman with services.networking.networkmanager";
72 }];
73
74 environment.systemPackages = [ connman ];
75
76 systemd.services."connman" = {
77 description = "Connection service";
78 wantedBy = [ "multi-user.target" ];
79 after = [ "syslog.target" ];
80 serviceConfig = {
81 Type = "dbus";
82 BusName = "net.connman";
83 Restart = "on-failure";
84 ExecStart = "${pkgs.connman}/sbin/connmand --config=${configFile} --nodaemon";
85 StandardOutput = "null";
86 };
87 };
88
89 systemd.services."connman-vpn" = mkIf cfg.enableVPN {
90 description = "ConnMan VPN service";
91 wantedBy = [ "multi-user.target" ];
92 after = [ "syslog.target" ];
93 before = [ "connman" ];
94 serviceConfig = {
95 Type = "dbus";
96 BusName = "net.connman.vpn";
97 ExecStart = "${pkgs.connman}/sbin/connman-vpnd -n";
98 StandardOutput = "null";
99 };
100 };
101
102 systemd.services."net-connman-vpn" = mkIf cfg.enableVPN {
103 description = "D-BUS Service";
104 serviceConfig = {
105 Name = "net.connman.vpn";
106 before = [ "connman" ];
107 ExecStart = "${pkgs.connman}/sbin/connman-vpnd -n";
108 User = "root";
109 SystemdService = "connman-vpn.service";
110 };
111 };
112
113 networking = {
114 useDHCP = false;
115 wireless.enable = true;
116 networkmanager.enable = false;
117 };
118
119 powerManagement.resumeCommands = ''
120 systemctl restart connman
121 '';
122
123 };
124}