Skip to content

Commit

Permalink
nixos/version: add extraOSReleaseArgs and extraLSBReleaseArgs
Browse files Browse the repository at this point in the history
A free-form `attrsOf str` option that is merged with the /etc/os-release
builder, allowing downstreams to customise arbitrary os-release fields.
This is separate from the variant option, as using an attribute set
merge means one gets an infinte recursion when making extraOSReleaseArgs
a recursive set, and the variant attribute is useful to define elsewhere
or multiple times.

Ditto for /etc/lsb-release.

Signed-off-by: Fernando Rodrigues <[email protected]>
  • Loading branch information
SigmaSquadron committed Nov 23, 2024
1 parent 0eae4ab commit 41617ab
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions nixos/modules/misc/version.nix
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ let
VARIANT = optionalString (cfg.variantName != null) cfg.variantName;
VARIANT_ID = optionalString (cfg.variant_id != null) cfg.variant_id;
DEFAULT_HOSTNAME = config.networking.fqdnOrHostName;
SUPPORT_END = "2025-06-30";
};
} // cfg.extraOSReleaseArgs;

initrdReleaseContents = (removeAttrs osReleaseContents [ "BUILD_ID" ]) // {
PRETTY_NAME = "${osReleaseContents.PRETTY_NAME} (Initrd)";
Expand Down Expand Up @@ -143,6 +142,26 @@ in
default = "NixOS";
description = "The name of the operating system vendor";
};

extraOSReleaseArgs = mkOption {
internal = true;
type = types.attrsOf types.str;
default = { };
description = "Additional attributes to be merged with the /etc/os-release generator.";
example = {
ANSI_COLOR = "1;31";
};
};

extraLSBReleaseArgs = mkOption {
internal = true;
type = types.attrsOf types.str;
default = { };
description = "Additional attributes to be merged with the /etc/lsb-release generator.";
example = {
LSB_VERSION = "1.0";
};
};
};

image = {
Expand Down Expand Up @@ -237,13 +256,13 @@ in
# https://www.freedesktop.org/software/systemd/man/os-release.html for the
# format.
environment.etc = {
"lsb-release".text = attrsToText {
"lsb-release".text = attrsToText ({
LSB_VERSION = "${cfg.release} (${cfg.codeName})";
DISTRIB_ID = "${cfg.distroId}";
DISTRIB_RELEASE = cfg.release;
DISTRIB_CODENAME = toLower cfg.codeName;
DISTRIB_DESCRIPTION = "${cfg.distroName} ${cfg.release} (${cfg.codeName})";
};
} // cfg.extraLSBReleaseArgs);

"os-release".text = attrsToText osReleaseContents;
};
Expand Down

0 comments on commit 41617ab

Please sign in to comment.