From d7535dd0430584ec9ce113f556f3bc97da48a4b5 Mon Sep 17 00:00:00 2001 From: rnhmjoj Date: Wed, 20 Aug 2025 18:56:24 +0200 Subject: [PATCH] nixos/networkmanager: fix for rootless wpa_supplicant --- .../services/networking/networkmanager.nix | 19 ++++++++++++------- .../services/networking/wpa_supplicant.nix | 19 +++++++++++++------ 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/nixos/modules/services/networking/networkmanager.nix b/nixos/modules/services/networking/networkmanager.nix index 9295157b793b..f76e649d75e9 100644 --- a/nixos/modules/services/networking/networkmanager.nix +++ b/nixos/modules/services/networking/networkmanager.nix @@ -11,7 +11,8 @@ let cfg = config.networking.networkmanager; ini = pkgs.formats.ini { }; - delegateWireless = config.networking.wireless.enable == true && cfg.unmanaged != [ ]; + # Whether wpa_supplicant is managed independently + delegateWireless = config.networking.wireless.networks != { } && cfg.unmanaged != [ ]; enableIwd = cfg.wifi.backend == "iwd"; @@ -136,10 +137,7 @@ let cfg.package ] ++ cfg.plugins - ++ pluginRuntimeDeps - ++ lib.optionals (!delegateWireless && !enableIwd) [ - pkgs.wpa_supplicant - ]; + ++ pluginRuntimeDeps; in { @@ -541,9 +539,9 @@ in assertions = [ { - assertion = config.networking.wireless.enable == true -> cfg.unmanaged != [ ]; + assertion = config.networking.wireless.networks != { } -> cfg.unmanaged != [ ]; message = '' - You can not use networking.networkmanager with networking.wireless. + You can not use networking.networkmanager with networking.wireless.networks. Except if you mark some interfaces as unmanaged by NetworkManager. ''; } @@ -676,6 +674,13 @@ in useDHCP = false; }) + (mkIf (!delegateWireless && !enableIwd) { + # Enable wpa_supplicant but fully control it over DBus + wireless.enable = true; + wireless.autoDetectInterfaces = false; + wireless.dbusControlled = true; + }) + (mkIf enableIwd { wireless.iwd.enable = true; }) diff --git a/nixos/modules/services/networking/wpa_supplicant.nix b/nixos/modules/services/networking/wpa_supplicant.nix index 8fa11f9ef87e..124bd9c9eda0 100644 --- a/nixos/modules/services/networking/wpa_supplicant.nix +++ b/nixos/modules/services/networking/wpa_supplicant.nix @@ -199,7 +199,12 @@ let script = '' iface_args="-s ${optionalString cfg.dbusControlled "-u"} -D${cfg.driver} ${configStr}" ${ - if iface == null then + if iface != null then + '' + # add known interface to the daemon arguments + args="-i${iface} $iface_args" + '' + else if cfg.autoDetectInterfaces then '' # detect interfaces automatically @@ -222,10 +227,7 @@ let done '' else - '' - # add known interface to the daemon arguments - args="-i${iface} $iface_args" - '' + "args=$iface_args" } # finally start daemon @@ -251,7 +253,8 @@ in "wlan1" ]; description = '' - The interfaces {command}`wpa_supplicant` will use. If empty, it will + The interfaces {command}`wpa_supplicant` will use. If empty and + [](#opt-networking.wireless.autoDetectInterfaces) is true it will automatically use all wireless interfaces. ::: {.note} @@ -260,6 +263,10 @@ in ''; }; + autoDetectInterfaces = mkEnableOption "automatic detection of wireless interfaces" // { + default = true; + }; + driver = mkOption { type = types.str; default = "nl80211,wext";