nixpkgs/nixos/modules/services/networking/connman.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

156 lines
4.4 KiB
Nix
Raw Normal View History

{ config, lib, pkgs, ... }:
let
cfg = config.services.connman;
configFile = pkgs.writeText "connman.conf" ''
[General]
2023-10-05 01:13:08 +00:00
NetworkInterfaceBlacklist=${lib.concatStringsSep "," cfg.networkInterfaceBlacklist}
${cfg.extraConfig}
'';
2019-12-21 21:48:15 +00:00
enableIwd = cfg.wifi.backend == "iwd";
in {
2023-10-05 01:13:08 +00:00
meta.maintainers = with lib.maintainers; [ AndersonTorres ];
imports = [
2023-10-05 01:13:08 +00:00
(lib.mkRenamedOptionModule [ "networking" "connman" ] [ "services" "connman" ])
];
###### interface
options = {
services.connman = {
2023-10-05 01:13:08 +00:00
enable = lib.mkOption {
type = lib.types.bool;
default = false;
description = ''
Whether to use ConnMan for managing your network connections.
'';
};
2023-10-05 01:13:08 +00:00
package = lib.mkOption {
type = lib.types.package;
description = "The connman package / build flavor";
2023-10-05 01:13:08 +00:00
default = pkgs.connman;
defaultText = lib.literalExpression "pkgs.connman";
example = lib.literalExpression "pkgs.connmanFull";
};
enableVPN = lib.mkOption {
type = lib.types.bool;
default = true;
description = ''
Whether to enable ConnMan VPN service.
'';
};
2023-10-05 01:13:08 +00:00
extraConfig = lib.mkOption {
type = lib.types.lines;
default = "";
description = ''
Configuration lines appended to the generated connman configuration file.
'';
};
2023-10-05 01:13:08 +00:00
networkInterfaceBlacklist = lib.mkOption {
type = with lib.types; listOf str;
default = [ "vmnet" "vboxnet" "virbr" "ifb" "ve" ];
description = ''
Default blacklisted interfaces, this includes NixOS containers interfaces (ve).
'';
};
2019-12-21 21:48:15 +00:00
wifi = {
2023-10-05 01:13:08 +00:00
backend = lib.mkOption {
type = lib.types.enum [ "wpa_supplicant" "iwd" ];
2019-12-21 21:48:15 +00:00
default = "wpa_supplicant";
description = ''
2019-12-21 21:48:15 +00:00
Specify the Wi-Fi backend used.
Currently supported are {option}`wpa_supplicant` or {option}`iwd`.
'';
};
};
2023-10-05 01:13:08 +00:00
extraFlags = lib.mkOption {
type = with lib.types; listOf str;
default = [ ];
example = [ "--nodnsproxy" ];
description = ''
Extra flags to pass to connmand
'';
};
};
};
###### implementation
2023-10-05 01:13:08 +00:00
config = lib.mkIf cfg.enable {
assertions = [{
2016-02-01 16:51:04 +00:00
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 ];
2019-08-13 21:52:01 +00:00
systemd.services.connman = {
description = "Connection service";
wantedBy = [ "multi-user.target" ];
2023-10-05 01:13:08 +00:00
after = [ "syslog.target" ] ++ lib.optional enableIwd "iwd.service";
requires = lib.optional enableIwd "iwd.service";
serviceConfig = {
Type = "dbus";
BusName = "net.connman";
Restart = "on-failure";
2019-12-21 21:48:15 +00:00
ExecStart = toString ([
"${cfg.package}/sbin/connmand"
2019-12-21 21:48:15 +00:00
"--config=${configFile}"
"--nodaemon"
2023-10-05 01:13:08 +00:00
] ++ lib.optional enableIwd "--wifi=iwd_agent"
2019-12-21 21:48:15 +00:00
++ cfg.extraFlags);
StandardOutput = "null";
};
};
2023-10-05 01:13:08 +00:00
systemd.services.connman-vpn = lib.mkIf cfg.enableVPN {
description = "ConnMan VPN service";
wantedBy = [ "multi-user.target" ];
after = [ "syslog.target" ];
before = [ "connman.service" ];
serviceConfig = {
Type = "dbus";
BusName = "net.connman.vpn";
ExecStart = "${cfg.package}/sbin/connman-vpnd -n";
StandardOutput = "null";
};
};
2023-10-05 01:13:08 +00:00
systemd.services.net-connman-vpn = lib.mkIf cfg.enableVPN {
description = "D-BUS Service";
serviceConfig = {
Name = "net.connman.vpn";
before = [ "connman.service" ];
ExecStart = "${cfg.package}/sbin/connman-vpnd -n";
User = "root";
SystemdService = "connman-vpn.service";
};
};
networking = {
useDHCP = false;
2019-12-21 21:48:15 +00:00
wireless = {
2023-10-05 01:13:08 +00:00
enable = lib.mkIf (!enableIwd) true;
dbusControlled = true;
2023-10-05 01:13:08 +00:00
iwd = lib.mkIf enableIwd {
2019-12-21 21:48:15 +00:00
enable = true;
};
};
networkmanager.enable = false;
};
};
}