Merge pull request #595 from nix-community/idempotent_gpt

idempotent gpt
This commit is contained in:
lassulus 2024-04-08 23:30:56 +02:00 committed by GitHub
commit 9e0bf2fe7f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 36 additions and 33 deletions

View File

@ -153,23 +153,26 @@ in
_create = diskoLib.mkCreateOption { _create = diskoLib.mkCreateOption {
inherit config options; inherit config options;
default = '' default = ''
if ! blkid "${config.device}" >/dev/null; then if ! blkid "${config.device}" >&2; then
sgdisk --clear ${config.device}
fi
${lib.concatStrings (map (partition: '' ${lib.concatStrings (map (partition: ''
if sgdisk \ # try to create the partition, if it fails, try to change the type and name
--info=${toString partition._index} \ if ! sgdisk \
${config.device} > /dev/null 2>&1
then
sgdisk \
--align-end \ --align-end \
--new=${toString partition._index}:${partition.start}:${partition.end} \ --new=${toString partition._index}:${partition.start}:${partition.end} \
--change-name=${toString partition._index}:${partition.label} \ --change-name=${toString partition._index}:${partition.label} \
--typecode=${toString partition._index}:${partition.type} \ --typecode=${toString partition._index}:${partition.type} \
${config.device} ${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 # ensure /dev/disk/by-path/..-partN exists before continuing
partprobe ${config.device} partprobe ${config.device} || : # sometimes partprobe fails, but the partitions are still up2date
udevadm trigger --subsystem-match=block udevadm trigger --subsystem-match=block
udevadm settle udevadm settle
fi
'') sortedPartitions)} '') sortedPartitions)}
${ ${
@ -186,7 +189,6 @@ in
) )
sortedHybridPartitions sortedHybridPartitions
} }
fi
${lib.concatStrings (map (partition: '' ${lib.concatStrings (map (partition: ''
${lib.optionalString (partition.content != null) partition.content._create} ${lib.optionalString (partition.content != null) partition.content._create}

View File

@ -8,6 +8,7 @@ diskoLib.makeDiskImages {
({ config, ... }: { ({ config, ... }: {
documentation.enable = false; documentation.enable = false;
system.stateVersion = config.system.nixos.version; system.stateVersion = config.system.nixos.version;
disko.memSize = 2048;
}) })
]; ];
} }