aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--layers/nix.nix14
-rw-r--r--pkgs/run-firecracker-vm/default.nix20
2 files changed, 25 insertions, 9 deletions
diff --git a/layers/nix.nix b/layers/nix.nix
index 67639be..b679539 100644
--- a/layers/nix.nix
+++ b/layers/nix.nix
@@ -5,7 +5,7 @@
# its images, read-only. With it, the run script requires --store.
{ config, lib, pkgs, ... }:
let
- inherit (config.fileSystems."/nix/store".overlay) lowerdir;
+ lowerdir = config.fc.storeLowerdirs;
in
{
nix.enable = true;
@@ -50,10 +50,11 @@ in
};
# The images are an overlay already: this is one image more than the
# base system, so there are at least two.
- fileSystems."/nix/store".overlay = {
- lowerdir = [ "/nix/.host-store" ];
- upperdir = "/nix/.rw-store/store";
- workdir = "/nix/.rw-store/work";
+ fc.storeLowerdirs = [ "/nix/.host-store" ];
+ # The upper layer, which fc-rw-store-unshadow (below) creates.
+ fileSystems."/nix/store" = {
+ depends = [ "/nix/.rw-store" ];
+ options = [ "upperdir=/sysroot/nix/.rw-store/store" "workdir=/sysroot/nix/.rw-store/work" ];
};
# nix in the guest deletes a path in the store that isn't in its
# database before it adds it, like the host's store's paths. On the
@@ -70,7 +71,8 @@ in
unitConfig.RequiresMountsFor = map (d: "/sysroot" + d) ([ "/nix/.rw-store" ] ++ lowerdir);
serviceConfig.Type = "oneshot";
script = ''
- cd /sysroot/nix/.rw-store/store 2>/dev/null || exit 0
+ mkdir -p -m 0755 /sysroot/nix/.rw-store/store /sysroot/nix/.rw-store/work
+ cd /sysroot/nix/.rw-store/store
for p in *; do
for d in ${toString (map (d: "/sysroot" + d) lowerdir)}; do
if test -e "$d/$p"; then
diff --git a/pkgs/run-firecracker-vm/default.nix b/pkgs/run-firecracker-vm/default.nix
index 63cb06a..5f07e0c 100644
--- a/pkgs/run-firecracker-vm/default.nix
+++ b/pkgs/run-firecracker-vm/default.nix
@@ -130,6 +130,13 @@ let
internal = true;
description = "Whether the guest has layers/nix.nix.";
};
+ # The store's lower layers: the images (from the layers), and
+ # what layers add, like layers/nix.nix the host's store.
+ options.fc.storeLowerdirs = lib.mkOption {
+ type = lib.types.listOf lib.types.str;
+ internal = true;
+ description = "The store's lower layers, as in the guest's /.";
+ };
options.fc.mountVsock9p = lib.mkOption {
type = lib.types.package;
default = mountVsock9p;
@@ -196,10 +203,17 @@ let
# imageFileSystems and images below), read-only, or with
# layers/nix.nix, writable. Without an upper layer, overlayfs needs
# at least two lower ones: a single image is the store itself
- # (mounted a second time).
+ # (mounted a second time). Not with overlay.lowerdir: NixOS makes
+ # that a single option (lowerdir=A:B:...), which the mount API caps
+ # at 255 bytes, i.e. about 10 images; a lowerdir+= each has no such
+ # limit. An upper layer (layers/nix.nix) adds its own options.
+ fc.storeLowerdirs = lib.mkBefore lowerdirs; # images first: 9P is slow
fileSystems."/nix/store" =
- if lib.length lowerdirs > 1 then {
- overlay.lowerdir = lowerdirs;
+ if lib.length config.fc.storeLowerdirs > 1 then {
+ fsType = "overlay";
+ device = "overlay";
+ depends = config.fc.storeLowerdirs;
+ options = map (d: "lowerdir+=/sysroot${d}") config.fc.storeLowerdirs;
} else
(imageFileSystems 1)."/nix/.image/0";