about summary refs log tree commit diff
path: root/pkgs/build-support
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2015-05-08 13:01:10 +0200
committerEelco Dolstra <eelco.dolstra@logicblox.com>2015-05-13 17:36:58 +0200
commitfef86de6188731c621cbbaa89e5cbe557f6f9546 (patch)
tree108d5a38f7b6e8d06bd444e25f8dafcc363f5480 /pkgs/build-support
parentb97362989f59ed08683f66023d1ad6a3e760b781 (diff)
downloadnixlib-fef86de6188731c621cbbaa89e5cbe557f6f9546.tar
nixlib-fef86de6188731c621cbbaa89e5cbe557f6f9546.tar.gz
nixlib-fef86de6188731c621cbbaa89e5cbe557f6f9546.tar.bz2
nixlib-fef86de6188731c621cbbaa89e5cbe557f6f9546.tar.lz
nixlib-fef86de6188731c621cbbaa89e5cbe557f6f9546.tar.xz
nixlib-fef86de6188731c621cbbaa89e5cbe557f6f9546.tar.zst
nixlib-fef86de6188731c621cbbaa89e5cbe557f6f9546.zip
Make module loading work in VMs
Also, execute stage 2 as PID 1.
Diffstat (limited to 'pkgs/build-support')
-rw-r--r--pkgs/build-support/vm/default.nix27
1 files changed, 17 insertions, 10 deletions
diff --git a/pkgs/build-support/vm/default.nix b/pkgs/build-support/vm/default.nix
index c9a9aac79734..5aa1a9c092d2 100644
--- a/pkgs/build-support/vm/default.nix
+++ b/pkgs/build-support/vm/default.nix
@@ -140,15 +140,7 @@ rec {
     echo "127.0.0.1 localhost" > /fs/etc/hosts
 
     echo "starting stage 2 ($command)"
-    test -n "$command"
-
-    set +e
-    chroot /fs $command $out
-    echo $? > /fs/tmp/xchg/in-vm-exit
-
-    mount -o remount,ro dummy /fs
-
-    poweroff -f
+    exec switch_root /fs $command $out
   '';
 
 
@@ -181,12 +173,27 @@ rec {
       ${coreutils}/bin/ln -s ${bash}/bin/sh /bin/sh
     fi
 
+    # Set up automatic kernel module loading.
+    export MODULE_DIR=${linux}/lib/modules/
+    ${coreutils}/bin/cat <<EOF > /run/modprobe
+    #! /bin/sh
+    export MODULE_DIR=$MODULE_DIR
+    exec ${kmod}/bin/modprobe "\$@"
+    EOF
+    ${coreutils}/bin/chmod 755 /run/modprobe
+    echo /run/modprobe > /proc/sys/kernel/modprobe
+
     # For debugging: if this is the second time this image is run,
     # then don't start the build again, but instead drop the user into
     # an interactive shell.
     if test -n "$origBuilder" -a ! -e /.debug; then
       ${coreutils}/bin/touch /.debug
-      exec $origBuilder $origArgs
+      $origBuilder $origArgs
+      echo $? > /tmp/xchg/in-vm-exit
+
+      ${busybox}/bin/mount -o remount,ro dummy /
+
+      ${busybox}/bin/poweroff -f
     else
       export PATH=/bin:/usr/bin:${coreutils}/bin
       echo "Starting interactive shell..."