aboutsummaryrefslogtreecommitdiffstats
path: root/pkgs
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs')
-rw-r--r--pkgs/run-firecracker-vm/default.nix46
1 files changed, 25 insertions, 21 deletions
diff --git a/pkgs/run-firecracker-vm/default.nix b/pkgs/run-firecracker-vm/default.nix
index 041bf60..19a6c9e 100644
--- a/pkgs/run-firecracker-vm/default.nix
+++ b/pkgs/run-firecracker-vm/default.nix
@@ -112,8 +112,8 @@ let
imports = [
(modulesPath + "/profiles/minimal.nix")
(modulesPath + "/profiles/perlless.nix")
- ({ config, ... }: { fileSystems = imageFileSystems (firstImage config) (n + 1); })
- ({ config, ... }: { systemd.generators.fc-home = homeGenerator (drive (firstImage config + n + 1)); })
+ { fileSystems = imageFileSystems (n + 1); }
+ { systemd.generators.fc-home = homeGenerator (label "fc-home"); }
{
# For a layer whose state is in /home: the run script then
# refuses to start the guest without --home.
@@ -201,7 +201,7 @@ let
if lib.length lowerdirs > 1 then {
overlay.lowerdir = lowerdirs;
} else
- (imageFileSystems (firstImage config) 1)."/nix/.image/0";
+ (imageFileSystems 1)."/nix/.image/0";
fileSystems."/xchg" = {
device = "564";
@@ -380,7 +380,7 @@ let
};
# /home: part of / (the tmpfs), or with fc.home on the kernel command
- # line (--home, see the run script), the drive after the images (device).
+ # line (--home, see the run script), the drive labelled fc-home (device).
# A generator rather than fileSystems, so a guest without it doesn't wait
# for the drive.
homeGenerator = device: pkgs.writeShellScript "fc-home-generator" ''
@@ -395,18 +395,18 @@ let
${pkgs.coreutils}/bin/ln -s ../home.mount "$1"/local-fs.target.requires/home.mount
'';
- # The guest's device of drive k (0: vda), see drives below.
- drive = k: "/dev/vd${lib.elemAt (lib.stringToCharacters "abcdefghijklmnopqrstuvwxyz") k}";
+ # The guest's drives go by their filesystems' labels, not by vda, vdb,
+ # ...: those come in the order the kernel probes the drives, which
+ # needn't be theirs in the Firecracker configuration (with virtio_blk
+ # and virtio_mmio as modules, as in linuxPackages_latest, two images
+ # came swapped). The run script labels the rw-store and home.
+ label = l: "/dev/disk/by-label/${l}";
- # The drive of image 0: after the rw-store (vda), if there is one, i.e.
- # with layers/nix.nix, else the first.
- firstImage = config: if config.fc.nix then 1 else 0;
-
- # The images, read-only drives from drive first on: image k (of layer
- # k) is drive first + k.
- imageFileSystems = first: count: lib.listToAttrs (lib.genList (k:
+ # The images, read-only drives, image k (of layer k) labelled
+ # fc-layer-K.
+ imageFileSystems = count: lib.listToAttrs (lib.genList (k:
lib.nameValuePair "/nix/.image/${toString k}" {
- device = drive (first + k);
+ device = label "fc-layer-${toString k}";
fsType = "erofs";
options = [ "ro" "nodev" "nosuid" ];
neededForBoot = true;
@@ -447,7 +447,7 @@ let
tar -c -P --verbatim-files-from \
--transform 'flags=rSh;s|^/nix/store/||' \
--files-from - |
- mkfs.erofs --quiet --tar=f --force-uid=0 --force-gid=0 --hard-dereference -T 0 $out
+ mkfs.erofs --quiet -L fc-layer-${toString k} --tar=f --force-uid=0 --force-gid=0 --hard-dereference -T 0 $out
'') toplevels;
config = pkgs.writeText "firecracker.json" (builtins.toJSON {
@@ -467,7 +467,7 @@ let
host_dev_name = "@TAP@"; # see modules/host
guest_mac = "@MAC@";
}];
- # In this order: vda, vdb, ... (see drive). The run script drops home
+ # The guest finds them by label (see label). The run script drops home
# without --home.
drives = lib.optional nix {
drive_id = "rw-store";
@@ -642,14 +642,15 @@ pkgs.writeShellScriptBin "run-firecracker-vm" /* sh */ ''
esac
done
- # disk VAR FILE SIZE: sets VAR to the absolute path of FILE, an ext4
+ # disk VAR FILE SIZE LABEL: sets VAR to the absolute path of FILE, an ext4
# image, created (sparse, of SIZE) if it doesn't exist; locked while the
- # guest runs, as two guests with the same file would wreck it.
+ # guest runs, as two guests with the same file would wreck it. The guest
+ # finds it by LABEL, which gets set on images from before labels, too.
disk() {
local f=$2 lock
if ! test -e "$f"; then
truncate -s "$3" "$f"
- mkfs.ext4 -q -F "$f"
+ mkfs.ext4 -q -F -L "$4" "$f"
fi
f=$(realpath "$f")
exec {lock}<"$f"
@@ -657,13 +658,16 @@ pkgs.writeShellScriptBin "run-firecracker-vm" /* sh */ ''
echo "$0: $f is in use by another VM" >&2
exit 1
fi
+ if test "$(e2label "$f")" != "$4"; then
+ e2label "$f" "$4"
+ fi
printf -v "$1" %s "$f"
}
if test -n "$rw_store"; then
- disk rw_store "$rw_store" "$rw_store_size"
+ disk rw_store "$rw_store" "$rw_store_size" fc-store
fi
if test -n "$home"; then
- disk home "$home" "$home_size"
+ disk home "$home" "$home_size" fc-home
args="$args fc.home"
fi