From 89eb93dc3ffda68535d6ee51a7825f1de31ae658 Mon Sep 17 00:00:00 2001 From: rnhmjoj Date: Thu, 22 Aug 2024 21:43:21 +0200 Subject: [PATCH] nixos/wireless: link config to /etc by default This links the generated configuration to /etc/wpa_supplicant.conf unless `allowAuxiliaryImperativeNetworks`. In the latter case the file in /etc should be writable and the generated one remains only in the Nix store. --- .../services/networking/wpa_supplicant.nix | 22 +++++-------------- nixos/tests/wpa_supplicant.nix | 6 ++--- 2 files changed, 7 insertions(+), 21 deletions(-) diff --git a/nixos/modules/services/networking/wpa_supplicant.nix b/nixos/modules/services/networking/wpa_supplicant.nix index 4fec023a2368..e13d574c0d73 100644 --- a/nixos/modules/services/networking/wpa_supplicant.nix +++ b/nixos/modules/services/networking/wpa_supplicant.nix @@ -50,15 +50,6 @@ let ++ optional cfg.scanOnLowSignal ''bgscan="simple:30:-70:3600"'' ++ optional (cfg.extraConfig != "") cfg.extraConfig); - configIsGenerated = with cfg; - networks != {} || extraConfig != "" || userControlled.enable; - - # the original configuration file - configFile = - if configIsGenerated - then pkgs.writeText "wpa_supplicant.conf" generatedConfig - else "/etc/wpa_supplicant.conf"; - # Creates a network block for wpa_supplicant.conf mkNetwork = opts: let @@ -90,8 +81,8 @@ let let deviceUnit = optional (iface != null) "sys-subsystem-net-devices-${utils.escapeSystemdPath iface}.device"; configStr = if cfg.allowAuxiliaryImperativeNetworks - then "-c /etc/wpa_supplicant.conf -I ${configFile}" - else "-c ${configFile}"; + then "-c /etc/wpa_supplicant.conf -I ${pkgs.writeText "wpa_supplicant.conf" generatedConfig}" + else "-c /etc/wpa_supplicant.conf"; in { description = "WPA Supplicant instance" + optionalString (iface != null) " for interface ${iface}"; @@ -112,12 +103,6 @@ let script = '' - ${optionalString (configIsGenerated && !cfg.allowAuxiliaryImperativeNetworks) '' - if [ -f /etc/wpa_supplicant.conf ]; then - echo >&2 "<3>/etc/wpa_supplicant.conf present but ignored. Generated ${configFile} is used instead." - fi - ''} - # ensure wpa_supplicant.conf exists, or the daemon will fail to start ${optionalString cfg.allowAuxiliaryImperativeNetworks '' touch /etc/wpa_supplicant.conf @@ -531,6 +516,9 @@ in { hardware.wirelessRegulatoryDatabase = true; + environment.etc."wpa_supplicant.conf" = + lib.mkIf (!cfg.allowAuxiliaryImperativeNetworks) { text = generatedConfig; }; + environment.systemPackages = [ pkgs.wpa_supplicant ]; services.dbus.packages = optional cfg.dbusControlled pkgs.wpa_supplicant; diff --git a/nixos/tests/wpa_supplicant.nix b/nixos/tests/wpa_supplicant.nix index 808e39b03644..71b9ba358fa1 100644 --- a/nixos/tests/wpa_supplicant.nix +++ b/nixos/tests/wpa_supplicant.nix @@ -123,16 +123,14 @@ in }; testScript = '' + config_file = "/etc/static/wpa_supplicant.conf" + with subtest("Daemon is running and accepting connections"): machine.wait_for_unit("wpa_supplicant.service") status = machine.wait_until_succeeds("wpa_cli status") assert "Failed to connect" not in status, \ "Failed to connect to the daemon" - # get the configuration file - cmdline = machine.succeed("cat /proc/$(pgrep wpa)/cmdline").split('\x00') - config_file = cmdline[cmdline.index("-c") + 1] - with subtest("WPA2 fallbacks have been generated"): assert int(machine.succeed(f"grep -c sae-only {config_file}")) == 1 assert int(machine.succeed(f"grep -c mixed-wpa {config_file}")) == 2