From 293d7c6cb0b057da6feeacab444fd9b175817512 Mon Sep 17 00:00:00 2001 From: Simonas Kazlauskas Date: Sat, 21 Dec 2024 00:38:49 +0200 Subject: [PATCH] nixos/wpa_supplicant: finetune service dependencies The current requires/wantedBy dependencies present a number of problems, especially for WiFi modules that might not be available at boot time (which is when the boot will be delayed by the service timeout of 1m30s.) Removal of `wantedBy` in particular avoids such blocking from taking place. Furthermore, once the service fails to launch at boot for this reason, the device appearing at a later date (most relevant to USB-pluggable WiFi antennae,) the WPA supplicant wouldn't be launched, thus leaving the user to figure out the service startups for themselves, which in the worst case may be over network. The `upheldBy` dependency type will ensure that the supplicant is running for as long as the specified device exists, and the `bindsTo` dependency type makes systemd stop the service if the WiFi device goes away achieving the plug-and-play ideal. `upheldBy` here also replaces the `wantedBy` as a mechanism for getting the service enabled and started at all. --- nixos/doc/manual/release-notes/rl-2505.section.md | 5 +++++ nixos/modules/services/networking/wpa_supplicant.nix | 7 ++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/nixos/doc/manual/release-notes/rl-2505.section.md b/nixos/doc/manual/release-notes/rl-2505.section.md index e0f633ff7ffe6..bda82c6a2eba9 100644 --- a/nixos/doc/manual/release-notes/rl-2505.section.md +++ b/nixos/doc/manual/release-notes/rl-2505.section.md @@ -200,10 +200,15 @@ - `services.avahi.ipv6` now defaults to true. +- Per-interface `wpa_supplicant` systemd services generated by the `networking.wireless` + configuration no longer blocks the `multi-user.target` and will start/stop the unit on demand as + the specified wireless interface appears or disappears. + - `bind.cacheNetworks` now only controls access for recursive queries, where it previously controlled access for all queries. - `programs.fzf.keybindings` now supports the fish shell. + ## Nixpkgs Library {#sec-release-25.05-lib} diff --git a/nixos/modules/services/networking/wpa_supplicant.nix b/nixos/modules/services/networking/wpa_supplicant.nix index 536aebe4931c4..3cf47dbd6b7fc 100644 --- a/nixos/modules/services/networking/wpa_supplicant.nix +++ b/nixos/modules/services/networking/wpa_supplicant.nix @@ -118,11 +118,12 @@ let { description = "WPA Supplicant instance" + optionalString (iface != null) " for interface ${iface}"; - after = deviceUnit; before = [ "network.target" ]; wants = [ "network.target" ]; - requires = deviceUnit; - wantedBy = [ "multi-user.target" ]; + after = deviceUnit; + bindsTo = deviceUnit; + upheldBy = deviceUnit; + wantedBy = optional (iface == null) "multi-user.target"; stopIfChanged = false; path = [ pkgs.wpa_supplicant ];