nixos/networkmanager: change config generation to use the ini generator

This commit is contained in:
Janik H. 2024-03-02 17:38:25 +01:00
parent 52e01114be
commit 8612ed1ee9
No known key found for this signature in database
2 changed files with 45 additions and 41 deletions

View File

@ -581,6 +581,8 @@ The pre-existing [services.ankisyncd](#opt-services.ankisyncd.enable) has been m
- The `hardware.pulseaudio` module now sets permission of pulse user home directory to 755 when running in "systemWide" mode. It fixes [issue 114399](https://github.com/NixOS/nixpkgs/issues/114399). - The `hardware.pulseaudio` module now sets permission of pulse user home directory to 755 when running in "systemWide" mode. It fixes [issue 114399](https://github.com/NixOS/nixpkgs/issues/114399).
- The `services.networkmanager.extraConfig` was renamed to `services.networkmanager.settings` and was changed to use the ini type instead of using a multiline string.
- The module `services.github-runner` has been removed. To configure a single GitHub Actions Runner refer to `services.github-runners.*`. Note that this will trigger a new runner registration. - The module `services.github-runner` has been removed. To configure a single GitHub Actions Runner refer to `services.github-runners.*`. Note that this will trigger a new runner registration.
- The `services.slskd` has been refactored to include more configuation options in - The `services.slskd` has been refactored to include more configuation options in

View File

@ -10,49 +10,31 @@ let
enableIwd = cfg.wifi.backend == "iwd"; enableIwd = cfg.wifi.backend == "iwd";
mkValue = v: configAttrs = lib.recursiveUpdate {
if v == true then "yes" main = {
else if v == false then "no"
else if lib.isInt v then toString v
else v;
mkSection = name: attrs: ''
[${name}]
${
lib.concatStringsSep "\n"
(lib.mapAttrsToList
(k: v: "${k}=${mkValue v}")
(lib.filterAttrs
(k: v: v != null)
attrs))
}
'';
configFile = pkgs.writeText "NetworkManager.conf" (lib.concatStringsSep "\n" [
(mkSection "main" {
plugins = "keyfile"; plugins = "keyfile";
inherit (cfg) dhcp dns; inherit (cfg) dhcp dns;
# If resolvconf is disabled that means that resolv.conf is managed by some other module. # If resolvconf is disabled that means that resolv.conf is managed by some other module.
rc-manager = rc-manager =
if config.networking.resolvconf.enable then "resolvconf" if config.networking.resolvconf.enable then "resolvconf"
else "unmanaged"; else "unmanaged";
}) };
(mkSection "keyfile" { keyfile = {
unmanaged-devices = unmanaged-devices =
if cfg.unmanaged == [ ] then null if cfg.unmanaged == [ ] then null
else lib.concatStringsSep ";" cfg.unmanaged; else lib.concatStringsSep ";" cfg.unmanaged;
}) };
(mkSection "logging" { logging = {
audit = config.security.audit.enable; audit = config.security.audit.enable;
level = cfg.logLevel; level = cfg.logLevel;
}) };
(mkSection "connection" cfg.connectionConfig) connection = cfg.connectionConfig;
(mkSection "device" { device = {
"wifi.scan-rand-mac-address" = cfg.wifi.scanRandMacAddress; "wifi.scan-rand-mac-address" = cfg.wifi.scanRandMacAddress;
"wifi.backend" = cfg.wifi.backend; "wifi.backend" = cfg.wifi.backend;
}) };
cfg.extraConfig } cfg.settings;
]); configFile = ini.generate "NetworkManager.conf" configAttrs;
/* /*
[network-manager] [network-manager]
@ -145,7 +127,7 @@ in
{ {
meta = { meta = {
maintainers = teams.freedesktop.members; maintainers = teams.freedesktop.members ++ [ lib.maintainers.janik ];
}; };
###### interface ###### interface
@ -185,11 +167,11 @@ in
''; '';
}; };
extraConfig = mkOption { settings = mkOption {
type = types.lines; type = ini.type;
default = ""; default = {};
description = '' description = ''
Configuration appended to the generated NetworkManager.conf. Configuration added to the generated NetworkManager.conf, note that you can overwrite settings with this.
Refer to Refer to
[ [
https://developer.gnome.org/NetworkManager/stable/NetworkManager.conf.html https://developer.gnome.org/NetworkManager/stable/NetworkManager.conf.html
@ -471,8 +453,28 @@ in
imports = [ imports = [
(mkRenamedOptionModule (mkRenamedOptionModule
[ "networking" "networkmanager" "packages" ] [ "networking" "networkmanager" "packages" ]
[ "networking" "networkmanager" "plugins" ]) [ "networking" "networkmanager" "plugins" ]
(mkRenamedOptionModule [ "networking" "networkmanager" "useDnsmasq" ] [ "networking" "networkmanager" "dns" ]) )
(mkRenamedOptionModule
[ "networking" "networkmanager" "useDnsmasq" ]
[ "networking" "networkmanager" "dns" ]
)
(mkRemovedOptionModule [ "networking" "networkmanager" "extraConfig" ] ''
This option was removed in favour of `networking.networkmanager.settings`,
which accepts structured nix-code equivalent to the ini
and allows for overriding settings.
Example patch:
```patch
networking.networkmanager = {
- extraConfig = '''
- [main]
- no-auto-default=*
- '''
+ extraConfig.main.no-auto-default = "*";
};
```
''
)
(mkRemovedOptionModule [ "networking" "networkmanager" "enableFccUnlock" ] '' (mkRemovedOptionModule [ "networking" "networkmanager" "enableFccUnlock" ] ''
This option was removed, because using bundled FCC unlock scripts is risky, This option was removed, because using bundled FCC unlock scripts is risky,
might conflict with vendor-provided unlock scripts, and should might conflict with vendor-provided unlock scripts, and should