diff --git a/modules/system/boot/stage-1-init.sh b/modules/system/boot/stage-1-init.sh index 17c9d2b3ee0..7a5ebedd7a8 100644 --- a/modules/system/boot/stage-1-init.sh +++ b/modules/system/boot/stage-1-init.sh @@ -127,6 +127,9 @@ fi if test -n "$debug1devices"; then fail; fi +@postDeviceCommands@ + + # Return true if the machine is on AC power, or if we can't determine # whether it's on AC power. onACPower() { @@ -223,6 +226,9 @@ for ((n = 0; n < ${#mountPoints[*]}; n++)); do case $device in /dev/*) ;; + //*) + # Don't touch SMB/CIFS paths. + ;; /*) device=/mnt-root$device ;; diff --git a/modules/system/boot/stage-1.nix b/modules/system/boot/stage-1.nix index da8a50f4903..3ff69ac12da 100644 --- a/modules/system/boot/stage-1.nix +++ b/modules/system/boot/stage-1.nix @@ -62,12 +62,22 @@ let ''; }; + boot.initrd.postDeviceCommands = mkOption { + default = ""; + merge = pkgs.lib.mergeStringOption; + description = '' + Shell commands to be executed immediately after stage 1 of the + boot has loaded kernel modules and created device nodes in + /dev. + ''; + }; + boot.initrd.postMountCommands = mkOption { default = ""; merge = pkgs.lib.mergeStringOption; description = '' Shell commands to be executed immediately after the stage 1 - filesystems has been mounted. + filesystems have been mounted. ''; }; @@ -232,7 +242,8 @@ let inherit (config.boot) isLiveCD resumeDevice; - inherit (config.boot.initrd) checkJournalingFS postMountCommands; + inherit (config.boot.initrd) checkJournalingFS + postDeviceCommands postMountCommands; # !!! copy&pasted from upstart-jobs/filesystems.nix. mountPoints = diff --git a/modules/virtualisation/qemu-vm.nix b/modules/virtualisation/qemu-vm.nix index eae0541f338..af1911a1ae6 100644 --- a/modules/virtualisation/qemu-vm.nix +++ b/modules/virtualisation/qemu-vm.nix @@ -16,25 +16,30 @@ boot.initrd.extraKernelModules = ["cifs" "virtio_net" "virtio_pci" "virtio_blk" "virtio_balloon" "nls_utf8"]; + boot.initrd.postDeviceCommands = + '' + ipconfig 10.0.2.15:::::eth0:none + ''; + + # Mount the host filesystem via CIFS, and bind-mount the Nix store + # of the host into our own filesystem. fileSystems = [ { mountPoint = "/"; device = "/dev/vda"; } + { mountPoint = "/hostfs"; + device = "//10.0.2.4/qemu"; + fsType = "cifs"; + options = "guest,username=nobody"; + neededForBoot = true; + } + { mountPoint = "/nix/store"; + device = "/hostfs/nix/store"; + options = "bind"; + neededForBoot = true; + } ]; - # Mount the host filesystem and bind-mount its Nix store into our - # own root FS. - boot.initrd.postMountCommands = - '' - ipconfig 10.0.2.15:::::eth0:none - - mkdir /hostfs - ${pkgs.vmTools.mountCifs}/bin/mount.cifs //10.0.2.4/qemu /hostfs -o guest,username=nobody - - mkdir -p $targetRoot/nix/store - mount --bind /hostfs/nix/store $targetRoot/nix/store - ''; - # Starting DHCP brings down eth0, which kills the connection to the # host filesystem and thus deadlocks the system. networking.useDHCP = false;