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