Skip to content

Commit

Permalink
nixos/qemu-vm: introduce virtualisation.mountHostNixStore option
Browse files Browse the repository at this point in the history
Now that `useBootLoader` produces a full system image, moving disk
images can be slow because they have a full Nix store in them.

It does not make sense to keep the 9p mountpoint to shadow the
/nix/store of the VM.

We disable it if we have `useBootLoader` and introduce an option for
easy overrides.
  • Loading branch information
RaitoBezarius committed Apr 23, 2023
1 parent 6d69171 commit 0df5257
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions nixos/modules/virtualisation/qemu-vm.nix
Original file line number Diff line number Diff line change
Expand Up @@ -574,12 +574,15 @@ in
virtualisation.writableStore =
mkOption {
type = types.bool;
default = true; # FIXME
default = cfg.mountHostNixStore;
defaultText = literalExpression "cfg.mountHostNixStore";
description =
lib.mdDoc ''
If enabled, the Nix store in the VM is made writable by
layering an overlay filesystem on top of the host's Nix
store.
By default, this is enabled if you mount a host Nix store.
'';
};

Expand Down Expand Up @@ -713,6 +716,21 @@ in
For applications which do a lot of reads from the store,
this can drastically improve performance, but at the cost of
disk space and image build time.
As an alternative, you can use a bootloader which will provide you
with a full NixOS system image containing a Nix store and
avoid mounting the host nix store through
{option}`virtualisation.mountHostNixStore`.
'';
};

virtualisation.mountHostNixStore =
mkOption {
type = types.bool;
default = !cfg.useNixStoreImage && !cfg.useBootLoader;
defaultText = literalExpression "!cfg.useNixStoreImage && !cfg.useBootLoader";
description = lib.mdDoc ''
Mount the host Nix store as a 9p mount.
'';
};

Expand Down Expand Up @@ -933,7 +951,7 @@ in
virtualisation.additionalPaths = [ config.system.build.toplevel ];

virtualisation.sharedDirectories = {
nix-store = mkIf (!cfg.useNixStoreImage) {
nix-store = mkIf cfg.mountHostNixStore {
source = builtins.storeDir;
target = "/nix/store";
};
Expand Down

0 comments on commit 0df5257

Please sign in to comment.