0
0
Fork 0
mirror of https://github.com/NixOS/nixpkgs.git synced 2025-07-13 21:50:33 +03:00

nixos/version: add ANSI_COLOR

This commit is contained in:
Peter Hoeg 2024-01-21 09:12:17 +01:00
parent 0e69c429b0
commit 9a113b42b3

View file

@ -5,34 +5,39 @@ let
opt = options.system.nixos; opt = options.system.nixos;
inherit (lib) inherit (lib)
concatStringsSep mapAttrsToList toLower concatStringsSep mapAttrsToList toLower optionalString
literalExpression mkRenamedOptionModule mkDefault mkOption trivial types; literalExpression mkRenamedOptionModule mkDefault mkOption trivial types;
needsEscaping = s: null != builtins.match "[a-zA-Z0-9]+" s; needsEscaping = s: null != builtins.match "[a-zA-Z0-9]+" s;
escapeIfNecessary = s: if needsEscaping s then s else ''"${lib.escape [ "\$" "\"" "\\" "\`" ] s}"''; escapeIfNecessary = s: if needsEscaping s then s else ''"${lib.escape [ "\$" "\"" "\\" "\`" ] s}"'';
attrsToText = attrs: attrsToText = attrs:
concatStringsSep "\n" ( concatStringsSep "\n"
mapAttrsToList (n: v: ''${n}=${escapeIfNecessary (toString v)}'') attrs (mapAttrsToList (n: v: ''${n}=${escapeIfNecessary (toString v)}'') attrs)
) + "\n"; + "\n";
osReleaseContents = { osReleaseContents =
NAME = "${cfg.distroName}"; let
ID = "${cfg.distroId}"; isNixos = cfg.distroId == "nixos";
VERSION = "${cfg.release} (${cfg.codeName})"; in
VERSION_CODENAME = toLower cfg.codeName; {
VERSION_ID = cfg.release; NAME = "${cfg.distroName}";
BUILD_ID = cfg.version; ID = "${cfg.distroId}";
PRETTY_NAME = "${cfg.distroName} ${cfg.release} (${cfg.codeName})"; VERSION = "${cfg.release} (${cfg.codeName})";
LOGO = "nix-snowflake"; VERSION_CODENAME = toLower cfg.codeName;
HOME_URL = lib.optionalString (cfg.distroId == "nixos") "https://nixos.org/"; VERSION_ID = cfg.release;
DOCUMENTATION_URL = lib.optionalString (cfg.distroId == "nixos") "https://nixos.org/learn.html"; BUILD_ID = cfg.version;
SUPPORT_URL = lib.optionalString (cfg.distroId == "nixos") "https://nixos.org/community.html"; PRETTY_NAME = "${cfg.distroName} ${cfg.release} (${cfg.codeName})";
BUG_REPORT_URL = lib.optionalString (cfg.distroId == "nixos") "https://github.com/NixOS/nixpkgs/issues"; LOGO = "nix-snowflake";
IMAGE_ID = lib.optionalString (config.system.image.id != null) config.system.image.id; HOME_URL = optionalString isNixos "https://nixos.org/";
IMAGE_VERSION = lib.optionalString (config.system.image.version != null) config.system.image.version; DOCUMENTATION_URL = optionalString isNixos "https://nixos.org/learn.html";
} // lib.optionalAttrs (cfg.variant_id != null) { SUPPORT_URL = optionalString isNixos "https://nixos.org/community.html";
VARIANT_ID = cfg.variant_id; BUG_REPORT_URL = optionalString isNixos "https://github.com/NixOS/nixpkgs/issues";
}; ANSI_COLOR = optionalString isNixos "1;34";
IMAGE_ID = optionalString (config.system.image.id != null) config.system.image.id;
IMAGE_VERSION = optionalString (config.system.image.version != null) config.system.image.version;
} // lib.optionalAttrs (cfg.variant_id != null) {
VARIANT_ID = cfg.variant_id;
};
initrdReleaseContents = (removeAttrs osReleaseContents [ "BUILD_ID" ]) // { initrdReleaseContents = (removeAttrs osReleaseContents [ "BUILD_ID" ]) // {
PRETTY_NAME = "${osReleaseContents.PRETTY_NAME} (Initrd)"; PRETTY_NAME = "${osReleaseContents.PRETTY_NAME} (Initrd)";
@ -56,60 +61,61 @@ in
}; };
options.system = { options.system = {
nixos = {
version = mkOption {
internal = true;
type = types.str;
description = lib.mdDoc "The full NixOS version (e.g. `16.03.1160.f2d4ee1`).";
};
nixos.version = mkOption { release = mkOption {
internal = true; readOnly = true;
type = types.str; type = types.str;
description = lib.mdDoc "The full NixOS version (e.g. `16.03.1160.f2d4ee1`)."; default = trivial.release;
}; description = lib.mdDoc "The NixOS release (e.g. `16.03`).";
};
nixos.release = mkOption { versionSuffix = mkOption {
readOnly = true; internal = true;
type = types.str; type = types.str;
default = trivial.release; default = trivial.versionSuffix;
description = lib.mdDoc "The NixOS release (e.g. `16.03`)."; description = lib.mdDoc "The NixOS version suffix (e.g. `1160.f2d4ee1`).";
}; };
nixos.versionSuffix = mkOption { revision = mkOption {
internal = true; internal = true;
type = types.str; type = types.nullOr types.str;
default = trivial.versionSuffix; default = trivial.revisionWithDefault null;
description = lib.mdDoc "The NixOS version suffix (e.g. `1160.f2d4ee1`)."; description = lib.mdDoc "The Git revision from which this NixOS configuration was built.";
}; };
nixos.revision = mkOption { codeName = mkOption {
internal = true; readOnly = true;
type = types.nullOr types.str; type = types.str;
default = trivial.revisionWithDefault null; default = trivial.codeName;
description = lib.mdDoc "The Git revision from which this NixOS configuration was built."; description = lib.mdDoc "The NixOS release code name (e.g. `Emu`).";
}; };
nixos.codeName = mkOption { distroId = mkOption {
readOnly = true; internal = true;
type = types.str; type = types.str;
default = trivial.codeName; default = "nixos";
description = lib.mdDoc "The NixOS release code name (e.g. `Emu`)."; description = lib.mdDoc "The id of the operating system";
}; };
nixos.distroId = mkOption { distroName = mkOption {
internal = true; internal = true;
type = types.str; type = types.str;
default = "nixos"; default = "NixOS";
description = lib.mdDoc "The id of the operating system"; description = lib.mdDoc "The name of the operating system";
}; };
nixos.distroName = mkOption { variant_id = mkOption {
internal = true; type = types.nullOr (types.strMatching "^[a-z0-9._-]+$");
type = types.str; default = null;
default = "NixOS"; description = lib.mdDoc "A lower-case string identifying a specific variant or edition of the operating system";
description = lib.mdDoc "The name of the operating system"; example = "installer";
}; };
nixos.variant_id = mkOption {
type = types.nullOr (types.strMatching "^[a-z0-9._-]+$");
default = null;
description = lib.mdDoc "A lower-case string identifying a specific variant or edition of the operating system";
example = "installer";
}; };
image = { image = {