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 escapeIfNeccessary = s: if needsEscaping s then s else ''"${lib.escape [ "\$" "\"" "\\" "\`" ] s}"'';
14 concatStringsSep "\n" (
15 mapAttrsToList (n: v: ''${n}=${escapeIfNeccessary (toString v)}'') attrs
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 = "NixOS ${cfg.release} (${cfg.codeName})";
26 LOGO = "nix-snowflake";
27 HOME_URL = "https://nixos.org/";
28 DOCUMENTATION_URL = "https://nixos.org/learn.html";
29 SUPPORT_URL = "https://nixos.org/community.html";
30 BUG_REPORT_URL = "https://github.com/NixOS/nixpkgs/issues";
33 initrdReleaseContents = osReleaseContents // {
34 PRETTY_NAME = "${osReleaseContents.PRETTY_NAME} (Initrd)";
36 initrdRelease = pkgs.writeText "initrd-release" (attrsToText initrdReleaseContents);
42 (mkRenamedOptionModule [ "system" "nixosVersion" ] [ "system" "nixos" "version" ])
43 (mkRenamedOptionModule [ "system" "nixosVersionSuffix" ] [ "system" "nixos" "versionSuffix" ])
44 (mkRenamedOptionModule [ "system" "nixosRevision" ] [ "system" "nixos" "revision" ])
45 (mkRenamedOptionModule [ "system" "nixosLabel" ] [ "system" "nixos" "label" ])
48 options.boot.initrd.osRelease = mkOption {
51 default = initrdRelease;
56 nixos.version = mkOption {
59 description = lib.mdDoc "The full NixOS version (e.g. `16.03.1160.f2d4ee1`).";
62 nixos.release = mkOption {
65 default = trivial.release;
66 description = lib.mdDoc "The NixOS release (e.g. `16.03`).";
69 nixos.versionSuffix = mkOption {
72 default = trivial.versionSuffix;
73 description = lib.mdDoc "The NixOS version suffix (e.g. `1160.f2d4ee1`).";
76 nixos.revision = mkOption {
78 type = types.nullOr types.str;
79 default = trivial.revisionWithDefault null;
80 description = lib.mdDoc "The Git revision from which this NixOS configuration was built.";
83 nixos.codeName = mkOption {
86 default = trivial.codeName;
87 description = lib.mdDoc "The NixOS release code name (e.g. `Emu`).";
90 stateVersion = mkOption {
92 default = cfg.release;
93 defaultText = literalExpression "config.${opt.release}";
94 description = lib.mdDoc ''
95 Every once in a while, a new NixOS release may change
96 configuration defaults in a way incompatible with stateful
97 data. For instance, if the default version of PostgreSQL
98 changes, the new version will probably be unable to read your
99 existing databases. To prevent such breakage, you should set the
100 value of this option to the NixOS release with which you want
101 to be compatible. The effect is that NixOS will use
102 defaults corresponding to the specified release (such as using
103 an older version of PostgreSQL).
104 It‘s perfectly fine and recommended to leave this value at the
105 release version of the first install of this system.
106 Changing this option will not upgrade your system. In fact it
107 is meant to stay constant exactly when you upgrade your system.
108 You should only bump this option, if you are sure that you can
109 or have migrated all state on your system which is affected
114 defaultChannel = mkOption {
117 default = "https://nixos.org/channels/nixos-unstable";
118 description = lib.mdDoc "Default NixOS channel to which the root user is subscribed.";
121 configurationRevision = mkOption {
122 type = types.nullOr types.str;
124 description = lib.mdDoc "The Git revision of the top-level flake from which this configuration was built.";
132 # These defaults are set here rather than up there so that
133 # changing them would not rebuild the manual
134 version = mkDefault (cfg.release + cfg.versionSuffix);
137 # Generate /etc/os-release. See
138 # https://www.freedesktop.org/software/systemd/man/os-release.html for the
141 "lsb-release".text = attrsToText {
142 LSB_VERSION = "${cfg.release} (${cfg.codeName})";
143 DISTRIB_ID = "nixos";
144 DISTRIB_RELEASE = cfg.release;
145 DISTRIB_CODENAME = toLower cfg.codeName;
146 DISTRIB_DESCRIPTION = "NixOS ${cfg.release} (${cfg.codeName})";
149 "os-release".text = attrsToText osReleaseContents;
152 # We have to use `warnings` because when warning in the default of the option
153 # the warning would also be shown when building the manual since the manual
154 # has to evaluate the default.
156 # TODO Remove this and drop the default of the option so people are forced to set it.
157 # Doing this also means fixing the comment in nixos/modules/testing/test-instrumentation.nix
158 warnings = lib.optional (options.system.stateVersion.highestPrio == (lib.mkOptionDefault { }).priority)
159 "system.stateVersion is not set, defaulting to ${config.system.stateVersion}. Read why this matters on https://nixos.org/manual/nixos/stable/options.html#opt-system.stateVersion.";
162 # uses version info nixpkgs, which requires a full nixpkgs path
163 meta.buildDocsInSandbox = false;