diff --git a/modules/system/activation/top-level.nix b/modules/system/activation/top-level.nix index 2fdaa6fd945..0128ffb0c26 100644 --- a/modules/system/activation/top-level.nix +++ b/modules/system/activation/top-level.nix @@ -69,6 +69,7 @@ let false fi ln -s ${kernelPath} $out/kernel + ln -s ${config.system.modulesTree} $out/kernel-modules if [ -n "$grub" ]; then ln -s $grub $out/grub fi diff --git a/modules/system/boot/modprobe.nix b/modules/system/boot/modprobe.nix index 4496106a231..65b3f6fd292 100644 --- a/modules/system/boot/modprobe.nix +++ b/modules/system/boot/modprobe.nix @@ -19,6 +19,14 @@ with pkgs.lib; '' #! ${pkgs.stdenv.shell} export MODULE_DIR=${config.system.modulesTree}/lib/modules + + # Fall back to the kernel modules used at boot time if the + # modules in the current configuration don't match the + # running kernel. + if [ ! -d "$MODULE_DIR/$(${pkgs.coreutils}/bin/uname -r)" ]; then + MODULE_DIR=/var/run/booted-system/kernel-modules/lib/modules + fi + exec ${pkgs.module_init_tools}/sbin/modprobe "$@" ''; };