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 VERSION = "${cfg.release} (${cfg.codeName})";
26 VERSION_CODENAME = toLower cfg.codeName;
27 VERSION_ID = cfg.release;
28 BUILD_ID = cfg.version;
29 PRETTY_NAME = "${cfg.distroName} ${cfg.release} (${cfg.codeName})";
30 LOGO = "nix-snowflake";
31 HOME_URL = optionalString isNixos "https://nixos.org/";
32 DOCUMENTATION_URL = optionalString isNixos "https://nixos.org/learn.html";
33 SUPPORT_URL = optionalString isNixos "https://nixos.org/community.html";
34 BUG_REPORT_URL = optionalString isNixos "https://github.com/NixOS/nixpkgs/issues";
35 ANSI_COLOR = optionalString isNixos "1;34";
36 IMAGE_ID = optionalString (config.system.image.id != null) config.system.image.id;
37 IMAGE_VERSION = optionalString (config.system.image.version != null) config.system.image.version;
38 } // lib.optionalAttrs (cfg.variant_id != null) {
39 VARIANT_ID = cfg.variant_id;
42 initrdReleaseContents = (removeAttrs osReleaseContents [ "BUILD_ID" ]) // {
43 PRETTY_NAME = "${osReleaseContents.PRETTY_NAME} (Initrd)";
45 initrdRelease = pkgs.writeText "initrd-release" (attrsToText initrdReleaseContents);
51 (mkRenamedOptionModule [ "system" "nixosVersion" ] [ "system" "nixos" "version" ])
52 (mkRenamedOptionModule [ "system" "nixosVersionSuffix" ] [ "system" "nixos" "versionSuffix" ])
53 (mkRenamedOptionModule [ "system" "nixosRevision" ] [ "system" "nixos" "revision" ])
54 (mkRenamedOptionModule [ "system" "nixosLabel" ] [ "system" "nixos" "label" ])
57 options.boot.initrd.osRelease = mkOption {
60 default = initrdRelease;
68 description = "The full NixOS version (e.g. `16.03.1160.f2d4ee1`).";
74 default = trivial.release;
75 description = "The NixOS release (e.g. `16.03`).";
78 versionSuffix = mkOption {
81 default = trivial.versionSuffix;
82 description = "The NixOS version suffix (e.g. `1160.f2d4ee1`).";
87 type = types.nullOr types.str;
88 default = trivial.revisionWithDefault null;
89 description = "The Git revision from which this NixOS configuration was built.";
95 default = trivial.codeName;
96 description = "The NixOS release code name (e.g. `Emu`).";
103 description = "The id of the operating system";
106 distroName = mkOption {
110 description = "The name of the operating system";
113 variant_id = mkOption {
114 type = types.nullOr (types.strMatching "^[a-z0-9._-]+$");
116 description = "A lower-case string identifying a specific variant or edition of the operating system";
117 example = "installer";
124 type = types.nullOr types.str;
129 This corresponds to the IMAGE_ID field in os-release. See the
130 upstream docs for more details on valid characters for this field:
131 https://www.freedesktop.org/software/systemd/man/latest/os-release.html#IMAGE_ID=
133 You would only want to set this option if you're build NixOS appliance images.
137 version = lib.mkOption {
138 type = types.nullOr types.str;
143 This corresponds to the IMAGE_VERSION field in os-release. See the
144 upstream docs for more details on valid characters for this field:
145 https://www.freedesktop.org/software/systemd/man/latest/os-release.html#IMAGE_VERSION=
147 You would only want to set this option if you're build NixOS appliance images.
153 stateVersion = mkOption {
155 # TODO Remove this and drop the default of the option so people are forced to set it.
156 # Doing this also means fixing the comment in nixos/modules/testing/test-instrumentation.nix
158 lib.warnIf (options.system.stateVersion.highestPrio == (lib.mkOptionDefault { }).priority)
159 "system.stateVersion is not set, defaulting to ${v}. Read why this matters on https://nixos.org/manual/nixos/stable/options.html#opt-system.stateVersion."
161 default = cfg.release;
162 defaultText = literalExpression "config.${opt.release}";
164 This option defines the first version of NixOS you have installed on this particular machine,
165 and is used to maintain compatibility with application data (e.g. databases) created on older NixOS versions.
167 For example, if NixOS version XX.YY ships with AwesomeDB version N by default, and is then
168 upgraded to version XX.YY+1, which ships AwesomeDB version N+1, the existing databases
169 may no longer be compatible, causing applications to fail, or even leading to data loss.
171 The `stateVersion` mechanism avoids this situation by making the default version of such packages
172 conditional on the first version of NixOS you've installed (encoded in `stateVersion`), instead of
173 simply always using the latest one.
175 Note that this generally only affects applications that can't upgrade their data automatically -
176 applications and services supporting automatic migrations will remain on latest versions when
179 Most users should **never** change this value after the initial install, for any reason,
180 even if you've upgraded your system to a new NixOS release.
182 This value does **not** affect the Nixpkgs version your packages and OS are pulled from,
183 so changing it will **not** upgrade your system.
185 This value being lower than the current NixOS release does **not** mean your system is
186 out of date, out of support, or vulnerable.
188 Do **not** change this value unless you have manually inspected all the changes it would
189 make to your configuration, and migrated your data accordingly.
193 configurationRevision = mkOption {
194 type = types.nullOr types.str;
196 description = "The Git revision of the top-level flake from which this configuration was built.";
204 # These defaults are set here rather than up there so that
205 # changing them would not rebuild the manual
206 version = mkDefault (cfg.release + cfg.versionSuffix);
209 # Generate /etc/os-release. See
210 # https://www.freedesktop.org/software/systemd/man/os-release.html for the
213 "lsb-release".text = attrsToText {
214 LSB_VERSION = "${cfg.release} (${cfg.codeName})";
215 DISTRIB_ID = "${cfg.distroId}";
216 DISTRIB_RELEASE = cfg.release;
217 DISTRIB_CODENAME = toLower cfg.codeName;
218 DISTRIB_DESCRIPTION = "${cfg.distroName} ${cfg.release} (${cfg.codeName})";
221 "os-release".text = attrsToText osReleaseContents;
226 # uses version info nixpkgs, which requires a full nixpkgs path
227 meta.buildDocsInSandbox = false;