From 3cb3775f9b474502847f170f029d3ea50eb3cf40 Mon Sep 17 00:00:00 2001 From: lassulus Date: Mon, 4 Mar 2024 01:40:58 +0100 Subject: [PATCH 1/3] lib/tests: use startCommand for create_machine --- lib/tests.nix | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/tests.nix b/lib/tests.nix index b2d0ddf..b4afa12 100644 --- a/lib/tests.nix +++ b/lib/tests.nix @@ -223,10 +223,15 @@ let disk_flags += f' -drive file={oldmachine.state_dir}/empty{i}.qcow2,id=drive{i + 1},if=none,index={i + 1},werror=report' disk_flags += f' -device virtio-blk-pci,drive=drive{i + 1}' return disk_flags - def create_test_machine(oldmachine=None, args={}): # taken from + def create_test_machine(oldmachine, args={}): # taken from + startCommand = "${pkgs.qemu_test}/bin/qemu-kvm" + startCommand += " -cpu max -m 1024 -virtfs local,path=/nix/store,security_model=none,mount_tag=nix-store" + startCommand += disks(oldmachine, ${toString num-disks}) + ${lib.optionalString efi '' + startCommand +=" -drive if=pflash,format=raw,unit=0,readonly=on,file=${pkgs.OVMF.firmware} -drive if=pflash,format=raw,unit=1,readonly=on,file=${pkgs.OVMF.variables}" + ''} machine = create_machine({ - "qemuFlags": "-cpu max -m 1024 -virtfs local,path=/nix/store,security_model=none,mount_tag=nix-store" + disks(oldmachine, ${toString num-disks}), - ${lib.optionalString efi ''"bios": "${pkgs.OVMF.fd}/FV/OVMF.fd",''} + "startCommand": startCommand, } | args) driver.machines.append(machine) return machine From 56f6d3d4af2c61c050a4f940c37a6f6f30f51553 Mon Sep 17 00:00:00 2001 From: lassulus Date: Mon, 4 Mar 2024 01:50:21 +0100 Subject: [PATCH 2/3] types gpt: hash label if it's > 36 characters --- lib/types/gpt.nix | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/types/gpt.nix b/lib/types/gpt.nix index 1b47020..5a70f07 100644 --- a/lib/types/gpt.nix +++ b/lib/types/gpt.nix @@ -55,7 +55,15 @@ in }; label = lib.mkOption { type = lib.types.str; - default = "${config._parent.type}-${config._parent.name}-${partition.config.name}"; + default = let + # 72 bytes is the maximum length of a GPT partition name + # the labels seem to be in UTF-16, so 2 bytes per character + limit = 36; + label = "${config._parent.type}-${config._parent.name}-${partition.config.name}"; + in if (lib.stringLength label) > limit then + builtins.substring 0 limit (builtins.hashString "sha256" label) + else + label; }; size = lib.mkOption { type = lib.types.either (lib.types.enum [ "100%" ]) (lib.types.strMatching "[0-9]+[KMGTP]?"); From 561579a63140c0ffb3c5227b2404b3366e0122ab Mon Sep 17 00:00:00 2001 From: lassulus Date: Mon, 4 Mar 2024 01:51:38 +0100 Subject: [PATCH 3/3] add long-device-name test & example --- example/long-device-name.nix | 34 ++++++++++++++++++++++++++++++++++ tests/long-device-name.nix | 11 +++++++++++ 2 files changed, 45 insertions(+) create mode 100644 example/long-device-name.nix create mode 100644 tests/long-device-name.nix diff --git a/example/long-device-name.nix b/example/long-device-name.nix new file mode 100644 index 0000000..158d683 --- /dev/null +++ b/example/long-device-name.nix @@ -0,0 +1,34 @@ +{ + disko.devices = { + disk = { + vdb = { + device = "/dev/disk/by-id/some-disk-id"; + name = "this-is-some-super-long-name-to-test-what-happens-when-the-name-is-too-long"; + type = "disk"; + content = { + type = "gpt"; + partitions = { + ESP = { + type = "EF00"; + size = "500M"; + content = { + type = "filesystem"; + format = "vfat"; + mountpoint = "/boot"; + }; + }; + root = { + size = "100%"; + content = { + type = "filesystem"; + format = "ext4"; + mountpoint = "/"; + }; + }; + }; + }; + }; + }; + }; +} + diff --git a/tests/long-device-name.nix b/tests/long-device-name.nix new file mode 100644 index 0000000..e328a9f --- /dev/null +++ b/tests/long-device-name.nix @@ -0,0 +1,11 @@ +{ pkgs ? import { } +, diskoLib ? pkgs.callPackage ../lib { } +}: +diskoLib.testLib.makeDiskoTest { + inherit pkgs; + name = "long-device-name"; + disko-config = ../example/long-device-name.nix; + extraTestScript = '' + machine.succeed("mountpoint /"); + ''; +}