networkmanager: hoist some lib.mkIfs up a few levels

would you believe one of these attributes was being set without a mkIf cfg.enabled guard :)
This commit is contained in:
2024-05-28 05:27:23 +00:00
parent cbe6072c03
commit 4ba0343315

View File

@@ -8,15 +8,19 @@
let let
cfg = config.sane.programs.networkmanager; cfg = config.sane.programs.networkmanager;
in in
{
config = lib.mkMerge [
{ {
sane.programs.networkmanager = { sane.programs.networkmanager = {
suggestedPrograms = [ "wpa_supplicant" ]; suggestedPrograms = [ "wpa_supplicant" ];
enableFor.system = lib.mkIf (builtins.any (en: en) (builtins.attrValues cfg.enableFor.user)) true; enableFor.system = lib.mkIf (builtins.any (en: en) (builtins.attrValues cfg.enableFor.user)) true;
}; };
}
(lib.mkIf cfg.enabled {
# add to systemd.packages so we get the service file it ships, then override what we need to customize (taken from nixpkgs) # add to systemd.packages so we get the service file it ships, then override what we need to customize (taken from nixpkgs)
systemd.packages = lib.mkIf cfg.enabled [ cfg.package ]; systemd.packages = [ cfg.package ];
systemd.services.NetworkManager = lib.mkIf cfg.enabled { systemd.services.NetworkManager = {
wantedBy = [ "network.target" ]; wantedBy = [ "network.target" ];
aliases = [ "dbus-org.freedesktop.NetworkManager.service" ]; aliases = [ "dbus-org.freedesktop.NetworkManager.service" ];
@@ -26,11 +30,9 @@ in
}; };
}; };
systemd.services.NetworkManager-wait-online = lib.mkIf cfg.enabled { systemd.services.NetworkManager-wait-online.wantedBy = [ "network-online.target" ];
wantedBy = [ "network-online.target" ];
};
systemd.services.NetworkManager-dispatcher = lib.mkIf cfg.enabled { systemd.services.NetworkManager-dispatcher = {
wantedBy = [ "NetworkManager.service" ]; wantedBy = [ "NetworkManager.service" ];
# to debug, add NM_DISPATCHER_DEBUG_LOG=1 # to debug, add NM_DISPATCHER_DEBUG_LOG=1
serviceConfig.ExecStart = [ serviceConfig.ExecStart = [
@@ -41,7 +43,7 @@ in
serviceConfig.RestartSec = "1s"; serviceConfig.RestartSec = "1s";
}; };
environment.etc = lib.mkIf cfg.enabled { environment.etc = {
"NetworkManager/system-connections".source = "/var/lib/NetworkManager/system-connections"; "NetworkManager/system-connections".source = "/var/lib/NetworkManager/system-connections";
"NetworkManager/NetworkManager.conf".text = '' "NetworkManager/NetworkManager.conf".text = ''
[device] [device]
@@ -83,13 +85,11 @@ in
# debug=... (see also: NM_DEBUG env var) # debug=... (see also: NM_DEBUG env var)
''; '';
}; };
hardware.wirelessRegulatoryDatabase = lib.mkIf cfg.enabled true; hardware.wirelessRegulatoryDatabase = true;
networking.useDHCP = lib.mkIf cfg.enabled false; networking.useDHCP = false;
users.groups = lib.mkIf cfg.enabled { users.groups.networkmanager.gid = config.ids.gids.networkmanager;
networkmanager.gid = config.ids.gids.networkmanager; services.udev.packages = [ cfg.package ];
}; security.polkit.enable = true;
services.udev.packages = lib.mkIf cfg.enabled [ cfg.package ];
security.polkit.enable = lib.mkIf cfg.enabled true;
security.polkit.extraConfig = '' security.polkit.extraConfig = ''
polkit.addRule(function(action, subject) { polkit.addRule(function(action, subject) {
if ( if (
@@ -104,4 +104,6 @@ in
boot.kernelModules = [ "ctr" ]; #< TODO: needed (what even is this)? boot.kernelModules = [ "ctr" ]; #< TODO: needed (what even is this)?
# TODO: polkit? # TODO: polkit?
# TODO: NetworkManager-ensure-profiles? # TODO: NetworkManager-ensure-profiles?
})
];
} }