Skip to content

Commit

Permalink
nixos/tests: add boot-stage2 tests
Browse files Browse the repository at this point in the history
- Test RO store mount even given the presence of filesystems with
  options ending in "ro"
- Test postBootCommands in stage2
  • Loading branch information
numinit committed Jan 20, 2025
1 parent 20d2e6d commit a16f4f1
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions nixos/tests/boot-stage2.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import ./make-test-python.nix (
{ pkgs, ... }:
{
name = "boot-stage2";

nodes.machine =
{
config,
pkgs,
lib,
...
}:
{
virtualisation = {
emptyDiskImages = [ 256 ];

# Mount an ext4 as the upper layer of the Nix store.
fileSystems = {
"/nix/store" = lib.mkForce {
device = "/dev/vdb"; # the above disk image
fsType = "ext4";

# data=journal always displays after errors=remount-ro; this is only needed because of the overlay
# and the bug will trigger with using `errors=remount-ro` on a non-overlaid store
options = [ "defaults" "errors=remount-ro" "data=journal" ];
};
};
};

boot = {
initrd = {
# Format the upper Nix store.
postDeviceCommands = ''
${pkgs.e2fsprogs}/bin/mkfs.ext4 /dev/vdb
'';

# Overlay the RO store onto it for the purposes of the test.
# Note that bug #0 can be triggered without an overlay,
# using the errors=remount-ro option (or similar) or with an overlay where any of the
# paths ends in 'ro'. The offending mountpoint just also has to be the last (top) one
# if an option ending in 'ro' is the last in the list.
postMountCommands = ''
mkdir -p /mnt-root/nix/store/rw /mnt-root/nix/store/work
mount -t overlay overlay \
-o lowerdir=/mnt-root/nix/.ro-store,upperdir=/mnt-root/nix/store/rw,workdir=/mnt-root/nix/store/work \
/mnt-root/nix/store
'';

kernelModules = [ "overlay" ];
};

postBootCommands = ''
touch /etc/post-boot-ran
mount
'';
};
};

testScript = ''
machine.wait_for_unit("multi-user.target")
machine.succeed("test /etc/post-boot-ran")
machine.fail("touch /nix/store/should-not-work");
'';

meta.maintainers = with pkgs.lib.maintainers; [ numinit ];
}
)

0 comments on commit a16f4f1

Please sign in to comment.