From ff3a0a4565cf666bf316337b00563219decf5b73 Mon Sep 17 00:00:00 2001 From: rnhmjoj Date: Fri, 1 May 2026 16:30:48 +0200 Subject: [PATCH] nixos/networking-interfaces-scripted: add fix for systemd initrd When systemd is used in stage 1 (boot.initrd.systemd.enable), the device units are activated before the stage 2 units are loaded, so the network-addresses-*.service are never started. To avoid this, in addition to the wantedBy dependency, we use udev rules with SYSTEMD_WANTS to trigger the services directly. --- .../modules/tasks/network-interfaces-scripted.nix | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/nixos/modules/tasks/network-interfaces-scripted.nix b/nixos/modules/tasks/network-interfaces-scripted.nix index 4bf274d4157f..7961cb21ff5a 100644 --- a/nixos/modules/tasks/network-interfaces-scripted.nix +++ b/nixos/modules/tasks/network-interfaces-scripted.nix @@ -888,9 +888,18 @@ let description = "NixOS scripted networking setup"; }; - services.udev.extraRules = '' - KERNEL=="tun", TAG+="systemd" - ''; + services.udev.extraRules = lib.concatStringsSep "\n" ( + [ ''KERNEL=="tun", TAG+="systemd"'' ] + # This creates a udev rule to start each service with a WantedBy + # dependency on a device unit. It's needed because if the service + # unit is loaded in stage 2 but its device was already up by + # stage 1, systemd will not automatically start it. + ++ lib.forEach (lib.attrNames cfg.interfaces) ( + iface: + ''ACTION=="add", SUBSYSTEM=="net", KERNEL=="${iface}", '' + + ''ENV{SYSTEMD_WANTS}="network-addresses-${iface}.service"'' + ) + ); };