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,17 +5,21 @@ 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 =
let
isNixos = cfg.distroId == "nixos";
in
{
NAME = "${cfg.distroName}"; NAME = "${cfg.distroName}";
ID = "${cfg.distroId}"; ID = "${cfg.distroId}";
VERSION = "${cfg.release} (${cfg.codeName})"; VERSION = "${cfg.release} (${cfg.codeName})";
@ -24,12 +28,13 @@ let
BUILD_ID = cfg.version; BUILD_ID = cfg.version;
PRETTY_NAME = "${cfg.distroName} ${cfg.release} (${cfg.codeName})"; PRETTY_NAME = "${cfg.distroName} ${cfg.release} (${cfg.codeName})";
LOGO = "nix-snowflake"; LOGO = "nix-snowflake";
HOME_URL = lib.optionalString (cfg.distroId == "nixos") "https://nixos.org/"; HOME_URL = optionalString isNixos "https://nixos.org/";
DOCUMENTATION_URL = lib.optionalString (cfg.distroId == "nixos") "https://nixos.org/learn.html"; DOCUMENTATION_URL = optionalString isNixos "https://nixos.org/learn.html";
SUPPORT_URL = lib.optionalString (cfg.distroId == "nixos") "https://nixos.org/community.html"; SUPPORT_URL = optionalString isNixos "https://nixos.org/community.html";
BUG_REPORT_URL = lib.optionalString (cfg.distroId == "nixos") "https://github.com/NixOS/nixpkgs/issues"; BUG_REPORT_URL = optionalString isNixos "https://github.com/NixOS/nixpkgs/issues";
IMAGE_ID = lib.optionalString (config.system.image.id != null) config.system.image.id; ANSI_COLOR = optionalString isNixos "1;34";
IMAGE_VERSION = lib.optionalString (config.system.image.version != null) config.system.image.version; 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) { } // lib.optionalAttrs (cfg.variant_id != null) {
VARIANT_ID = cfg.variant_id; VARIANT_ID = cfg.variant_id;
}; };
@ -56,61 +61,62 @@ in
}; };
options.system = { options.system = {
nixos = {
nixos.version = mkOption { version = mkOption {
internal = true; internal = true;
type = types.str; type = types.str;
description = lib.mdDoc "The full NixOS version (e.g. `16.03.1160.f2d4ee1`)."; description = lib.mdDoc "The full NixOS version (e.g. `16.03.1160.f2d4ee1`).";
}; };
nixos.release = mkOption { release = mkOption {
readOnly = true; readOnly = true;
type = types.str; type = types.str;
default = trivial.release; default = trivial.release;
description = lib.mdDoc "The NixOS release (e.g. `16.03`)."; description = lib.mdDoc "The NixOS release (e.g. `16.03`).";
}; };
nixos.versionSuffix = mkOption { versionSuffix = mkOption {
internal = true; internal = true;
type = types.str; type = types.str;
default = trivial.versionSuffix; default = trivial.versionSuffix;
description = lib.mdDoc "The NixOS version suffix (e.g. `1160.f2d4ee1`)."; description = lib.mdDoc "The NixOS version suffix (e.g. `1160.f2d4ee1`).";
}; };
nixos.revision = mkOption { revision = mkOption {
internal = true; internal = true;
type = types.nullOr types.str; type = types.nullOr types.str;
default = trivial.revisionWithDefault null; default = trivial.revisionWithDefault null;
description = lib.mdDoc "The Git revision from which this NixOS configuration was built."; description = lib.mdDoc "The Git revision from which this NixOS configuration was built.";
}; };
nixos.codeName = mkOption { codeName = mkOption {
readOnly = true; readOnly = true;
type = types.str; type = types.str;
default = trivial.codeName; default = trivial.codeName;
description = lib.mdDoc "The NixOS release code name (e.g. `Emu`)."; description = lib.mdDoc "The NixOS release code name (e.g. `Emu`).";
}; };
nixos.distroId = mkOption { distroId = 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 id of the operating system";
}; };
nixos.distroName = mkOption { distroName = mkOption {
internal = true; internal = true;
type = types.str; type = types.str;
default = "NixOS"; default = "NixOS";
description = lib.mdDoc "The name of the operating system"; description = lib.mdDoc "The name of the operating system";
}; };
nixos.variant_id = mkOption { variant_id = mkOption {
type = types.nullOr (types.strMatching "^[a-z0-9._-]+$"); type = types.nullOr (types.strMatching "^[a-z0-9._-]+$");
default = null; default = null;
description = lib.mdDoc "A lower-case string identifying a specific variant or edition of the operating system"; description = lib.mdDoc "A lower-case string identifying a specific variant or edition of the operating system";
example = "installer"; example = "installer";
}; };
};
image = { image = {