Merge pull request #302590 from nikstur/repart-image-label-length

nixos/image/repart: assert maximum label length

authored by nikstur and committed by GitHub 80cafa6a 9a7afcba

+46 -3
+5
nixos/lib/systemd-lib.nix
··· 525 525 )} 526 526 ''; 527 527 528 + # The maximum number of characters allowed in a GPT partition label. This 529 + # limit is specified by UEFI and enforced by systemd-repart. 530 + # Corresponds to GPT_LABEL_MAX from systemd's gpt.h. 531 + GPTMaxLabelLength = 36; 532 + 528 533 }
+38
nixos/modules/image/repart.nix
··· 6 6 let 7 7 cfg = config.image.repart; 8 8 9 + inherit (utils.systemdUtils.lib) GPTMaxLabelLength; 10 + 9 11 partitionOptions = { 10 12 options = { 11 13 storePaths = lib.mkOption { ··· 223 225 }; 224 226 225 227 config = { 228 + 229 + assertions = lib.mapAttrsToList (fileName: partitionConfig: 230 + let 231 + inherit (partitionConfig) repartConfig; 232 + labelLength = builtins.stringLength repartConfig.Label; 233 + in 234 + { 235 + assertion = repartConfig ? Label -> GPTMaxLabelLength >= labelLength; 236 + message = '' 237 + The partition label '${repartConfig.Label}' 238 + defined for '${fileName}' is ${toString labelLength} characters long, 239 + but the maximum label length supported by UEFI is ${toString 240 + GPTMaxLabelLength}. 241 + ''; 242 + } 243 + ) cfg.partitions; 244 + 245 + warnings = lib.filter (v: v != null) (lib.mapAttrsToList (fileName: partitionConfig: 246 + let 247 + inherit (partitionConfig) repartConfig; 248 + suggestedMaxLabelLength = GPTMaxLabelLength - 2; 249 + labelLength = builtins.stringLength repartConfig.Label; 250 + in 251 + if (repartConfig ? Label && labelLength >= suggestedMaxLabelLength) then '' 252 + The partition label '${repartConfig.Label}' 253 + defined for '${fileName}' is ${toString labelLength} characters long. 254 + The suggested maximum label length is ${toString 255 + suggestedMaxLabelLength}. 256 + 257 + If you use sytemd-sysupdate style A/B updates, this might 258 + not leave enough space to increment the version number included in 259 + the label in a future release. For example, if your label is 260 + ${toString GPTMaxLabelLength} characters long (the maximum enforced by UEFI) and 261 + you're at version 9, you cannot increment this to 10. 262 + '' else null 263 + ) cfg.partitions); 226 264 227 265 image.repart = 228 266 let
+3 -3
nixos/modules/system/boot/systemd/repart.nix
··· 13 13 14 14 partitionAssertions = lib.mapAttrsToList (fileName: definition: 15 15 let 16 - maxLabelLength = 36; # GPT_LABEL_MAX defined in systemd's gpt.h 16 + inherit (utils.systemdUtils.lib) GPTMaxLabelLength; 17 17 labelLength = builtins.stringLength definition.Label; 18 18 in 19 19 { 20 - assertion = definition ? Label -> maxLabelLength >= labelLength; 20 + assertion = definition ? Label -> GPTMaxLabelLength >= labelLength; 21 21 message = '' 22 22 The partition label '${definition.Label}' defined for '${fileName}' is ${toString labelLength} 23 - characters long, but the maximum label length supported by systemd is ${toString maxLabelLength}. 23 + characters long, but the maximum label length supported by systemd is ${toString GPTMaxLabelLength}. 24 24 ''; 25 25 } 26 26 ) cfg.partitions;