nixos/image/repart: assert maximum label length
The maximum label length is specified by UEFI and enforced/asserted by systemd-repart. This lets evaluation fail already and give the user some more information about what's wrong. Also warn when the suggested label length is exceeded. This serves as a safety mechanism for using systemd-sysupdate style A/B updates where the version number is encoded in the label and might not be incrementable when the maximum label size is reached.
This commit is contained in:
parent
4c397ea6de
commit
ad19cee09c
1 changed files with 38 additions and 0 deletions
|
@ -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;
|
||||||
|
|
Loading…
Reference in a new issue