From 392275f1856f14b02f113a1116671ac0b14069e8 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 24 Aug 2010 12:59:16 +0000 Subject: [PATCH] * Move support for writable Nix stores to qemu-vm.nix. svn path=/nixos/trunk/; revision=23393 --- modules/virtualisation/qemu-vm.nix | 27 ++++++++++++++++++++++++++- tests/installer.nix | 13 +------------ 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/modules/virtualisation/qemu-vm.nix b/modules/virtualisation/qemu-vm.nix index 3d3b241ed737..739dc8a2b529 100644 --- a/modules/virtualisation/qemu-vm.nix +++ b/modules/virtualisation/qemu-vm.nix @@ -86,6 +86,17 @@ let ''; }; + virtualisation.writableStore = + mkOption { + default = false; + description = + '' + If enabled, the Nix store in the VM is made writable by + layering an AUFS/tmpfs filesystem on top of the host's Nix + store. + ''; + }; + networking.primaryIPAddress = mkOption { default = ""; @@ -163,7 +174,11 @@ in # CIFS. Also use paravirtualised network and block devices for # performance. boot.initrd.availableKernelModules = - [ "cifs" "virtio_net" "virtio_pci" "virtio_blk" "virtio_balloon" "nls_utf8" ]; + [ "cifs" "virtio_net" "virtio_pci" "virtio_blk" "virtio_balloon" "nls_utf8" ] + ++ optional cfg.writableStore [ "aufs" ]; + + boot.extraModulePackages = + optional cfg.writableStore config.boot.kernelPackages.aufs2; boot.initrd.extraUtilsCommands = '' @@ -190,6 +205,16 @@ in fi ''; + boot.initrd.postMountCommands = + '' + mount -o remount,ro $targetRoot/nix/store + ${optionalString cfg.writableStore '' + mkdir /mnt-store-tmpfs + mount -t tmpfs -o "mode=755" none /mnt-store-tmpfs + mount -t aufs -o dirs=/mnt-store-tmpfs=rw:$targetRoot/nix/store=rr none $targetRoot/nix/store + ''} + ''; + # After booting, register the closure of the paths in # `virtualisation.pathsInNixDB' in the Nix database in the VM. This # allows Nix operations to work in the VM. The path to the diff --git a/tests/installer.nix b/tests/installer.nix index 5a71f246b584..ed1bb2b9028b 100644 --- a/tests/installer.nix +++ b/tests/installer.nix @@ -77,18 +77,7 @@ let dir = "/tmp/channel"; }; - # Make the Nix store in this VM writable using AUFS. This - # should probably be moved to qemu-vm.nix. - boot.extraModulePackages = [ config.boot.kernelPackages.aufs2 ]; - boot.initrd.availableKernelModules = [ "aufs" ]; - - boot.initrd.postMountCommands = - '' - mkdir /mnt-store-tmpfs - mount -t tmpfs -o "mode=755" none /mnt-store-tmpfs - mount -t aufs -o dirs=/mnt-store-tmpfs=rw:$targetRoot/nix/store=rr none $targetRoot/nix/store - ''; - + virtualisation.writableStore = true; virtualisation.pathsInNixDB = channelContents; };