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.
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user