mirror of
https://github.com/nix-community/disko.git
synced 2024-09-17 09:37:17 +03:00
Merge pull request #553 from nix-community/long_device_names
types gpt: hash long device names
This commit is contained in:
commit
c54e7e2b2b
34
example/long-device-name.nix
Normal file
34
example/long-device-name.nix
Normal 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 = "/";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
@ -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' -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}'
|
disk_flags += f' -device virtio-blk-pci,drive=drive{i + 1}'
|
||||||
return disk_flags
|
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({
|
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}),
|
"startCommand": startCommand,
|
||||||
${lib.optionalString efi ''"bios": "${pkgs.OVMF.fd}/FV/OVMF.fd",''}
|
|
||||||
} | args)
|
} | args)
|
||||||
driver.machines.append(machine)
|
driver.machines.append(machine)
|
||||||
return machine
|
return machine
|
||||||
|
@ -55,7 +55,15 @@ in
|
|||||||
};
|
};
|
||||||
label = lib.mkOption {
|
label = lib.mkOption {
|
||||||
type = lib.types.str;
|
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 {
|
size = lib.mkOption {
|
||||||
type = lib.types.either (lib.types.enum [ "100%" ]) (lib.types.strMatching "[0-9]+[KMGTP]?");
|
type = lib.types.either (lib.types.enum [ "100%" ]) (lib.types.strMatching "[0-9]+[KMGTP]?");
|
||||||
|
11
tests/long-device-name.nix
Normal file
11
tests/long-device-name.nix
Normal 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 /");
|
||||||
|
'';
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user