1 { config, lib, options, pkgs, ... }:
4 cfg = config.system.nixos;
5 opt = options.system.nixos;
8 concatStringsSep mapAttrsToList toLower optionalString
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}"'';
15 (mapAttrsToList (n: v: ''${n}=${escapeIfNecessary (toString v)}'') attrs)
20 isNixos = cfg.distroId == "nixos";
23 NAME = "${cfg.distroName}";
24 ID = "${cfg.distroId}";
25 ID_LIKE = optionalString (!isNixos) "nixos";
26 VENDOR_NAME = cfg.vendorName;
27 VERSION = "${cfg.release} (${cfg.codeName})";
28 VERSION_CODENAME = toLower cfg.codeName;
29 VERSION_ID = cfg.release;
30 BUILD_ID = cfg.version;
31 PRETTY_NAME = "${cfg.distroName} ${cfg.release} (${cfg.codeName})";
32 CPE_NAME = "cpe:/o:${cfg.vendorId}:${cfg.distroId}:${cfg.release}";
33 LOGO = "nix-snowflake";
34 HOME_URL = optionalString isNixos "https://nixos.org/";
35 VENDOR_URL = optionalString isNixos "https://nixos.org/";
36 DOCUMENTATION_URL = optionalString isNixos "https://nixos.org/learn.html";
37 SUPPORT_URL = optionalString isNixos "https://nixos.org/community.html";
38 BUG_REPORT_URL = optionalString isNixos "https://github.com/NixOS/nixpkgs/issues";
39 ANSI_COLOR = optionalString isNixos "1;34";
40 IMAGE_ID = optionalString (config.system.image.id != null) config.system.image.id;
41 IMAGE_VERSION = optionalString (config.system.image.version != null) config.system.image.version;
42 VARIANT = optionalString (cfg.variantName != null) cfg.variantName;
43 VARIANT_ID = optionalString (cfg.variant_id != null) cfg.variant_id;
44 DEFAULT_HOSTNAME = config.networking.fqdnOrHostName;
45 SUPPORT_END = "2025-06-30";
48 initrdReleaseContents = (removeAttrs osReleaseContents [ "BUILD_ID" ]) // {
49 PRETTY_NAME = "${osReleaseContents.PRETTY_NAME} (Initrd)";
51 initrdRelease = pkgs.writeText "initrd-release" (attrsToText initrdReleaseContents);
57 (mkRenamedOptionModule [ "system" "nixosVersion" ] [ "system" "nixos" "version" ])
58 (mkRenamedOptionModule [ "system" "nixosVersionSuffix" ] [ "system" "nixos" "versionSuffix" ])
59 (mkRenamedOptionModule [ "system" "nixosRevision" ] [ "system" "nixos" "revision" ])
60 (mkRenamedOptionModule [ "system" "nixosLabel" ] [ "system" "nixos" "label" ])
63 options.boot.initrd.osRelease = mkOption {
66 default = initrdRelease;
74 description = "The full NixOS version (e.g. `16.03.1160.f2d4ee1`).";
80 default = trivial.release;
81 description = "The NixOS release (e.g. `16.03`).";
84 versionSuffix = mkOption {
87 default = trivial.versionSuffix;
88 description = "The NixOS version suffix (e.g. `1160.f2d4ee1`).";
93 type = types.nullOr types.str;
94 default = trivial.revisionWithDefault null;
95 description = "The Git revision from which this NixOS configuration was built.";
101 default = trivial.codeName;
102 description = "The NixOS release code name (e.g. `Emu`).";
105 distroId = mkOption {
109 description = "The id of the operating system";
112 distroName = mkOption {
116 description = "The name of the operating system";
119 variant_id = mkOption {
120 type = types.nullOr (types.strMatching "^[a-z0-9._-]+$");
122 description = "A lower-case string identifying a specific variant or edition of the operating system";
123 example = "installer";
126 variantName = mkOption {
127 type = types.nullOr types.str;
129 description = "A string identifying a specific variant or edition of the operating system suitable for presentation to the user";
130 example = "NixOS Installer Image";
133 vendorId = mkOption {
137 description = "The id of the operating system vendor";
140 vendorName = mkOption {
144 description = "The name of the operating system vendor";
151 type = types.nullOr types.str;
156 This corresponds to the IMAGE_ID field in os-release. See the
157 upstream docs for more details on valid characters for this field:
158 https://www.freedesktop.org/software/systemd/man/latest/os-release.html#IMAGE_ID=
160 You would only want to set this option if you're build NixOS appliance images.
164 version = lib.mkOption {
165 type = types.nullOr types.str;
170 This corresponds to the IMAGE_VERSION field in os-release. See the
171 upstream docs for more details on valid characters for this field:
172 https://www.freedesktop.org/software/systemd/man/latest/os-release.html#IMAGE_VERSION=
174 You would only want to set this option if you're build NixOS appliance images.
180 stateVersion = mkOption {
182 # TODO Remove this and drop the default of the option so people are forced to set it.
183 # Doing this also means fixing the comment in nixos/modules/testing/test-instrumentation.nix
185 lib.warnIf (options.system.stateVersion.highestPrio == (lib.mkOptionDefault { }).priority)
186 "system.stateVersion is not set, defaulting to ${v}. Read why this matters on https://nixos.org/manual/nixos/stable/options.html#opt-system.stateVersion."
188 default = cfg.release;
189 defaultText = literalExpression "config.${opt.release}";
191 This option defines the first version of NixOS you have installed on this particular machine,
192 and is used to maintain compatibility with application data (e.g. databases) created on older NixOS versions.
194 For example, if NixOS version XX.YY ships with AwesomeDB version N by default, and is then
195 upgraded to version XX.YY+1, which ships AwesomeDB version N+1, the existing databases
196 may no longer be compatible, causing applications to fail, or even leading to data loss.
198 The `stateVersion` mechanism avoids this situation by making the default version of such packages
199 conditional on the first version of NixOS you've installed (encoded in `stateVersion`), instead of
200 simply always using the latest one.
202 Note that this generally only affects applications that can't upgrade their data automatically -
203 applications and services supporting automatic migrations will remain on latest versions when
206 Most users should **never** change this value after the initial install, for any reason,
207 even if you've upgraded your system to a new NixOS release.
209 This value does **not** affect the Nixpkgs version your packages and OS are pulled from,
210 so changing it will **not** upgrade your system.
212 This value being lower than the current NixOS release does **not** mean your system is
213 out of date, out of support, or vulnerable.
215 Do **not** change this value unless you have manually inspected all the changes it would
216 make to your configuration, and migrated your data accordingly.
220 configurationRevision = mkOption {
221 type = types.nullOr types.str;
223 description = "The Git revision of the top-level flake from which this configuration was built.";
231 # These defaults are set here rather than up there so that
232 # changing them would not rebuild the manual
233 version = mkDefault (cfg.release + cfg.versionSuffix);
236 # Generate /etc/os-release. See
237 # https://www.freedesktop.org/software/systemd/man/os-release.html for the
240 "lsb-release".text = attrsToText {
241 LSB_VERSION = "${cfg.release} (${cfg.codeName})";
242 DISTRIB_ID = "${cfg.distroId}";
243 DISTRIB_RELEASE = cfg.release;
244 DISTRIB_CODENAME = toLower cfg.codeName;
245 DISTRIB_DESCRIPTION = "${cfg.distroName} ${cfg.release} (${cfg.codeName})";
248 "os-release".text = attrsToText osReleaseContents;
253 # uses version info nixpkgs, which requires a full nixpkgs path
254 meta.buildDocsInSandbox = false;