summary refs log tree commit diff
path: root/nixos/modules/system/boot/modprobe.nix
diff options
context:
space:
mode:
authorShea Levy <shea@shealevy.com>2016-08-15 19:05:52 -0400
committerShea Levy <shea@shealevy.com>2016-08-15 19:05:52 -0400
commit9adad8612b082bcbae30c81678a04b79a44079a4 (patch)
tree6814d056ee2960d122842dc9c830bb411c40d5ff /nixos/modules/system/boot/modprobe.nix
parent57b2d1e9b0dcdd1d25bd2d450174764b9417ffc1 (diff)
downloadnixlib-9adad8612b082bcbae30c81678a04b79a44079a4.tar
nixlib-9adad8612b082bcbae30c81678a04b79a44079a4.tar.gz
nixlib-9adad8612b082bcbae30c81678a04b79a44079a4.tar.bz2
nixlib-9adad8612b082bcbae30c81678a04b79a44079a4.tar.lz
nixlib-9adad8612b082bcbae30c81678a04b79a44079a4.tar.xz
nixlib-9adad8612b082bcbae30c81678a04b79a44079a4.tar.zst
nixlib-9adad8612b082bcbae30c81678a04b79a44079a4.zip
Revert "Merge branch 'modprobe-fix' of git://github.com/abbradar/nixpkgs"
Was meant to go into staging, sorry

This reverts commit 57b2d1e9b0dcdd1d25bd2d450174764b9417ffc1, reversing
changes made to 760b2b9048ea775c319cb348d74447a20dea513e.
Diffstat (limited to 'nixos/modules/system/boot/modprobe.nix')
-rw-r--r--nixos/modules/system/boot/modprobe.nix41
1 files changed, 39 insertions, 2 deletions
diff --git a/nixos/modules/system/boot/modprobe.nix b/nixos/modules/system/boot/modprobe.nix
index b915a98d5375..9bb10eac9880 100644
--- a/nixos/modules/system/boot/modprobe.nix
+++ b/nixos/modules/system/boot/modprobe.nix
@@ -8,6 +8,41 @@ with lib;
 
   options = {
 
+    system.sbin.modprobe = mkOption {
+      internal = true;
+      default = pkgs.stdenv.mkDerivation {
+        name = "modprobe";
+        buildCommand = ''
+          mkdir -p $out/bin
+          for i in ${pkgs.kmod}/sbin/*; do
+            name=$(basename $i)
+            echo "$text" > $out/bin/$name
+            echo 'exec '$i' "$@"' >> $out/bin/$name
+            chmod +x $out/bin/$name
+          done
+          ln -s bin $out/sbin
+        '';
+        text =
+          ''
+            #! ${pkgs.stdenv.shell}
+            export MODULE_DIR=/run/current-system/kernel-modules/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=/run/booted-system/kernel-modules/lib/modules/
+            fi
+
+          '';
+        meta.priority = 4;
+      };
+      description = ''
+        Wrapper around modprobe that sets the path to the modules
+        tree.
+      '';
+    };
+
     boot.blacklistedKernelModules = mkOption {
       type = types.listOf types.str;
       default = [];
@@ -52,7 +87,7 @@ with lib;
       '';
     environment.etc."modprobe.d/debian.conf".source = pkgs.kmod-debian-aliases;
 
-    environment.systemPackages = [ pkgs.kmod ];
+    environment.systemPackages = [ config.system.sbin.modprobe pkgs.kmod ];
 
     system.activationScripts.modprobe =
       ''
@@ -60,9 +95,11 @@ with lib;
         # in the right location in the Nix store for kernel modules).
         # We need this when the kernel (or some module) auto-loads a
         # module.
-        echo ${pkgs.kmod}/bin/modprobe > /proc/sys/kernel/modprobe
+        echo ${config.system.sbin.modprobe}/sbin/modprobe > /proc/sys/kernel/modprobe
       '';
 
+    environment.sessionVariables.MODULE_DIR = "/run/current-system/kernel-modules/lib/modules";
+
   };
 
 }