From 04452cfd2bafc8f7158f88de3b7de011a754b608 Mon Sep 17 00:00:00 2001 From: lassulus Date: Sat, 15 Jul 2023 20:42:37 +0200 Subject: [PATCH] tests: refactor to not use args and to use gpt type --- example/bcachefs.nix | 4 +- example/boot-raid1.nix | 31 ++++++-------- example/btrfs-subvolumes.nix | 4 +- example/complex.nix | 8 ++-- example/gpt-bios-compat.nix | 4 +- example/hybrid-tmpfs-on-root.nix | 38 +++++++---------- example/hybrid.nix | 38 +++++++---------- example/luks-lvm.nix | 28 +++++------- example/lvm-raid.nix | 55 +++++++++--------------- example/lvm-sizes-sort.nix | 28 +++++------- example/mdadm.nix | 73 +++++++++++++------------------- example/multi-device-no-deps.nix | 40 +++++++---------- example/negative-size.nix | 21 ++++----- example/swap.nix | 36 ++++++---------- example/tmpfs.nix | 30 +++++-------- example/with-lib.nix | 32 ++++++-------- example/zfs-over-legacy.nix | 31 ++++++-------- example/zfs.nix | 46 ++++++++------------ lib/tests.nix | 9 +++- 19 files changed, 221 insertions(+), 335 deletions(-) diff --git a/example/bcachefs.nix b/example/bcachefs.nix index 42a9a19..008e67e 100644 --- a/example/bcachefs.nix +++ b/example/bcachefs.nix @@ -1,8 +1,8 @@ -{ disks ? [ "/dev/vdb" ], ... }: { +{ disko.devices = { disk = { vdb = { - device = builtins.elemAt disks 0; + device = "/dev/disk/by-path/pci-0000:02:00.0-nvme-1"; type = "disk"; content = { type = "gpt"; diff --git a/example/boot-raid1.nix b/example/boot-raid1.nix index 6a026ef..8fbe73b 100644 --- a/example/boot-raid1.nix +++ b/example/boot-raid1.nix @@ -1,9 +1,9 @@ -{ disks ? [ "/dev/vdb" "/dev/vdc" ], ... }: { +{ disko.devices = { disk = { one = { type = "disk"; - device = builtins.elemAt disks 0; + device = "/dev/sda"; content = { type = "gpt"; partitions = { @@ -12,7 +12,7 @@ type = "EF02"; }; ESP = { - size = "128M"; + size = "100M"; type = "EF00"; content = { type = "mdraid"; @@ -31,7 +31,7 @@ }; two = { type = "disk"; - device = builtins.elemAt disks 1; + device = "/dev/sdb"; content = { type = "gpt"; partitions = { @@ -73,20 +73,15 @@ type = "mdadm"; level = 1; content = { - type = "table"; - format = "gpt"; - partitions = [ - { - name = "primary"; - start = "1MiB"; - end = "100%"; - content = { - type = "filesystem"; - format = "ext4"; - mountpoint = "/"; - }; - } - ]; + type = "gpt"; + partitions.primary = { + size = "100%"; + content = { + type = "filesystem"; + format = "ext4"; + mountpoint = "/"; + }; + }; }; }; }; diff --git a/example/btrfs-subvolumes.nix b/example/btrfs-subvolumes.nix index 1f0040d..877cf12 100644 --- a/example/btrfs-subvolumes.nix +++ b/example/btrfs-subvolumes.nix @@ -1,9 +1,9 @@ -{ disks ? [ "/dev/vdb" ], ... }: { +{ disko.devices = { disk = { vdb = { type = "disk"; - device = builtins.elemAt disks 0; + device = "/dev/disk/by-diskseq/1"; content = { type = "gpt"; partitions = { diff --git a/example/complex.nix b/example/complex.nix index 722cea5..4a6f35f 100644 --- a/example/complex.nix +++ b/example/complex.nix @@ -1,9 +1,9 @@ -{ disks ? [ "/dev/vdb" "/dev/vdc" "/dev/vdd" ], ... }: { +{ disko.devices = { disk = { disk0 = { type = "disk"; - device = builtins.elemAt disks 0; + device = "/dev/disk/by-id/ata-QEMU_HARDDISK_QM00001"; content = { type = "gpt"; partitions = { @@ -21,7 +21,7 @@ }; disk1 = { type = "disk"; - device = builtins.elemAt disks 1; + device = "/dev/disk/by-id/ata-QEMU_HARDDISK_QM00002"; content = { type = "gpt"; partitions = { @@ -47,7 +47,7 @@ }; disk2 = { type = "disk"; - device = builtins.elemAt disks 2; + device = "/dev/disk/by-id/ata-QEMU_HARDDISK_QM00003"; content = { type = "gpt"; partitions = { diff --git a/example/gpt-bios-compat.nix b/example/gpt-bios-compat.nix index 837b38a..6ace866 100644 --- a/example/gpt-bios-compat.nix +++ b/example/gpt-bios-compat.nix @@ -1,9 +1,9 @@ # Example to create a bios compatible gpt partition -{ disks ? [ "/dev/vdb" ], ... }: { +{ disko.devices = { disk = { vdb = { - device = builtins.elemAt disks 0; + device = "/dev/vdb"; type = "disk"; content = { type = "gpt"; diff --git a/example/hybrid-tmpfs-on-root.nix b/example/hybrid-tmpfs-on-root.nix index 7a4ef8f..46a1c76 100644 --- a/example/hybrid-tmpfs-on-root.nix +++ b/example/hybrid-tmpfs-on-root.nix @@ -1,41 +1,33 @@ -{ disks ? [ "/dev/sda" ], ... }: { +{ disko.devices = { disk.main = { - device = builtins.elemAt disks 0; + device = "/dev/disk/by-id/ata-Samsung_SSD_860_EVO_500GB_S3Z1NB0K303456L"; type = "disk"; content = { - type = "table"; - format = "gpt"; - partitions = [ - { - name = "boot"; - start = "0"; - end = "1M"; - flags = [ "bios_grub" ]; - } - { + type = "gpt"; + partitions = { + boot = { + size = "1M"; + type = "EF02"; + }; + ESP = { name = "ESP"; - start = "1M"; - end = "512M"; - bootable = true; + size = "512M"; content = { type = "filesystem"; format = "vfat"; mountpoint = "/boot"; }; - } - { - name = "nix"; - start = "512M"; - end = "100%"; - part-type = "primary"; + }; + nix = { + size = "100%"; content = { type = "filesystem"; format = "ext4"; mountpoint = "/nix"; }; - } - ]; + }; + }; }; }; nodev."/" = { diff --git a/example/hybrid.nix b/example/hybrid.nix index aeef6b8..5f97fa9 100644 --- a/example/hybrid.nix +++ b/example/hybrid.nix @@ -1,41 +1,33 @@ -{ disks ? [ "/dev/vda" ], ... }: { +{ disko.devices = { disk = { main = { type = "disk"; - device = builtins.elemAt disks 0; + device = "/dev/disk/by-id/ata-Samsung_SSD_850_EVO_250GB_S21PNXAGB12345"; content = { - type = "table"; - format = "gpt"; - partitions = [ - { - name = "boot"; - start = "0"; - end = "1M"; - flags = [ "bios_grub" ]; - } - { - name = "ESP"; - start = "1M"; - end = "512M"; - bootable = true; + type = "gpt"; + partitions = { + boot = { + size = "1M"; + type = "EF02"; + }; + ESP = { + size = "512M"; content = { type = "filesystem"; format = "vfat"; mountpoint = "/boot"; }; - } - { - name = "root"; - start = "512M"; - end = "100%"; + }; + root = { + size = "100%"; content = { type = "filesystem"; format = "ext4"; mountpoint = "/"; }; - } - ]; + }; + }; }; }; }; diff --git a/example/luks-lvm.nix b/example/luks-lvm.nix index acadad6..48d3c84 100644 --- a/example/luks-lvm.nix +++ b/example/luks-lvm.nix @@ -1,18 +1,14 @@ -{ disks ? [ "/dev/vdb" ], ... }: { +{ disko.devices = { disk = { vdb = { type = "disk"; - device = builtins.elemAt disks 0; + device = "/dev/vdb"; content = { - type = "table"; - format = "gpt"; - partitions = [ - { - name = "ESP"; - start = "1MiB"; - end = "100MiB"; - bootable = true; + type = "gpt"; + partitions = { + ESP = { + size = "100M"; content = { type = "filesystem"; format = "vfat"; @@ -21,11 +17,9 @@ "defaults" ]; }; - } - { - name = "luks"; - start = "100MiB"; - end = "100%"; + }; + luks = { + size = "100%"; content = { type = "luks"; name = "crypted"; @@ -39,8 +33,8 @@ vg = "pool"; }; }; - } - ]; + }; + }; }; }; }; diff --git a/example/lvm-raid.nix b/example/lvm-raid.nix index 2c06d88..b26b24c 100644 --- a/example/lvm-raid.nix +++ b/example/lvm-raid.nix @@ -1,64 +1,51 @@ -{ disks ? [ "/dev/vdb" "/dev/vdc" ], ... }: { +{ disko.devices = { disk = { one = { type = "disk"; - device = builtins.elemAt disks 0; + device = "/dev/sda"; content = { - type = "table"; - format = "gpt"; - partitions = [ - { - name = "boot"; - start = "0"; - end = "100M"; - fs-type = "fat32"; - bootable = true; + type = "gpt"; + partitions = { + boot = { + size = "100M"; content = { type = "mdraid"; name = "boot"; }; - } - { - name = "primary"; - start = "100M"; - end = "100%"; + }; + primary = { + size = "100%"; content = { type = "lvm_pv"; vg = "pool"; }; - } - ]; + }; + }; }; }; two = { type = "disk"; - device = builtins.elemAt disks 1; + device = "/dev/sdb"; content = { - type = "table"; - format = "gpt"; - partitions = [ - { + type = "gpt"; + partitions = { + boot = { name = "boot"; - start = "0"; - end = "100M"; - fs-type = "fat32"; - bootable = true; + size = "100M"; content = { type = "mdraid"; name = "boot"; }; - } - { - name = "primary"; - start = "100M"; - end = "100%"; + }; + primary = { + size = "100%"; content = { type = "lvm_pv"; vg = "pool"; }; - } - ]; + }; + }; }; }; }; diff --git a/example/lvm-sizes-sort.nix b/example/lvm-sizes-sort.nix index e5bb08d..a088adc 100644 --- a/example/lvm-sizes-sort.nix +++ b/example/lvm-sizes-sort.nix @@ -1,35 +1,29 @@ -{ disks ? [ "/dev/vdb" "/dev/vdc" ], ... }: { +{ disko.devices = { disk = { one = { type = "disk"; - device = builtins.elemAt disks 0; + device = "/dev/disk/by-id/ata-VMware_Virtual_SATA_CDRW_Drive_00000000000000000001"; content = { - type = "table"; - format = "gpt"; - partitions = [ - { - name = "boot"; - start = "0"; - end = "100M"; - fs-type = "fat32"; - bootable = true; + type = "gpt"; + partitions = { + boot = { + size = "100M"; content = { type = "filesystem"; format = "vfat"; mountpoint = "/boot"; }; - } - { + }; + primary = { name = "primary"; - start = "100M"; - end = "100%"; + size = "100%"; content = { type = "lvm_pv"; vg = "pool"; }; - } - ]; + }; + }; }; }; }; diff --git a/example/mdadm.nix b/example/mdadm.nix index ccabe5c..08178d2 100644 --- a/example/mdadm.nix +++ b/example/mdadm.nix @@ -1,56 +1,44 @@ -{ disks ? [ "/dev/vdb" "/dev/vdc" ], ... }: { +{ disko.devices = { disk = { vdb = { type = "disk"; - device = builtins.elemAt disks 0; + device = "/dev/my-disk"; content = { - type = "table"; - format = "gpt"; - partitions = [ - { - name = "boot"; - start = "0"; - end = "1M"; - part-type = "primary"; - flags = [ "bios_grub" ]; - } - { - name = "mdadm"; - start = "1MiB"; - end = "100%"; + type = "gpt"; + partitions = { + boot = { + size = "1M"; + type = "EF02"; + }; + mdadm = { + size = "100%"; content = { type = "mdraid"; name = "raid1"; }; - } - ]; + }; + }; }; }; vdc = { type = "disk"; - device = builtins.elemAt disks 1; + device = "/dev/my-disk2"; content = { - type = "table"; - format = "gpt"; - partitions = [ - { - name = "boot"; - start = "0"; - end = "1M"; - part-type = "primary"; - flags = [ "bios_grub" ]; - } - { - name = "mdadm"; - start = "1MiB"; - end = "100%"; + type = "gpt"; + partitions = { + boot = { + size = "1M"; + type = "EF02"; + }; + mdadm = { + size = "100%"; content = { type = "mdraid"; name = "raid1"; }; - } - ]; + }; + }; }; }; }; @@ -59,20 +47,17 @@ type = "mdadm"; level = 1; content = { - type = "table"; - format = "gpt"; - partitions = [ - { - name = "primary"; - start = "1MiB"; - end = "100%"; + type = "gpt"; + partitions = { + primary = { + size = "100%"; content = { type = "filesystem"; format = "ext4"; mountpoint = "/"; }; - } - ]; + }; + }; }; }; }; diff --git a/example/multi-device-no-deps.nix b/example/multi-device-no-deps.nix index 09b0839..dda6782 100644 --- a/example/multi-device-no-deps.nix +++ b/example/multi-device-no-deps.nix @@ -1,48 +1,38 @@ -{ disks ? [ "/dev/vdb" "/dev/vdc" ], ... }: { +{ disko.devices = { disk = { disk0 = { - device = builtins.elemAt disks 0; + device = "/dev/vda"; type = "disk"; content = { - type = "table"; - format = "gpt"; - partitions = [ - { - name = "nix"; - part-type = "primary"; - start = "0%"; - end = "100%"; - bootable = true; + type = "gpt"; + partitions = { + nix = { + size = "100%"; content = { type = "filesystem"; format = "ext4"; mountpoint = "/a"; }; - } - ]; + }; + }; }; }; disk1 = { - device = builtins.elemAt disks 1; + device = "/dev/vdb"; type = "disk"; content = { - type = "table"; - format = "gpt"; - partitions = [ - { - name = "root"; - part-type = "primary"; - start = "0%"; - end = "100%"; - bootable = true; + type = "gpt"; + partitions = { + root = { + size = "100%"; content = { type = "filesystem"; format = "ext4"; mountpoint = "/b"; }; - } - ]; + }; + }; }; }; }; diff --git a/example/negative-size.nix b/example/negative-size.nix index 89d8754..d4d4753 100644 --- a/example/negative-size.nix +++ b/example/negative-size.nix @@ -1,26 +1,21 @@ -{ disks ? [ "/dev/vdb" "/dev/vdc" ], ... }: { +{ disko.devices = { disk = { disk0 = { - device = builtins.elemAt disks 0; + device = "/dev/disk/by-id/ata-disk0"; type = "disk"; content = { - type = "table"; - format = "gpt"; - partitions = [ - { - name = "nix"; - part-type = "primary"; - start = "0%"; - end = "-10MiB"; - bootable = true; + type = "gpt"; + partitions = { + nix = { + end = "-10M"; content = { type = "filesystem"; format = "ext4"; mountpoint = "/"; }; - } - ]; + }; + }; }; }; }; diff --git a/example/swap.nix b/example/swap.nix index 8d5d8d6..fdfbe6f 100644 --- a/example/swap.nix +++ b/example/swap.nix @@ -1,47 +1,37 @@ -{ disks ? [ "/dev/vdb" ], ... }: { +{ disko.devices = { disk = { vdb = { - device = builtins.elemAt disks 0; + device = "/dev/vdb"; type = "disk"; content = { - type = "table"; - format = "gpt"; - partitions = [ - { - name = "ESP"; - start = "1MiB"; - end = "100MiB"; - bootable = true; + type = "gpt"; + partitions = { + ESP = { + size = "100M"; content = { type = "filesystem"; format = "vfat"; mountpoint = "/boot"; }; - } - { - name = "root"; - start = "100MiB"; + }; + root = { end = "-1G"; - part-type = "primary"; content = { type = "filesystem"; format = "ext4"; mountpoint = "/"; }; - } - { - name = "swap"; - start = "-1G"; - end = "100%"; - part-type = "primary"; + }; + swap = { + size = "100%"; content = { type = "swap"; randomEncryption = true; resumeDevice = true; # resume from hiberation from this device }; - } - ]; + }; + }; }; }; }; diff --git a/example/tmpfs.nix b/example/tmpfs.nix index cc43115..afda544 100644 --- a/example/tmpfs.nix +++ b/example/tmpfs.nix @@ -1,37 +1,29 @@ -{ disks ? [ "/dev/vdb" ], ... }: { +{ disko.devices = { disk = { vdb = { - device = builtins.elemAt disks 0; + device = "/dev/vdb"; type = "disk"; content = { - type = "table"; - format = "gpt"; - partitions = [ - { - name = "ESP"; - start = "1MiB"; - end = "100MiB"; - bootable = true; + type = "gpt"; + partitions = { + ESP = { + size = "100M"; content = { type = "filesystem"; format = "vfat"; mountpoint = "/boot"; }; - } - { - name = "root"; - start = "100MiB"; - end = "100%"; - part-type = "primary"; - bootable = true; + }; + root = { + size = "100%"; content = { type = "filesystem"; format = "ext4"; mountpoint = "/"; }; - } - ]; + }; + }; }; }; }; diff --git a/example/with-lib.nix b/example/with-lib.nix index ed3c19d..5558fac 100644 --- a/example/with-lib.nix +++ b/example/with-lib.nix @@ -1,34 +1,26 @@ # Example to create a bios compatible gpt partition { disks ? [ "/dev/vdb" ], lib, ... }: { disko.devices = { - disk = lib.genAttrs [ (lib.head disks) ] (device: { + disk = lib.genAttrs disks (device: { + name = lib.replaceStrings [ "/" ] [ "_" ] device; device = device; type = "disk"; content = { - type = "table"; - format = "gpt"; - partitions = [ - { - name = "boot"; - start = "0"; - end = "1M"; - part-type = "primary"; - flags = [ "bios_grub" ]; - } - { - name = "root"; - # leave space for the grub aka BIOS boot - start = "1M"; - end = "100%"; - part-type = "primary"; - bootable = true; + type = "gpt"; + partitions = { + boot = { + size = "1M"; + type = "EF02"; + }; + root = { + size = "100%"; content = { type = "filesystem"; format = "ext4"; mountpoint = "/"; }; - } - ]; + }; + }; }; }); }; diff --git a/example/zfs-over-legacy.nix b/example/zfs-over-legacy.nix index 2a5a2c6..e91b1b7 100644 --- a/example/zfs-over-legacy.nix +++ b/example/zfs-over-legacy.nix @@ -1,18 +1,14 @@ -{ disks ? [ "/dev/vdb" "/dev/vdc" ], ... }: { +{ disko.devices = { disk = { vdb = { type = "disk"; - device = builtins.elemAt disks 0; + device = "/dev/vdb"; content = { - type = "table"; - format = "gpt"; - partitions = [ - { - name = "ESP"; - start = "1MiB"; - end = "100MiB"; - bootable = true; + type = "gpt"; + partitions = { + ESP = { + size = "100M"; content = { type = "filesystem"; format = "vfat"; @@ -21,24 +17,21 @@ "defaults" ]; }; - } - { - start = "100MiB"; - end = "100%"; - name = "primary"; - bootable = true; + }; + primary = { + size = "100%"; content = { type = "filesystem"; format = "ext4"; mountpoint = "/"; }; - } - ]; + }; + }; }; }; vdc = { type = "disk"; - device = builtins.elemAt disks 1; + device = "/dev/vdc"; content = { type = "zfs"; pool = "zroot"; diff --git a/example/zfs.nix b/example/zfs.nix index d1189f5..0d34667 100644 --- a/example/zfs.nix +++ b/example/zfs.nix @@ -1,54 +1,44 @@ -{ disks ? [ "/dev/vdb" "/dev/vdc" ], ... }: { +{ disko.devices = { disk = { x = { type = "disk"; - device = builtins.elemAt disks 0; + device = "/dev/sdx"; content = { - type = "table"; - format = "gpt"; - partitions = [ - { - name = "ESP"; - start = "0"; - end = "64MiB"; - fs-type = "fat32"; - bootable = true; + type = "gpt"; + partitions = { + ESP = { + size = "64M"; content = { type = "filesystem"; format = "vfat"; mountpoint = "/boot"; }; - } - { - name = "zfs"; - start = "128MiB"; - end = "100%"; + }; + zfs = { + size = "100%"; content = { type = "zfs"; pool = "zroot"; }; - } - ]; + }; + }; }; }; y = { type = "disk"; - device = builtins.elemAt disks 1; + device = "/dev/sdy"; content = { - type = "table"; - format = "gpt"; - partitions = [ - { - name = "zfs"; - start = "128MiB"; - end = "100%"; + type = "gpt"; + partitions = { + zfs = { + size = "100%"; content = { type = "zfs"; pool = "zroot"; }; - } - ]; + }; + }; }; }; }; diff --git a/lib/tests.nix b/lib/tests.nix index b6020a3..e029dbd 100644 --- a/lib/tests.nix +++ b/lib/tests.nix @@ -52,10 +52,15 @@ let }; devices = [ "/dev/vda" "/dev/vdb" "/dev/vdc" "/dev/vdd" "/dev/vde" "/dev/vdf"]; # for installation we skip /dev/vda because it is the test runner disk - testConfigInstall = testlib.prepareDiskoConfig (import disko-config { inherit lib; }) (lib.tail devices); + importedDiskoConfig = import disko-config; + diskoConfigWithArgs = if builtins.isFunction importedDiskoConfig then + importedDiskoConfig { inherit lib; } + else + importedDiskoConfig; + testConfigInstall = testlib.prepareDiskoConfig diskoConfigWithArgs (lib.tail devices); # we need to shift the disks by one because the first disk is the /dev/vda of the test runner # so /dev/vdb becomes /dev/vda etc. - testConfigBooted = testlib.prepareDiskoConfig (import disko-config { inherit lib; }) devices; + testConfigBooted = testlib.prepareDiskoConfig diskoConfigWithArgs devices; tsp-generator = pkgs.callPackage ../. { checked = true; }; tsp-create = (tsp-generator.createScript testConfigInstall) pkgs;