2023-05-11 14:35:00 +02:00
|
|
|
{ system ? builtins.currentSystem
|
|
|
|
, config ? { }
|
|
|
|
, pkgs ? import ../.. { inherit system config; }
|
|
|
|
}:
|
2022-06-22 04:10:44 +02:00
|
|
|
|
2023-05-11 14:35:00 +02:00
|
|
|
with import ../lib/testing-python.nix { inherit system pkgs; };
|
|
|
|
with pkgs.lib;
|
|
|
|
{
|
2023-05-26 15:26:48 +02:00
|
|
|
bind = makeTest {
|
|
|
|
name = "non-default-filesystem-bind";
|
|
|
|
|
|
|
|
nodes.machine = { ... }: {
|
|
|
|
virtualisation.writableStore = false;
|
|
|
|
|
|
|
|
virtualisation.fileSystems."/test-bind-dir/bind" = {
|
|
|
|
device = "/";
|
|
|
|
neededForBoot = true;
|
|
|
|
options = [ "bind" ];
|
|
|
|
};
|
|
|
|
|
|
|
|
virtualisation.fileSystems."/test-bind-file/bind" = {
|
|
|
|
depends = [ "/nix/store" ];
|
|
|
|
device = builtins.toFile "empty" "";
|
|
|
|
neededForBoot = true;
|
|
|
|
options = [ "bind" ];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
testScript = ''
|
|
|
|
machine.wait_for_unit("multi-user.target")
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2023-05-11 14:35:00 +02:00
|
|
|
btrfs = makeTest
|
2022-06-22 04:10:44 +02:00
|
|
|
{
|
2023-05-11 14:35:00 +02:00
|
|
|
name = "non-default-filesystems-btrfs";
|
2022-06-22 04:10:44 +02:00
|
|
|
|
2023-05-11 14:35:00 +02:00
|
|
|
nodes.machine =
|
|
|
|
{ config, pkgs, lib, ... }:
|
|
|
|
let
|
|
|
|
disk = config.virtualisation.rootDevice;
|
|
|
|
in
|
|
|
|
{
|
|
|
|
virtualisation.rootDevice = "/dev/vda";
|
|
|
|
virtualisation.useDefaultFilesystems = false;
|
2022-06-22 04:10:44 +02:00
|
|
|
|
2023-05-11 14:35:00 +02:00
|
|
|
boot.initrd.availableKernelModules = [ "btrfs" ];
|
|
|
|
boot.supportedFilesystems = [ "btrfs" ];
|
2022-06-22 04:10:44 +02:00
|
|
|
|
2023-05-11 14:35:00 +02:00
|
|
|
boot.initrd.postDeviceCommands = ''
|
|
|
|
FSTYPE=$(blkid -o value -s TYPE ${disk} || true)
|
|
|
|
if test -z "$FSTYPE"; then
|
|
|
|
modprobe btrfs
|
|
|
|
${pkgs.btrfs-progs}/bin/mkfs.btrfs ${disk}
|
2022-06-22 04:10:44 +02:00
|
|
|
|
2023-05-11 14:35:00 +02:00
|
|
|
mkdir /nixos
|
|
|
|
mount -t btrfs ${disk} /nixos
|
2022-06-22 04:10:44 +02:00
|
|
|
|
2023-05-11 14:35:00 +02:00
|
|
|
${pkgs.btrfs-progs}/bin/btrfs subvolume create /nixos/root
|
|
|
|
${pkgs.btrfs-progs}/bin/btrfs subvolume create /nixos/home
|
|
|
|
|
|
|
|
umount /nixos
|
|
|
|
fi
|
|
|
|
'';
|
2022-06-22 04:10:44 +02:00
|
|
|
|
2023-05-11 14:35:00 +02:00
|
|
|
virtualisation.fileSystems = {
|
|
|
|
"/" = {
|
|
|
|
device = disk;
|
|
|
|
fsType = "btrfs";
|
|
|
|
options = [ "subvol=/root" ];
|
|
|
|
};
|
|
|
|
|
|
|
|
"/home" = {
|
|
|
|
device = disk;
|
|
|
|
fsType = "btrfs";
|
|
|
|
options = [ "subvol=/home" ];
|
|
|
|
};
|
|
|
|
};
|
2022-06-22 04:10:44 +02:00
|
|
|
};
|
|
|
|
|
2023-05-11 14:35:00 +02:00
|
|
|
testScript = ''
|
|
|
|
machine.wait_for_unit("multi-user.target")
|
|
|
|
|
|
|
|
with subtest("BTRFS filesystems are mounted correctly"):
|
|
|
|
machine.succeed("grep -E '/dev/vda / btrfs rw,relatime,space_cache=v2,subvolid=[0-9]+,subvol=/root 0 0' /proc/mounts")
|
|
|
|
machine.succeed("grep -E '/dev/vda /home btrfs rw,relatime,space_cache=v2,subvolid=[0-9]+,subvol=/home 0 0' /proc/mounts")
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
erofs =
|
|
|
|
let
|
|
|
|
fsImage = "/tmp/non-default-filesystem.img";
|
|
|
|
in
|
|
|
|
makeTest {
|
|
|
|
name = "non-default-filesystems-erofs";
|
|
|
|
|
2023-07-04 17:17:32 +02:00
|
|
|
meta.maintainers = with maintainers; [ nikstur ];
|
|
|
|
|
2023-05-11 14:35:00 +02:00
|
|
|
nodes.machine = _: {
|
|
|
|
virtualisation.qemu.drives = [{
|
|
|
|
name = "non-default-filesystem";
|
|
|
|
file = fsImage;
|
|
|
|
}];
|
|
|
|
|
|
|
|
virtualisation.fileSystems."/non-default" = {
|
|
|
|
device = "/dev/vdb";
|
|
|
|
fsType = "erofs";
|
|
|
|
neededForBoot = true;
|
2022-06-22 04:10:44 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2023-05-11 14:35:00 +02:00
|
|
|
testScript = ''
|
|
|
|
import subprocess
|
|
|
|
import tempfile
|
2022-06-22 04:10:44 +02:00
|
|
|
|
2023-05-11 14:35:00 +02:00
|
|
|
with tempfile.TemporaryDirectory() as tmp_dir:
|
|
|
|
with open(f"{tmp_dir}/filesystem", "w") as f:
|
|
|
|
f.write("erofs")
|
|
|
|
|
|
|
|
subprocess.run([
|
|
|
|
"${pkgs.erofs-utils}/bin/mkfs.erofs",
|
|
|
|
"${fsImage}",
|
|
|
|
tmp_dir,
|
|
|
|
])
|
|
|
|
|
|
|
|
machine.start()
|
|
|
|
machine.wait_for_unit("default.target")
|
|
|
|
|
|
|
|
file_contents = machine.succeed("cat /non-default/filesystem")
|
|
|
|
assert "erofs" in file_contents
|
|
|
|
'';
|
|
|
|
};
|
2023-07-04 17:09:00 +02:00
|
|
|
|
|
|
|
squashfs =
|
|
|
|
let
|
|
|
|
fsImage = "/tmp/non-default-filesystem.img";
|
|
|
|
in
|
|
|
|
makeTest {
|
|
|
|
name = "non-default-filesystems-squashfs";
|
|
|
|
|
|
|
|
meta.maintainers = with maintainers; [ nikstur ];
|
|
|
|
|
|
|
|
nodes.machine = {
|
|
|
|
virtualisation.qemu.drives = [{
|
|
|
|
name = "non-default-filesystem";
|
|
|
|
file = fsImage;
|
|
|
|
deviceExtraOpts.serial = "non-default";
|
|
|
|
}];
|
|
|
|
|
|
|
|
virtualisation.fileSystems."/non-default" = {
|
|
|
|
device = "/dev/disk/by-id/virtio-non-default";
|
|
|
|
fsType = "squashfs";
|
|
|
|
neededForBoot = true;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
testScript = ''
|
|
|
|
import subprocess
|
|
|
|
|
|
|
|
with open("filesystem", "w") as f:
|
|
|
|
f.write("squashfs")
|
|
|
|
|
|
|
|
subprocess.run([
|
|
|
|
"${pkgs.squashfsTools}/bin/mksquashfs",
|
|
|
|
"filesystem",
|
|
|
|
"${fsImage}",
|
|
|
|
])
|
|
|
|
|
|
|
|
assert "squashfs" in machine.succeed("cat /non-default/filesystem")
|
|
|
|
'';
|
|
|
|
};
|
2023-05-11 14:35:00 +02:00
|
|
|
}
|