From 4d59ace14f96db0b45fc3bef1d9b9e91325b0a2c Mon Sep 17 00:00:00 2001 From: WilliButz Date: Tue, 27 Feb 2024 13:29:23 +0100 Subject: [PATCH] nixos/systemd-repart: add assertion for partition label length The maximum length for a GPT label supported by systemd is 36 characters. When a repart definition contains a label that is longer than the supported maximum length, it is ignored by systemd-repart and a log message is produced. The new assertion makes this obvious to the user at evaluation time, allowing them to either drop the property entirely or choose a supported label within the length limit instead. --- nixos/modules/system/boot/systemd/repart.nix | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/nixos/modules/system/boot/systemd/repart.nix b/nixos/modules/system/boot/systemd/repart.nix index 3be744acd0b3..6cc387cb6f43 100644 --- a/nixos/modules/system/boot/systemd/repart.nix +++ b/nixos/modules/system/boot/systemd/repart.nix @@ -10,6 +10,20 @@ let "repart.d" format (lib.mapAttrs (_n: v: { Partition = v; }) cfg.partitions); + + partitionAssertions = lib.mapAttrsToList (fileName: definition: + let + maxLabelLength = 36; # GPT_LABEL_MAX defined in systemd's gpt.h + labelLength = builtins.stringLength definition.Label; + in + { + assertion = definition ? Label -> maxLabelLength >= labelLength; + message = '' + The partition label '${definition.Label}' defined for '${fileName}' is ${toString labelLength} + characters long, but the maximum label length supported by systemd is ${toString maxLabelLength}. + ''; + } + ) cfg.partitions; in { options = { @@ -81,7 +95,7 @@ in 'boot.initrd.systemd.repart.enable' requires 'boot.initrd.systemd.enable' to be enabled. ''; } - ]; + ] ++ partitionAssertions; # systemd-repart uses loopback devices for partition creation boot.initrd.availableKernelModules = lib.optional initrdCfg.enable "loop";