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