qemu-vm: Use unionfs-fuse instead of aufs for writableStore

This commit is contained in:
Shea Levy 2012-12-16 11:56:49 -05:00
parent be4f69519b
commit 3eb0faf317

View File

@ -95,7 +95,7 @@ let
description = description =
'' ''
If enabled, the Nix store in the VM is made writable by If enabled, the Nix store in the VM is made writable by
layering an AUFS/tmpfs filesystem on top of the host's Nix layering a unionfs-fuse/tmpfs filesystem on top of the host's Nix
store. store.
''; '';
}; };
@ -250,16 +250,18 @@ in
# CIFS. Also use paravirtualised network and block devices for # CIFS. Also use paravirtualised network and block devices for
# performance. # performance.
boot.initrd.availableKernelModules = boot.initrd.availableKernelModules =
[ "cifs" "nls_utf8" "hmac" "md4" "ecb" "des_generic" ] [ "cifs" "nls_utf8" "hmac" "md4" "ecb" "des_generic" ];
++ optional cfg.writableStore [ "aufs" ];
boot.extraModulePackages = # unionfs-fuse expects fuse to be loaded
optional cfg.writableStore config.boot.kernelPackages.aufs; boot.initrd.kernelModules = optional cfg.writableStore [ "fuse" ];
boot.initrd.extraUtilsCommands = boot.initrd.extraUtilsCommands =
'' ''
# We need mke2fs in the initrd. # We need mke2fs in the initrd.
cp ${pkgs.e2fsprogs}/sbin/mke2fs $out/bin cp ${pkgs.e2fsprogs}/sbin/mke2fs $out/bin
'' + optionalString cfg.writableStore ''
cp -v ${pkgs.fuse}/lib/libfuse* $out/lib
cp -v ${pkgs.unionfs-fuse}/bin/unionfs $out/bin
''; '';
boot.initrd.postDeviceCommands = boot.initrd.postDeviceCommands =
@ -288,9 +290,17 @@ in
mkdir -p $targetRoot/boot mkdir -p $targetRoot/boot
mount -o remount,ro $targetRoot/nix/store mount -o remount,ro $targetRoot/nix/store
${optionalString cfg.writableStore '' ${optionalString cfg.writableStore ''
mkdir /mnt-store-tmpfs # Hacky!!! fuse hard-codes the path to mount
mount -t tmpfs -o "mode=755" none /mnt-store-tmpfs mkdir -p /nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-${pkgs.utillinux.name}/bin
mount -t aufs -o dirs=/mnt-store-tmpfs=rw:$targetRoot/nix/store=rr none $targetRoot/nix/store ln -s $(which mount) /nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-${pkgs.utillinux.name}/bin
ln -s $(which umount) /nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-${pkgs.utillinux.name}/bin
mkdir -p /unionfs-chroot$targetRoot
mount --rbind $targetRoot /unionfs-chroot$targetRoot
mkdir /unionfs-chroot/mnt-store-tmpfs
mount -t tmpfs -o "mode=755" none /unionfs-chroot/mnt-store-tmpfs
unionfs -o allow_other,cow,nonempty,chroot=/unionfs-chroot /mnt-store-tmpfs=RW:$targetRoot/nix/store=RO $targetRoot/nix/store
''} ''}
''; '';