Merge pull request #302590 from nikstur/repart-image-label-length
nixos/image/repart: assert maximum label length
This commit is contained in:
commit
80cafa6a29
|
@ -525,4 +525,9 @@ in rec {
|
||||||
)}
|
)}
|
||||||
'';
|
'';
|
||||||
|
|
||||||
|
# The maximum number of characters allowed in a GPT partition label. This
|
||||||
|
# limit is specified by UEFI and enforced by systemd-repart.
|
||||||
|
# Corresponds to GPT_LABEL_MAX from systemd's gpt.h.
|
||||||
|
GPTMaxLabelLength = 36;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,8 @@
|
||||||
let
|
let
|
||||||
cfg = config.image.repart;
|
cfg = config.image.repart;
|
||||||
|
|
||||||
|
inherit (utils.systemdUtils.lib) GPTMaxLabelLength;
|
||||||
|
|
||||||
partitionOptions = {
|
partitionOptions = {
|
||||||
options = {
|
options = {
|
||||||
storePaths = lib.mkOption {
|
storePaths = lib.mkOption {
|
||||||
|
@ -224,6 +226,42 @@ in
|
||||||
|
|
||||||
config = {
|
config = {
|
||||||
|
|
||||||
|
assertions = lib.mapAttrsToList (fileName: partitionConfig:
|
||||||
|
let
|
||||||
|
inherit (partitionConfig) repartConfig;
|
||||||
|
labelLength = builtins.stringLength repartConfig.Label;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
assertion = repartConfig ? Label -> GPTMaxLabelLength >= labelLength;
|
||||||
|
message = ''
|
||||||
|
The partition label '${repartConfig.Label}'
|
||||||
|
defined for '${fileName}' is ${toString labelLength} characters long,
|
||||||
|
but the maximum label length supported by UEFI is ${toString
|
||||||
|
GPTMaxLabelLength}.
|
||||||
|
'';
|
||||||
|
}
|
||||||
|
) cfg.partitions;
|
||||||
|
|
||||||
|
warnings = lib.filter (v: v != null) (lib.mapAttrsToList (fileName: partitionConfig:
|
||||||
|
let
|
||||||
|
inherit (partitionConfig) repartConfig;
|
||||||
|
suggestedMaxLabelLength = GPTMaxLabelLength - 2;
|
||||||
|
labelLength = builtins.stringLength repartConfig.Label;
|
||||||
|
in
|
||||||
|
if (repartConfig ? Label && labelLength >= suggestedMaxLabelLength) then ''
|
||||||
|
The partition label '${repartConfig.Label}'
|
||||||
|
defined for '${fileName}' is ${toString labelLength} characters long.
|
||||||
|
The suggested maximum label length is ${toString
|
||||||
|
suggestedMaxLabelLength}.
|
||||||
|
|
||||||
|
If you use sytemd-sysupdate style A/B updates, this might
|
||||||
|
not leave enough space to increment the version number included in
|
||||||
|
the label in a future release. For example, if your label is
|
||||||
|
${toString GPTMaxLabelLength} characters long (the maximum enforced by UEFI) and
|
||||||
|
you're at version 9, you cannot increment this to 10.
|
||||||
|
'' else null
|
||||||
|
) cfg.partitions);
|
||||||
|
|
||||||
image.repart =
|
image.repart =
|
||||||
let
|
let
|
||||||
version = config.image.repart.version;
|
version = config.image.repart.version;
|
||||||
|
|
|
@ -13,14 +13,14 @@ let
|
||||||
|
|
||||||
partitionAssertions = lib.mapAttrsToList (fileName: definition:
|
partitionAssertions = lib.mapAttrsToList (fileName: definition:
|
||||||
let
|
let
|
||||||
maxLabelLength = 36; # GPT_LABEL_MAX defined in systemd's gpt.h
|
inherit (utils.systemdUtils.lib) GPTMaxLabelLength;
|
||||||
labelLength = builtins.stringLength definition.Label;
|
labelLength = builtins.stringLength definition.Label;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
assertion = definition ? Label -> maxLabelLength >= labelLength;
|
assertion = definition ? Label -> GPTMaxLabelLength >= labelLength;
|
||||||
message = ''
|
message = ''
|
||||||
The partition label '${definition.Label}' defined for '${fileName}' is ${toString labelLength}
|
The partition label '${definition.Label}' defined for '${fileName}' is ${toString labelLength}
|
||||||
characters long, but the maximum label length supported by systemd is ${toString maxLabelLength}.
|
characters long, but the maximum label length supported by systemd is ${toString GPTMaxLabelLength}.
|
||||||
'';
|
'';
|
||||||
}
|
}
|
||||||
) cfg.partitions;
|
) cfg.partitions;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user