1 { config, lib, options, pkgs, ... }:
4 cfg = config.system.nixos;
5 opt = options.system.nixos;
8 concatStringsSep mapAttrsToList toLower
9 literalExpression mkRenamedOptionModule mkDefault mkOption trivial types;
11 needsEscaping = s: null != builtins.match "[a-zA-Z0-9]+" s;
12 escapeIfNecessary = s: if needsEscaping s then s else ''"${lib.escape [ "\$" "\"" "\\" "\`" ] s}"'';
14 concatStringsSep "\n" (
15 mapAttrsToList (n: v: ''${n}=${escapeIfNecessary (toString v)}'') attrs
19 NAME = "${cfg.distroName}";
20 ID = "${cfg.distroId}";
21 VERSION = "${cfg.release} (${cfg.codeName})";
22 VERSION_CODENAME = toLower cfg.codeName;
23 VERSION_ID = cfg.release;
24 BUILD_ID = cfg.version;
25 PRETTY_NAME = "${cfg.distroName} ${cfg.release} (${cfg.codeName})";
26 LOGO = "nix-snowflake";
27 HOME_URL = lib.optionalString (cfg.distroId == "nixos") "https://nixos.org/";
28 DOCUMENTATION_URL = lib.optionalString (cfg.distroId == "nixos") "https://nixos.org/learn.html";
29 SUPPORT_URL = lib.optionalString (cfg.distroId == "nixos") "https://nixos.org/community.html";
30 SUPPORT_END = "2024-06-30";
31 BUG_REPORT_URL = lib.optionalString (cfg.distroId == "nixos") "https://github.com/NixOS/nixpkgs/issues";
32 } // lib.optionalAttrs (cfg.variant_id != null) {
33 VARIANT_ID = cfg.variant_id;
36 initrdReleaseContents = (removeAttrs osReleaseContents [ "BUILD_ID" ]) // {
37 PRETTY_NAME = "${osReleaseContents.PRETTY_NAME} (Initrd)";
39 initrdRelease = pkgs.writeText "initrd-release" (attrsToText initrdReleaseContents);
45 (mkRenamedOptionModule [ "system" "nixosVersion" ] [ "system" "nixos" "version" ])
46 (mkRenamedOptionModule [ "system" "nixosVersionSuffix" ] [ "system" "nixos" "versionSuffix" ])
47 (mkRenamedOptionModule [ "system" "nixosRevision" ] [ "system" "nixos" "revision" ])
48 (mkRenamedOptionModule [ "system" "nixosLabel" ] [ "system" "nixos" "label" ])
51 options.boot.initrd.osRelease = mkOption {
54 default = initrdRelease;
59 nixos.version = mkOption {
62 description = lib.mdDoc "The full NixOS version (e.g. `16.03.1160.f2d4ee1`).";
65 nixos.release = mkOption {
68 default = trivial.release;
69 description = lib.mdDoc "The NixOS release (e.g. `16.03`).";
72 nixos.versionSuffix = mkOption {
75 default = trivial.versionSuffix;
76 description = lib.mdDoc "The NixOS version suffix (e.g. `1160.f2d4ee1`).";
79 nixos.revision = mkOption {
81 type = types.nullOr types.str;
82 default = trivial.revisionWithDefault null;
83 description = lib.mdDoc "The Git revision from which this NixOS configuration was built.";
86 nixos.codeName = mkOption {
89 default = trivial.codeName;
90 description = lib.mdDoc "The NixOS release code name (e.g. `Emu`).";
93 nixos.distroId = mkOption {
97 description = lib.mdDoc "The id of the operating system";
100 nixos.distroName = mkOption {
104 description = lib.mdDoc "The name of the operating system";
107 nixos.variant_id = mkOption {
108 type = types.nullOr (types.strMatching "^[a-z0-9._-]+$");
110 description = lib.mdDoc "A lower-case string identifying a specific variant or edition of the operating system";
111 example = "installer";
114 stateVersion = mkOption {
116 # TODO Remove this and drop the default of the option so people are forced to set it.
117 # Doing this also means fixing the comment in nixos/modules/testing/test-instrumentation.nix
119 lib.warnIf (options.system.stateVersion.highestPrio == (lib.mkOptionDefault { }).priority)
120 "system.stateVersion is not set, defaulting to ${v}. Read why this matters on https://nixos.org/manual/nixos/stable/options.html#opt-system.stateVersion."
122 default = cfg.release;
123 defaultText = literalExpression "config.${opt.release}";
124 description = lib.mdDoc ''
125 This option defines the first version of NixOS you have installed on this particular machine,
126 and is used to maintain compatibility with application data (e.g. databases) created on older NixOS versions.
128 For example, if NixOS version XX.YY ships with AwesomeDB version N by default, and is then
129 upgraded to version XX.YY+1, which ships AwesomeDB version N+1, the existing databases
130 may no longer be compatible, causing applications to fail, or even leading to data loss.
132 The `stateVersion` mechanism avoids this situation by making the default version of such packages
133 conditional on the first version of NixOS you've installed (encoded in `stateVersion`), instead of
134 simply always using the latest one.
136 Note that this generally only affects applications that can't upgrade their data automatically -
137 applications and services supporting automatic migrations will remain on latest versions when
140 Most users should **never** change this value after the initial install, for any reason,
141 even if you've upgraded your system to a new NixOS release.
143 This value does **not** affect the Nixpkgs version your packages and OS are pulled from,
144 so changing it will **not** upgrade your system.
146 This value being lower than the current NixOS release does **not** mean your system is
147 out of date, out of support, or vulnerable.
149 Do **not** change this value unless you have manually inspected all the changes it would
150 make to your configuration, and migrated your data accordingly.
154 configurationRevision = mkOption {
155 type = types.nullOr types.str;
157 description = lib.mdDoc "The Git revision of the top-level flake from which this configuration was built.";
165 # These defaults are set here rather than up there so that
166 # changing them would not rebuild the manual
167 version = mkDefault (cfg.release + cfg.versionSuffix);
170 # Generate /etc/os-release. See
171 # https://www.freedesktop.org/software/systemd/man/os-release.html for the
174 "lsb-release".text = attrsToText {
175 LSB_VERSION = "${cfg.release} (${cfg.codeName})";
176 DISTRIB_ID = "${cfg.distroId}";
177 DISTRIB_RELEASE = cfg.release;
178 DISTRIB_CODENAME = toLower cfg.codeName;
179 DISTRIB_DESCRIPTION = "${cfg.distroName} ${cfg.release} (${cfg.codeName})";
182 "os-release".text = attrsToText osReleaseContents;
187 # uses version info nixpkgs, which requires a full nixpkgs path
188 meta.buildDocsInSandbox = false;