nixos/tests: Use autoFormat (#434312)

Emily 07ed5f41 cd06dcae

+40 -16
nixos/modules/virtualisation/qemu-vm.nix
···
cfg = config.virtualisation;
-
opt = options.virtualisation;
-
qemu = cfg.qemu.package;
hostPkgs = cfg.host.pkgs;
consoles = lib.concatMapStringsSep " " (c: "console=${c}") cfg.qemu.consoles;
-
driveOpts =
+
driveOptions =
{ ... }:
{
options = {
-
-
file = mkOption {
-
type = types.str;
-
description = "The file image used for this drive.";
-
};
-
driveExtraOpts = mkOption {
type = types.attrsOf types.str;
default = { };
···
${lib.pipe cfg.emptyDiskImages [
(lib.imap0 (
-
idx: size: ''
+
idx:
+
{ size, ... }:
+
''
test -e "empty${builtins.toString idx}.qcow2" || ${qemu}/bin/qemu-img create -f qcow2 "empty${builtins.toString idx}.qcow2" "${builtins.toString size}M"
''
))
···
};
virtualisation.emptyDiskImages = mkOption {
-
type = types.listOf types.ints.positive;
+
type = types.listOf (
+
types.coercedTo types.ints.positive (size: { inherit size; }) (
+
types.submodule {
+
options.size = mkOption {
+
type = types.ints.positive;
+
description = "The size of the disk in MiB";
+
};
+
options.driveConfig = mkOption {
+
type = lib.types.submodule driveOptions;
+
description = "Drive configuration to pass to {option}`virtualisation.qemu.drives`";
+
};
+
}
+
)
+
);
default = [ ];
description = ''
Additional disk images to provide to the VM. The value is
···
};
drives = mkOption {
-
type = types.listOf (types.submodule driveOpts);
+
type = types.listOf (
+
types.submodule {
+
imports = [ driveOptions ];
+
+
options = {
+
file = mkOption {
+
type = types.str;
+
description = "The file image used for this drive.";
+
};
+
};
+
}
+
);
description = "Drives passed to qemu.";
};
···
driveExtraOpts.format = "raw";
])
-
(imap0 (idx: _: {
-
file = "$(pwd)/empty${toString idx}.qcow2";
-
driveExtraOpts.werror = "report";
-
}) cfg.emptyDiskImages)
+
(imap0 (
+
idx: imgCfg:
+
lib.mkMerge [
+
{
+
file = "$(pwd)/empty${toString idx}.qcow2";
+
driveExtraOpts.werror = "report";
+
}
+
imgCfg.driveConfig
+
]
+
) cfg.emptyDiskImages)
];
# By default, use mkVMOverride to enable building test VMs (e.g. via
+13 -9
nixos/tests/bees.nix
···
nodes.machine =
{ config, pkgs, ... }:
{
-
boot.initrd.postDeviceCommands = ''
-
${pkgs.btrfs-progs}/bin/mkfs.btrfs -f -L aux1 /dev/vdb
-
${pkgs.btrfs-progs}/bin/mkfs.btrfs -f -L aux2 /dev/vdc
-
'';
virtualisation.emptyDiskImages = [
-
4096
-
4096
+
{
+
size = 4096;
+
driveConfig.deviceExtraOpts.serial = "aux1";
+
}
+
{
+
size = 4096;
+
driveConfig.deviceExtraOpts.serial = "aux2";
+
}
];
virtualisation.fileSystems = {
"/aux1" = {
# filesystem configured to be deduplicated
-
device = "/dev/disk/by-label/aux1";
+
device = "/dev/disk/by-id/virtio-aux1";
fsType = "btrfs";
+
autoFormat = true;
};
"/aux2" = {
# filesystem not configured to be deduplicated
-
device = "/dev/disk/by-label/aux2";
+
device = "/dev/disk/by-id/virtio-aux2";
fsType = "btrfs";
+
autoFormat = true;
};
};
services.beesd.filesystems = {
aux1 = {
-
spec = "LABEL=aux1";
+
spec = "/dev/disk/by-id/virtio-aux1";
hashTableSizeMB = 16;
verbosity = "debug";
};
+8 -7
nixos/tests/glusterfs.nix
···
networking.firewall.enable = false;
services.glusterfs.enable = true;
-
# create a mount point for the volume
-
boot.initrd.postDeviceCommands = ''
-
${pkgs.e2fsprogs}/bin/mkfs.ext4 -L data /dev/vdb
-
'';
-
-
virtualisation.emptyDiskImages = [ 1024 ];
+
virtualisation.emptyDiskImages = [
+
{
+
size = 1024;
+
driveConfig.deviceExtraOpts.serial = "data";
+
}
+
];
virtualisation.fileSystems = {
"/data" = {
-
device = "/dev/disk/by-label/data";
+
device = "/dev/disk/by-id/virtio-data";
fsType = "ext4";
+
autoFormat = true;
};
};
};
+12 -10
nixos/tests/hardened.nix
···
imports = [ ../modules/profiles/hardened.nix ];
environment.memoryAllocator.provider = "graphene-hardened";
nix.settings.sandbox = false;
-
virtualisation.emptyDiskImages = [ 4096 ];
-
boot.initrd.postDeviceCommands = ''
-
${pkgs.dosfstools}/bin/mkfs.vfat -n EFISYS /dev/vdb
-
'';
+
virtualisation.emptyDiskImages = [
+
{
+
size = 4096;
+
driveConfig.deviceExtraOpts.serial = "deferred";
+
}
+
];
virtualisation.fileSystems = {
-
"/efi" = {
-
device = "/dev/disk/by-label/EFISYS";
+
"/deferred" = {
+
device = "/dev/disk/by-id/virtio-deferred";
fsType = "vfat";
+
autoFormat = true;
options = [ "noauto" ];
};
};
···
# Test deferred mount
with subtest("Deferred mounts work"):
-
machine.fail("mountpoint -q /efi") # was deferred
-
machine.execute("mkdir -p /efi")
-
machine.succeed("mount /dev/disk/by-label/EFISYS /efi")
-
machine.succeed("mountpoint -q /efi") # now mounted
+
machine.fail("mountpoint -q /deferred") # was deferred
+
machine.systemctl("start deferred.mount")
+
machine.succeed("mountpoint -q /deferred") # now mounted
# Test Nix dæmon usage
+8 -5
nixos/tests/moosefs.nix
···
chunkserver =
{ pkgs, ... }:
{
-
virtualisation.emptyDiskImages = [ 4096 ];
-
boot.initrd.postDeviceCommands = ''
-
${pkgs.e2fsprogs}/bin/mkfs.ext4 -L data /dev/vdb
-
'';
+
virtualisation.emptyDiskImages = [
+
{
+
size = 4096;
+
driveConfig.deviceExtraOpts.serial = "data";
+
}
+
];
fileSystems = pkgs.lib.mkVMOverride {
"/data" = {
-
device = "/dev/disk/by-label/data";
+
device = "/dev/disk/by-id/virtio-data";
fsType = "ext4";
+
autoFormat = true;
};
};
+8 -5
nixos/tests/orangefs.nix
···
{ pkgs, ... }:
{
networking.firewall.allowedTCPPorts = [ 3334 ];
-
boot.initrd.postDeviceCommands = ''
-
${pkgs.e2fsprogs}/bin/mkfs.ext4 -L data /dev/vdb
-
'';
-
virtualisation.emptyDiskImages = [ 4096 ];
+
virtualisation.emptyDiskImages = [
+
{
+
size = 4096;
+
driveConfig.deviceExtraOpts.serial = "data";
+
}
+
];
virtualisation.fileSystems = {
"/data" = {
-
device = "/dev/disk/by-label/data";
+
device = "/dev/disk/by-id/virtio-data";
fsType = "ext4";
+
autoFormat = true;
};
};
+8 -5
nixos/tests/saunafs.nix
···
chunkserver =
{ pkgs, ... }:
{
-
virtualisation.emptyDiskImages = [ 4096 ];
-
boot.initrd.postDeviceCommands = ''
-
${pkgs.e2fsprogs}/bin/mkfs.ext4 -L data /dev/vdb
-
'';
+
virtualisation.emptyDiskImages = [
+
{
+
size = 4096;
+
driveConfig.deviceExtraOpts.serial = "data";
+
}
+
];
fileSystems = pkgs.lib.mkVMOverride {
"/data" = {
-
device = "/dev/disk/by-label/data";
+
device = "/dev/disk/by-id/virtio-data";
fsType = "ext4";
+
autoFormat = true;
};
};
+8 -6
nixos/tests/snapper.nix
···
nodes.machine =
{ pkgs, lib, ... }:
{
-
boot.initrd.postDeviceCommands = ''
-
${pkgs.btrfs-progs}/bin/mkfs.btrfs -f -L aux /dev/vdb
-
'';
-
-
virtualisation.emptyDiskImages = [ 4096 ];
+
virtualisation.emptyDiskImages = [
+
{
+
size = 4096;
+
driveConfig.deviceExtraOpts.serial = "aux";
+
}
+
];
virtualisation.fileSystems = {
"/home" = {
-
device = "/dev/disk/by-label/aux";
+
device = "/dev/disk/by-id/virtio-aux";
fsType = "btrfs";
+
autoFormat = true;
};
};
services.snapper.configs.home.SUBVOLUME = "/home";
+4 -6
nixos/tests/swap-file-btrfs.nix
···
meta.maintainers = with lib.maintainers; [ oxalica ];
nodes.machine =
-
{ pkgs, ... }:
+
{ config, pkgs, ... }:
{
virtualisation.useDefaultFilesystems = false;
virtualisation.rootDevice = "/dev/vda";
-
boot.initrd.postDeviceCommands = ''
-
${pkgs.btrfs-progs}/bin/mkfs.btrfs --label root /dev/vda
-
'';
-
+
boot.initrd.systemd.enable = true;
virtualisation.fileSystems = {
"/" = {
-
device = "/dev/disk/by-label/root";
+
device = config.virtualisation.rootDevice;
fsType = "btrfs";
+
autoFormat = true;
};
};