diff --git a/nixos/modules/system/boot/systemd/initrd.nix b/nixos/modules/system/boot/systemd/initrd.nix index 370fceb94844..3dd954a526bb 100644 --- a/nixos/modules/system/boot/systemd/initrd.nix +++ b/nixos/modules/system/boot/systemd/initrd.nix @@ -640,6 +640,10 @@ in ) cfg.automounts ); + services."modprobe@" = lib.mkIf (config.system.build.kernel.config.isYes "MODULES") { + serviceConfig.ExecSearchPath = lib.makeBinPath [ cfg.package.kmod ]; + }; + services.initrd-find-nixos-closure = lib.mkIf (!config.system.nixos-init.enable) { description = "Find NixOS closure"; diff --git a/nixos/tests/systemd-initrd-modprobe.nix b/nixos/tests/systemd-initrd-modprobe.nix index 88237f5ab801..894de6e29ffd 100644 --- a/nixos/tests/systemd-initrd-modprobe.nix +++ b/nixos/tests/systemd-initrd-modprobe.nix @@ -18,6 +18,10 @@ rtt = machine.succeed("cat /sys/module/tcp_hybla/parameters/rtt0") assert int(rtt) == 42, "Parameter should be respected for initrd kernel modules" + with subtest("modprobe@ services work"): + modprobe_service_status = machine.succeed("systemctl show --property ExecMainStatus modprobe@9pnet_virtio.service") + t.assertEqual("ExecMainStatus=0\n", modprobe_service_status) + # Make sure it sticks in stage 2 machine.switch_root() machine.wait_for_unit("multi-user.target")