nixos/networkmanager: Add connectionConfig. (#118308)
Adds the `networking.networkmanager.connectionConfig` option which allows setting arbitrary settings inside the `[connection]` section. This also reworked the underlying representation significantly to be less string-pasting and more semantic. In a future step it probably makes sense to provide raw access to other sections to users rather than replying on `extraConfig`. However I decided to defer this primarily because ordering of sections can matter. (Although IIUC this is only true for different `[connection]` sections). I think in the future we could expose an object where users can define/edit all sections and map the current configuration onto those. For now however only `[connection]` is exposed and the rest are just used internally.master
parent
73125980f8
commit
af51d70857
|
@ -22,36 +22,51 @@ let
|
||||||
|
|
||||||
enableIwd = cfg.wifi.backend == "iwd";
|
enableIwd = cfg.wifi.backend == "iwd";
|
||||||
|
|
||||||
configFile = pkgs.writeText "NetworkManager.conf" ''
|
mkValue = v:
|
||||||
[main]
|
if v == true then "yes"
|
||||||
plugins=keyfile
|
else if v == false then "no"
|
||||||
dhcp=${cfg.dhcp}
|
else if lib.isInt v then toString v
|
||||||
dns=${cfg.dns}
|
else v;
|
||||||
# If resolvconf is disabled that means that resolv.conf is managed by some other module.
|
|
||||||
rc-manager=${if config.networking.resolvconf.enable then "resolvconf" else "unmanaged"}
|
|
||||||
|
|
||||||
[keyfile]
|
mkSection = name: attrs: ''
|
||||||
${optionalString (cfg.unmanaged != [])
|
[${name}]
|
||||||
''unmanaged-devices=${lib.concatStringsSep ";" cfg.unmanaged}''}
|
${
|
||||||
|
lib.concatStringsSep "\n"
|
||||||
[logging]
|
(lib.mapAttrsToList
|
||||||
level=${cfg.logLevel}
|
(k: v: "${k}=${mkValue v}")
|
||||||
audit=${lib.boolToString config.security.audit.enable}
|
(lib.filterAttrs
|
||||||
|
(k: v: v != null)
|
||||||
[connection]
|
attrs))
|
||||||
ipv6.ip6-privacy=2
|
}
|
||||||
ethernet.cloned-mac-address=${cfg.ethernet.macAddress}
|
|
||||||
wifi.cloned-mac-address=${cfg.wifi.macAddress}
|
|
||||||
${optionalString (cfg.wifi.powersave != null)
|
|
||||||
''wifi.powersave=${if cfg.wifi.powersave then "3" else "2"}''}
|
|
||||||
|
|
||||||
[device]
|
|
||||||
wifi.scan-rand-mac-address=${if cfg.wifi.scanRandMacAddress then "yes" else "no"}
|
|
||||||
wifi.backend=${cfg.wifi.backend}
|
|
||||||
|
|
||||||
${cfg.extraConfig}
|
|
||||||
'';
|
'';
|
||||||
|
|
||||||
|
configFile = pkgs.writeText "NetworkManager.conf" (lib.concatStringsSep "\n" [
|
||||||
|
(mkSection "main" {
|
||||||
|
plugins = "keyfile";
|
||||||
|
dhcp = cfg.dhcp;
|
||||||
|
dns = cfg.dns;
|
||||||
|
# If resolvconf is disabled that means that resolv.conf is managed by some other module.
|
||||||
|
rc-manager =
|
||||||
|
if config.networking.resolvconf.enable then "resolvconf"
|
||||||
|
else "unmanaged";
|
||||||
|
})
|
||||||
|
(mkSection "keyfile" {
|
||||||
|
unmanaged-devices =
|
||||||
|
if cfg.unmanaged == [] then null
|
||||||
|
else lib.concatStringsSep ";" cfg.unmanaged;
|
||||||
|
})
|
||||||
|
(mkSection "logging" {
|
||||||
|
audit = config.security.audit.enable;
|
||||||
|
level = cfg.logLevel;
|
||||||
|
})
|
||||||
|
(mkSection "connection" cfg.connectionConfig)
|
||||||
|
(mkSection "device" {
|
||||||
|
"wifi.scan-rand-mac-address" = cfg.wifi.scanRandMacAddress;
|
||||||
|
"wifi.backend" = cfg.wifi.backend;
|
||||||
|
})
|
||||||
|
cfg.extraConfig
|
||||||
|
]);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
[network-manager]
|
[network-manager]
|
||||||
Identity=unix-group:networkmanager
|
Identity=unix-group:networkmanager
|
||||||
|
@ -154,6 +169,28 @@ in {
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
connectionConfig = mkOption {
|
||||||
|
type = with types; attrsOf (nullOr (oneOf [
|
||||||
|
bool
|
||||||
|
int
|
||||||
|
str
|
||||||
|
]));
|
||||||
|
default = {};
|
||||||
|
description = ''
|
||||||
|
Configuration for the [connection] section of NetworkManager.conf.
|
||||||
|
Refer to
|
||||||
|
<link xlink:href="https://developer.gnome.org/NetworkManager/stable/NetworkManager.conf.html">
|
||||||
|
https://developer.gnome.org/NetworkManager/stable/NetworkManager.conf.html#id-1.2.3.11
|
||||||
|
</link>
|
||||||
|
or
|
||||||
|
<citerefentry>
|
||||||
|
<refentrytitle>NetworkManager.conf</refentrytitle>
|
||||||
|
<manvolnum>5</manvolnum>
|
||||||
|
</citerefentry>
|
||||||
|
for more information.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
extraConfig = mkOption {
|
extraConfig = mkOption {
|
||||||
type = types.lines;
|
type = types.lines;
|
||||||
default = "";
|
default = "";
|
||||||
|
@ -482,6 +519,18 @@ in {
|
||||||
(mkIf enableIwd {
|
(mkIf enableIwd {
|
||||||
wireless.iwd.enable = true;
|
wireless.iwd.enable = true;
|
||||||
})
|
})
|
||||||
|
|
||||||
|
{
|
||||||
|
networkmanager.connectionConfig = {
|
||||||
|
"ipv6.ip6-privacy" = 2;
|
||||||
|
"ethernet.cloned-mac-address" = cfg.ethernet.macAddress;
|
||||||
|
"wifi.cloned-mac-address" = cfg.wifi.macAddress;
|
||||||
|
"wifi.powersave" =
|
||||||
|
if cfg.wifi.powersave == null then null
|
||||||
|
else if cfg.wifi.powersave then 3
|
||||||
|
else 2;
|
||||||
|
};
|
||||||
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
boot.kernelModules = [ "ctr" ];
|
boot.kernelModules = [ "ctr" ];
|
||||||
|
|
Loading…
Reference in New Issue