about summary refs log tree commit diff
path: root/nixos/modules/system
diff options
context:
space:
mode:
authorWill Fancher <elvishjerricco@gmail.com>2024-02-27 20:37:02 -0500
committerGitHub <noreply@github.com>2024-02-27 20:37:02 -0500
commitb9fe04d671880b1b69336e255c3d4ca05f9e4caa (patch)
treeb90d2726becb020bd4d3ac3f570562f934029f21 /nixos/modules/system
parenta587a6a35772f2b1692e87333c9d94ad477a4fd0 (diff)
parent4d59ace14f96db0b45fc3bef1d9b9e91325b0a2c (diff)
Merge pull request #291825 from WilliButz/repart/max-label-length
nixos/systemd-repart: add assertion for partition label length
Diffstat (limited to 'nixos/modules/system')
-rw-r--r--nixos/modules/system/boot/systemd/repart.nix16
1 files changed, 15 insertions, 1 deletions
diff --git a/nixos/modules/system/boot/systemd/repart.nix b/nixos/modules/system/boot/systemd/repart.nix
index 3be744acd0b3b..6cc387cb6f43f 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";