2021-12-05 19:40:24 +00:00
|
|
|
|
{ config, lib, options, pkgs, ... }:
|
2012-04-10 21:56:38 +01:00
|
|
|
|
|
2015-09-18 14:46:47 +01:00
|
|
|
|
let
|
2017-04-01 01:00:00 +01:00
|
|
|
|
cfg = config.system.nixos;
|
2021-12-05 19:40:24 +00:00
|
|
|
|
opt = options.system.nixos;
|
2015-09-18 14:46:47 +01:00
|
|
|
|
|
2022-02-28 06:44:38 +00:00
|
|
|
|
inherit (lib)
|
|
|
|
|
concatStringsSep mapAttrsToList toLower
|
|
|
|
|
literalExpression mkRenamedOptionModule mkDefault mkOption trivial types;
|
|
|
|
|
|
2022-03-14 04:11:05 +00:00
|
|
|
|
needsEscaping = s: null != builtins.match "[a-zA-Z0-9]+" s;
|
|
|
|
|
escapeIfNeccessary = s: if needsEscaping s then s else ''"${lib.escape [ "\$" "\"" "\\" "\`" ] s}"'';
|
2022-02-28 06:44:38 +00:00
|
|
|
|
attrsToText = attrs:
|
2022-03-14 04:11:05 +00:00
|
|
|
|
concatStringsSep "\n" (
|
|
|
|
|
mapAttrsToList (n: v: ''${n}=${escapeIfNeccessary (toString v)}'') attrs
|
2022-05-26 01:25:12 +01:00
|
|
|
|
) + "\n";
|
2022-02-28 06:44:38 +00:00
|
|
|
|
|
2022-04-01 12:54:09 +01:00
|
|
|
|
osReleaseContents = {
|
|
|
|
|
NAME = "NixOS";
|
|
|
|
|
ID = "nixos";
|
|
|
|
|
VERSION = "${cfg.release} (${cfg.codeName})";
|
|
|
|
|
VERSION_CODENAME = toLower cfg.codeName;
|
|
|
|
|
VERSION_ID = cfg.release;
|
|
|
|
|
BUILD_ID = cfg.version;
|
|
|
|
|
PRETTY_NAME = "NixOS ${cfg.release} (${cfg.codeName})";
|
|
|
|
|
LOGO = "nix-snowflake";
|
|
|
|
|
HOME_URL = "https://nixos.org/";
|
|
|
|
|
DOCUMENTATION_URL = "https://nixos.org/learn.html";
|
|
|
|
|
SUPPORT_URL = "https://nixos.org/community.html";
|
|
|
|
|
BUG_REPORT_URL = "https://github.com/NixOS/nixpkgs/issues";
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
initrdReleaseContents = osReleaseContents // {
|
|
|
|
|
PRETTY_NAME = "${osReleaseContents.PRETTY_NAME} (Initrd)";
|
|
|
|
|
};
|
|
|
|
|
initrdRelease = pkgs.writeText "initrd-release" (attrsToText initrdReleaseContents);
|
|
|
|
|
|
2022-02-28 06:44:38 +00:00
|
|
|
|
in
|
2012-04-10 21:56:38 +01:00
|
|
|
|
{
|
2019-12-10 01:51:19 +00:00
|
|
|
|
imports = [
|
2022-07-14 10:28:21 +01:00
|
|
|
|
./label.nix
|
2019-12-10 01:51:19 +00:00
|
|
|
|
(mkRenamedOptionModule [ "system" "nixosVersion" ] [ "system" "nixos" "version" ])
|
|
|
|
|
(mkRenamedOptionModule [ "system" "nixosVersionSuffix" ] [ "system" "nixos" "versionSuffix" ])
|
|
|
|
|
(mkRenamedOptionModule [ "system" "nixosRevision" ] [ "system" "nixos" "revision" ])
|
|
|
|
|
(mkRenamedOptionModule [ "system" "nixosLabel" ] [ "system" "nixos" "label" ])
|
|
|
|
|
];
|
2012-04-10 21:56:38 +01:00
|
|
|
|
|
2022-07-14 10:51:04 +01:00
|
|
|
|
options.boot.initrd.osRelease = mkOption {
|
|
|
|
|
internal = true;
|
|
|
|
|
readOnly = true;
|
|
|
|
|
default = initrdRelease;
|
|
|
|
|
};
|
|
|
|
|
|
2018-07-25 21:22:54 +01:00
|
|
|
|
options.system = {
|
2013-01-16 13:40:41 +00:00
|
|
|
|
|
2018-07-25 21:22:54 +01:00
|
|
|
|
nixos.version = mkOption {
|
2013-10-23 15:59:33 +01:00
|
|
|
|
internal = true;
|
2013-10-30 10:02:04 +00:00
|
|
|
|
type = types.str;
|
2022-07-20 11:32:04 +01:00
|
|
|
|
description = lib.mdDoc "The full NixOS version (e.g. `16.03.1160.f2d4ee1`).";
|
2012-04-10 21:56:38 +01:00
|
|
|
|
};
|
2012-05-17 22:10:42 +01:00
|
|
|
|
|
2018-07-25 21:22:54 +01:00
|
|
|
|
nixos.release = mkOption {
|
2015-07-30 12:36:57 +01:00
|
|
|
|
readOnly = true;
|
2015-07-27 18:46:36 +01:00
|
|
|
|
type = types.str;
|
2018-04-26 09:31:05 +01:00
|
|
|
|
default = trivial.release;
|
2022-07-20 11:32:04 +01:00
|
|
|
|
description = lib.mdDoc "The NixOS release (e.g. `16.03`).";
|
2015-07-27 18:46:36 +01:00
|
|
|
|
};
|
|
|
|
|
|
2018-07-25 21:22:54 +01:00
|
|
|
|
nixos.versionSuffix = mkOption {
|
2013-10-23 15:59:33 +01:00
|
|
|
|
internal = true;
|
2013-10-30 10:02:04 +00:00
|
|
|
|
type = types.str;
|
2018-04-26 09:31:05 +01:00
|
|
|
|
default = trivial.versionSuffix;
|
2022-07-20 11:32:04 +01:00
|
|
|
|
description = lib.mdDoc "The NixOS version suffix (e.g. `1160.f2d4ee1`).";
|
2013-01-16 13:40:41 +00:00
|
|
|
|
};
|
|
|
|
|
|
2018-07-25 21:22:54 +01:00
|
|
|
|
nixos.revision = mkOption {
|
2013-10-24 18:58:34 +01:00
|
|
|
|
internal = true;
|
2020-02-10 14:25:44 +00:00
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
|
default = trivial.revisionWithDefault null;
|
2022-07-20 11:32:04 +01:00
|
|
|
|
description = lib.mdDoc "The Git revision from which this NixOS configuration was built.";
|
2013-10-24 18:58:34 +01:00
|
|
|
|
};
|
|
|
|
|
|
2018-07-25 21:22:54 +01:00
|
|
|
|
nixos.codeName = mkOption {
|
2015-07-30 12:36:57 +01:00
|
|
|
|
readOnly = true;
|
2013-10-30 10:02:04 +00:00
|
|
|
|
type = types.str;
|
2019-02-03 20:10:12 +00:00
|
|
|
|
default = trivial.codeName;
|
2022-07-20 11:32:04 +01:00
|
|
|
|
description = lib.mdDoc "The NixOS release code name (e.g. `Emu`).";
|
2013-07-17 12:34:40 +01:00
|
|
|
|
};
|
|
|
|
|
|
2017-04-01 01:00:00 +01:00
|
|
|
|
stateVersion = mkOption {
|
|
|
|
|
type = types.str;
|
|
|
|
|
default = cfg.release;
|
2021-12-05 19:40:24 +00:00
|
|
|
|
defaultText = literalExpression "config.${opt.release}";
|
2022-07-20 11:32:04 +01:00
|
|
|
|
description = lib.mdDoc ''
|
2017-04-01 01:00:00 +01:00
|
|
|
|
Every once in a while, a new NixOS release may change
|
|
|
|
|
configuration defaults in a way incompatible with stateful
|
|
|
|
|
data. For instance, if the default version of PostgreSQL
|
|
|
|
|
changes, the new version will probably be unable to read your
|
2020-01-07 21:27:03 +00:00
|
|
|
|
existing databases. To prevent such breakage, you should set the
|
2017-04-01 01:00:00 +01:00
|
|
|
|
value of this option to the NixOS release with which you want
|
2020-01-07 21:27:03 +00:00
|
|
|
|
to be compatible. The effect is that NixOS will use
|
2017-04-01 01:00:00 +01:00
|
|
|
|
defaults corresponding to the specified release (such as using
|
|
|
|
|
an older version of PostgreSQL).
|
2020-01-07 21:27:03 +00:00
|
|
|
|
It‘s perfectly fine and recommended to leave this value at the
|
|
|
|
|
release version of the first install of this system.
|
|
|
|
|
Changing this option will not upgrade your system. In fact it
|
|
|
|
|
is meant to stay constant exactly when you upgrade your system.
|
|
|
|
|
You should only bump this option, if you are sure that you can
|
|
|
|
|
or have migrated all state on your system which is affected
|
|
|
|
|
by this option.
|
2017-04-01 01:00:00 +01:00
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2015-09-18 14:46:47 +01:00
|
|
|
|
defaultChannel = mkOption {
|
2013-10-24 14:09:00 +01:00
|
|
|
|
internal = true;
|
2013-10-30 10:02:04 +00:00
|
|
|
|
type = types.str;
|
2020-04-01 02:11:51 +01:00
|
|
|
|
default = "https://nixos.org/channels/nixos-unstable";
|
2022-07-20 11:32:04 +01:00
|
|
|
|
description = lib.mdDoc "Default NixOS channel to which the root user is subscribed.";
|
2013-10-24 14:09:00 +01:00
|
|
|
|
};
|
|
|
|
|
|
2019-09-13 17:58:40 +01:00
|
|
|
|
configurationRevision = mkOption {
|
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
|
default = null;
|
2022-07-20 11:32:04 +01:00
|
|
|
|
description = lib.mdDoc "The Git revision of the top-level flake from which this configuration was built.";
|
2019-09-13 17:58:40 +01:00
|
|
|
|
};
|
|
|
|
|
|
2012-05-17 22:10:42 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
config = {
|
|
|
|
|
|
2017-04-01 01:00:00 +01:00
|
|
|
|
system.nixos = {
|
2015-09-18 17:50:48 +01:00
|
|
|
|
# These defaults are set here rather than up there so that
|
|
|
|
|
# changing them would not rebuild the manual
|
2017-04-01 01:00:00 +01:00
|
|
|
|
version = mkDefault (cfg.release + cfg.versionSuffix);
|
2015-09-18 14:46:47 +01:00
|
|
|
|
};
|
2013-07-17 12:34:40 +01:00
|
|
|
|
|
2012-05-17 22:10:42 +01:00
|
|
|
|
# Generate /etc/os-release. See
|
2017-01-07 16:28:11 +00:00
|
|
|
|
# https://www.freedesktop.org/software/systemd/man/os-release.html for the
|
2012-05-17 22:10:42 +01:00
|
|
|
|
# format.
|
2022-02-28 06:44:38 +00:00
|
|
|
|
environment.etc = {
|
|
|
|
|
"lsb-release".text = attrsToText {
|
|
|
|
|
LSB_VERSION = "${cfg.release} (${cfg.codeName})";
|
|
|
|
|
DISTRIB_ID = "nixos";
|
|
|
|
|
DISTRIB_RELEASE = cfg.release;
|
|
|
|
|
DISTRIB_CODENAME = toLower cfg.codeName;
|
|
|
|
|
DISTRIB_DESCRIPTION = "NixOS ${cfg.release} (${cfg.codeName})";
|
|
|
|
|
};
|
|
|
|
|
|
2022-04-01 12:54:09 +01:00
|
|
|
|
"os-release".text = attrsToText osReleaseContents;
|
|
|
|
|
};
|
|
|
|
|
|
2021-05-24 15:08:40 +01:00
|
|
|
|
# We have to use `warnings` because when warning in the default of the option
|
|
|
|
|
# the warning would also be shown when building the manual since the manual
|
|
|
|
|
# has to evaluate the default.
|
|
|
|
|
#
|
|
|
|
|
# TODO Remove this and drop the default of the option so people are forced to set it.
|
|
|
|
|
# Doing this also means fixing the comment in nixos/modules/testing/test-instrumentation.nix
|
|
|
|
|
warnings = lib.optional (options.system.stateVersion.highestPrio == (lib.mkOptionDefault { }).priority)
|
|
|
|
|
"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.";
|
2012-04-10 21:56:38 +01:00
|
|
|
|
};
|
|
|
|
|
|
2021-11-18 23:26:27 +00:00
|
|
|
|
# uses version info nixpkgs, which requires a full nixpkgs path
|
|
|
|
|
meta.buildDocsInSandbox = false;
|
2012-04-10 21:56:38 +01:00
|
|
|
|
}
|