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 extraConfig = mkOption { 31 type = types.lines; 32 default = '' 33 ''; 34 description = '' 35 Configuration lines appended to the generated connman configuration file. 36 ''; 37 }; 38 39 networkInterfaceBlacklist = mkOption { 40 type = with types; listOf string; 41 default = [ "vmnet" "vboxnet" "virbr" "ifb" "ve" ]; 42 description = '' 43 Default blacklisted interfaces, this includes NixOS containers interfaces (ve). 44 ''; 45 }; 46 47 }; 48 49 }; 50 51 ###### implementation 52 53 config = mkIf cfg.enable { 54 55 assertions = [{ 56 assertion = !config.networking.useDHCP; 57 message = "You can not use services.networking.connman with services.networking.useDHCP"; 58 }{ 59 assertion = config.networking.wireless.enable; 60 message = "You must use services.networking.connman with services.networking.wireless"; 61 }{ 62 assertion = !config.networking.networkmanager.enable; 63 message = "You can not use services.networking.connman with services.networking.networkmanager"; 64 }]; 65 66 environment.systemPackages = [ connman ]; 67 68 systemd.services."connman" = { 69 description = "Connection service"; 70 wantedBy = [ "multi-user.target" ]; 71 after = [ "syslog.target" ]; 72 serviceConfig = { 73 Type = "dbus"; 74 BusName = "net.connman"; 75 Restart = "on-failure"; 76 ExecStart = "${pkgs.connman}/sbin/connmand --config=${configFile} --nodaemon"; 77 StandardOutput = "null"; 78 }; 79 }; 80 81 systemd.services."connman-vpn" = { 82 description = "ConnMan VPN service"; 83 wantedBy = [ "multi-user.target" ]; 84 after = [ "syslog.target" ]; 85 before = [ "connman" ]; 86 serviceConfig = { 87 Type = "dbus"; 88 BusName = "net.connman.vpn"; 89 ExecStart = "${pkgs.connman}/sbin/connman-vpnd -n"; 90 StandardOutput = "null"; 91 }; 92 }; 93 94 systemd.services."net-connman-vpn" = { 95 description = "D-BUS Service"; 96 serviceConfig = { 97 Name = "net.connman.vpn"; 98 before = [ "connman" ]; 99 ExecStart = "${pkgs.connman}/sbin/connman-vpnd -n"; 100 User = "root"; 101 SystemdService = "connman-vpn.service"; 102 }; 103 }; 104 105 networking = { 106 useDHCP = false; 107 wireless.enable = true; 108 networkmanager.enable = false; 109 }; 110 111 powerManagement.resumeCommands = '' 112 systemctl restart connman 113 ''; 114 115 }; 116}