Merge pull request #553 from nix-community/long_device_names

types gpt: hash long device names
This commit is contained in:
lassulus 2024-03-05 07:46:52 +07:00 committed by GitHub
commit c54e7e2b2b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 62 additions and 4 deletions

View File

@ -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 = "/";
};
};
};
};
};
};
};
}

View File

@ -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 <nixpkgs/nixos/tests/installer.nix>
def create_test_machine(oldmachine, args={}): # taken from <nixpkgs/nixos/tests/installer.nix>
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

View File

@ -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]?");

View File

@ -0,0 +1,11 @@
{ pkgs ? import <nixpkgs> { }
, diskoLib ? pkgs.callPackage ../lib { }
}:
diskoLib.testLib.makeDiskoTest {
inherit pkgs;
name = "long-device-name";
disko-config = ../example/long-device-name.nix;
extraTestScript = ''
machine.succeed("mountpoint /");
'';
}