From 89b617b99ddc1abd6b4225229a11565d42713601 Mon Sep 17 00:00:00 2001 From: lassulus Date: Sun, 7 Apr 2024 12:47:17 +0200 Subject: [PATCH 1/2] idempotent gpt --- lib/types/gpt.nix | 68 ++++++++++++++++++++++++----------------------- 1 file changed, 35 insertions(+), 33 deletions(-) diff --git a/lib/types/gpt.nix b/lib/types/gpt.nix index c5ec107..58a95b8 100644 --- a/lib/types/gpt.nix +++ b/lib/types/gpt.nix @@ -153,40 +153,42 @@ in _create = diskoLib.mkCreateOption { inherit config options; default = '' - if ! blkid "${config.device}" >/dev/null; then - ${lib.concatStrings (map (partition: '' - if sgdisk \ - --info=${toString partition._index} \ - ${config.device} > /dev/null 2>&1 - then - sgdisk \ - --align-end \ - --new=${toString partition._index}:${partition.start}:${partition.end} \ - --change-name=${toString partition._index}:${partition.label} \ - --typecode=${toString partition._index}:${partition.type} \ - ${config.device} - # ensure /dev/disk/by-path/..-partN exists before continuing - partprobe ${config.device} - udevadm trigger --subsystem-match=block - udevadm settle - fi - '') sortedPartitions)} - - ${ - lib.optionalString (sortedHybridPartitions != []) - ("sgdisk -h " - + (lib.concatStringsSep ":" (map (p: (toString p._index)) sortedHybridPartitions)) - + ( - lib.optionalString (!config.efiGptPartitionFirst) ":EE " - ) - + parent.device) - } - ${lib.concatMapStrings (p: - p.hybrid._create - ) - sortedHybridPartitions - } + if ! blkid "${config.device}" >&2; then + sgdisk --clear ${config.device} fi + ${lib.concatStrings (map (partition: '' + # try to create the partition, if it fails, try to change the type and name + if ! sgdisk \ + --align-end \ + --new=${toString partition._index}:${partition.start}:${partition.end} \ + --change-name=${toString partition._index}:${partition.label} \ + --typecode=${toString partition._index}:${partition.type} \ + ${config.device} + then sgdisk \ + --change-name=${toString partition._index}:${partition.label} \ + --typecode=${toString partition._index}:${partition.type} \ + ${config.device} + fi + # ensure /dev/disk/by-path/..-partN exists before continuing + partprobe ${config.device} || : # sometimes partprobe fails, but the partitions are still up2date + udevadm trigger --subsystem-match=block + udevadm settle + '') sortedPartitions)} + + ${ + lib.optionalString (sortedHybridPartitions != []) + ("sgdisk -h " + + (lib.concatStringsSep ":" (map (p: (toString p._index)) sortedHybridPartitions)) + + ( + lib.optionalString (!config.efiGptPartitionFirst) ":EE " + ) + + parent.device) + } + ${lib.concatMapStrings (p: + p.hybrid._create + ) + sortedHybridPartitions + } ${lib.concatStrings (map (partition: '' ${lib.optionalString (partition.content != null) partition.content._create} From e18e85ba3f8a6aec60a5b1f8a6cc9fac2ebd1406 Mon Sep 17 00:00:00 2001 From: lassulus Date: Mon, 8 Apr 2024 18:40:31 +0200 Subject: [PATCH 2/2] tests/make-disk-image: increase memSize --- tests/make-disk-image.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/make-disk-image.nix b/tests/make-disk-image.nix index 15c1fc4..02d3ead 100644 --- a/tests/make-disk-image.nix +++ b/tests/make-disk-image.nix @@ -8,6 +8,7 @@ diskoLib.makeDiskImages { ({ config, ... }: { documentation.enable = false; system.stateVersion = config.system.nixos.version; + disko.memSize = 2048; }) ]; }