Skip to content

Commit 02e1f93

Browse files
committed
nixos/version: add extraOSReleaseArgs and extraLSBReleaseArgs
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]>
1 parent b4d7b9a commit 02e1f93

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

nixos/modules/misc/version.nix

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ let
4242
VARIANT = optionalString (cfg.variantName != null) cfg.variantName;
4343
VARIANT_ID = optionalString (cfg.variant_id != null) cfg.variant_id;
4444
DEFAULT_HOSTNAME = config.system.nixos.distroId;
45-
SUPPORT_END = "2025-06-30";
46-
};
45+
} // cfg.extraOSReleaseArgs;
4746

4847
initrdReleaseContents = (removeAttrs osReleaseContents [ "BUILD_ID" ]) // {
4948
PRETTY_NAME = "${osReleaseContents.PRETTY_NAME} (Initrd)";
@@ -143,6 +142,26 @@ in
143142
default = "NixOS";
144143
description = "The name of the operating system vendor";
145144
};
145+
146+
extraOSReleaseArgs = mkOption {
147+
internal = true;
148+
type = types.attrsOf types.str;
149+
default = { };
150+
description = "Additional attributes to be merged with the /etc/os-release generator.";
151+
example = {
152+
ANSI_COLOR = "1;31";
153+
};
154+
};
155+
156+
extraLSBReleaseArgs = mkOption {
157+
internal = true;
158+
type = types.attrsOf types.str;
159+
default = { };
160+
description = "Additional attributes to be merged with the /etc/lsb-release generator.";
161+
example = {
162+
LSB_VERSION = "1.0";
163+
};
164+
};
146165
};
147166

148167
image = {
@@ -237,13 +256,13 @@ in
237256
# https://www.freedesktop.org/software/systemd/man/os-release.html for the
238257
# format.
239258
environment.etc = {
240-
"lsb-release".text = attrsToText {
259+
"lsb-release".text = attrsToText ({
241260
LSB_VERSION = "${cfg.release} (${cfg.codeName})";
242261
DISTRIB_ID = "${cfg.distroId}";
243262
DISTRIB_RELEASE = cfg.release;
244263
DISTRIB_CODENAME = toLower cfg.codeName;
245264
DISTRIB_DESCRIPTION = "${cfg.distroName} ${cfg.release} (${cfg.codeName})";
246-
};
265+
} // cfg.extraLSBReleaseArgs);
247266

248267
"os-release".text = attrsToText osReleaseContents;
249268
};

0 commit comments

Comments
 (0)