2021-12-19 01:06:50 +00:00
|
|
|
{ config, lib, options, pkgs, ... }:
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.system.nixos;
|
2021-12-19 01:06:50 +00:00
|
|
|
opt = options.system.nixos;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2022-03-05 16:20:37 +00:00
|
|
|
inherit (lib)
|
|
|
|
concatStringsSep mapAttrsToList toLower
|
|
|
|
literalExpression mkRenamedOptionModule mkDefault mkOption trivial types;
|
|
|
|
|
2022-03-30 09:31:56 +00:00
|
|
|
needsEscaping = s: null != builtins.match "[a-zA-Z0-9]+" s;
|
2023-05-24 13:37:59 +00:00
|
|
|
escapeIfNecessary = s: if needsEscaping s then s else ''"${lib.escape [ "\$" "\"" "\\" "\`" ] s}"'';
|
2022-03-05 16:20:37 +00:00
|
|
|
attrsToText = attrs:
|
2022-03-30 09:31:56 +00:00
|
|
|
concatStringsSep "\n" (
|
2023-05-24 13:37:59 +00:00
|
|
|
mapAttrsToList (n: v: ''${n}=${escapeIfNecessary (toString v)}'') attrs
|
2022-06-16 17:23:12 +00:00
|
|
|
) + "\n";
|
2022-03-05 16:20:37 +00:00
|
|
|
|
2022-04-03 18:54:34 +00:00
|
|
|
osReleaseContents = {
|
2023-01-20 10:41:00 +00:00
|
|
|
NAME = "${cfg.distroName}";
|
|
|
|
ID = "${cfg.distroId}";
|
2022-04-03 18:54:34 +00:00
|
|
|
VERSION = "${cfg.release} (${cfg.codeName})";
|
|
|
|
VERSION_CODENAME = toLower cfg.codeName;
|
|
|
|
VERSION_ID = cfg.release;
|
|
|
|
BUILD_ID = cfg.version;
|
2023-01-20 10:41:00 +00:00
|
|
|
PRETTY_NAME = "${cfg.distroName} ${cfg.release} (${cfg.codeName})";
|
2022-04-03 18:54:34 +00:00
|
|
|
LOGO = "nix-snowflake";
|
2023-01-20 10:41:00 +00:00
|
|
|
HOME_URL = lib.optionalString (cfg.distroId == "nixos") "https://nixos.org/";
|
|
|
|
DOCUMENTATION_URL = lib.optionalString (cfg.distroId == "nixos") "https://nixos.org/learn.html";
|
|
|
|
SUPPORT_URL = lib.optionalString (cfg.distroId == "nixos") "https://nixos.org/community.html";
|
|
|
|
BUG_REPORT_URL = lib.optionalString (cfg.distroId == "nixos") "https://github.com/NixOS/nixpkgs/issues";
|
2023-01-11 07:51:40 +00:00
|
|
|
} // lib.optionalAttrs (cfg.variant_id != null) {
|
|
|
|
VARIANT_ID = cfg.variant_id;
|
2022-04-03 18:54:34 +00:00
|
|
|
};
|
|
|
|
|
2023-07-15 17:15:38 +00:00
|
|
|
initrdReleaseContents = (removeAttrs osReleaseContents [ "BUILD_ID" ]) // {
|
2022-04-03 18:54:34 +00:00
|
|
|
PRETTY_NAME = "${osReleaseContents.PRETTY_NAME} (Initrd)";
|
|
|
|
};
|
|
|
|
initrdRelease = pkgs.writeText "initrd-release" (attrsToText initrdReleaseContents);
|
|
|
|
|
2022-03-05 16:20:37 +00:00
|
|
|
in
|
2020-04-24 23:36:52 +00:00
|
|
|
{
|
|
|
|
imports = [
|
2022-08-12 12:06:08 +00:00
|
|
|
./label.nix
|
2020-04-24 23:36:52 +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" ])
|
|
|
|
];
|
|
|
|
|
2022-08-12 12:06:08 +00:00
|
|
|
options.boot.initrd.osRelease = mkOption {
|
|
|
|
internal = true;
|
|
|
|
readOnly = true;
|
|
|
|
default = initrdRelease;
|
|
|
|
};
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
options.system = {
|
|
|
|
|
|
|
|
nixos.version = mkOption {
|
|
|
|
internal = true;
|
|
|
|
type = types.str;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "The full NixOS version (e.g. `16.03.1160.f2d4ee1`).";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
nixos.release = mkOption {
|
|
|
|
readOnly = true;
|
|
|
|
type = types.str;
|
|
|
|
default = trivial.release;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "The NixOS release (e.g. `16.03`).";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
nixos.versionSuffix = mkOption {
|
|
|
|
internal = true;
|
|
|
|
type = types.str;
|
|
|
|
default = trivial.versionSuffix;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "The NixOS version suffix (e.g. `1160.f2d4ee1`).";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
nixos.revision = mkOption {
|
|
|
|
internal = true;
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = trivial.revisionWithDefault null;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "The Git revision from which this NixOS configuration was built.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
nixos.codeName = mkOption {
|
|
|
|
readOnly = true;
|
|
|
|
type = types.str;
|
|
|
|
default = trivial.codeName;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "The NixOS release code name (e.g. `Emu`).";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
2023-01-20 10:41:00 +00:00
|
|
|
nixos.distroId = mkOption {
|
|
|
|
internal = true;
|
|
|
|
type = types.str;
|
|
|
|
default = "nixos";
|
|
|
|
description = lib.mdDoc "The id of the operating system";
|
|
|
|
};
|
|
|
|
|
|
|
|
nixos.distroName = mkOption {
|
|
|
|
internal = true;
|
|
|
|
type = types.str;
|
|
|
|
default = "NixOS";
|
|
|
|
description = lib.mdDoc "The name of the operating system";
|
|
|
|
};
|
|
|
|
|
2023-01-11 07:51:40 +00:00
|
|
|
nixos.variant_id = mkOption {
|
|
|
|
type = types.nullOr (types.strMatching "^[a-z0-9._-]+$");
|
|
|
|
default = null;
|
|
|
|
description = lib.mdDoc "A lower-case string identifying a specific variant or edition of the operating system";
|
|
|
|
example = "installer";
|
|
|
|
};
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
stateVersion = mkOption {
|
|
|
|
type = types.str;
|
2022-12-28 21:21:41 +00:00
|
|
|
# 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
|
|
|
|
apply = v:
|
|
|
|
lib.warnIf (options.system.stateVersion.highestPrio == (lib.mkOptionDefault { }).priority)
|
|
|
|
"system.stateVersion is not set, defaulting to ${v}. Read why this matters on https://nixos.org/manual/nixos/stable/options.html#opt-system.stateVersion."
|
|
|
|
v;
|
2020-04-24 23:36:52 +00:00
|
|
|
default = cfg.release;
|
2021-12-19 01:06:50 +00:00
|
|
|
defaultText = literalExpression "config.${opt.release}";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2023-11-16 04:20:00 +00:00
|
|
|
This option defines the first version of NixOS you have installed on this particular machine,
|
|
|
|
and is used to maintain compatibility with application data (e.g. databases) created on older NixOS versions.
|
|
|
|
|
|
|
|
For example, if NixOS version XX.YY ships with AwesomeDB version N by default, and is then
|
|
|
|
upgraded to version XX.YY+1, which ships AwesomeDB version N+1, the existing databases
|
|
|
|
may no longer be compatible, causing applications to fail, or even leading to data loss.
|
|
|
|
|
|
|
|
The `stateVersion` mechanism avoids this situation by making the default version of such packages
|
|
|
|
conditional on the first version of NixOS you've installed (encoded in `stateVersion`), instead of
|
|
|
|
simply always using the latest one.
|
|
|
|
|
|
|
|
Note that this generally only affects applications that can't upgrade their data automatically -
|
|
|
|
applications and services supporting automatic migrations will remain on latest versions when
|
|
|
|
you upgrade.
|
|
|
|
|
|
|
|
Most users should **never** change this value after the initial install, for any reason,
|
|
|
|
even if you've upgraded your system to a new NixOS release.
|
|
|
|
|
|
|
|
This value does **not** affect the Nixpkgs version your packages and OS are pulled from,
|
|
|
|
so changing it will **not** upgrade your system.
|
|
|
|
|
|
|
|
This value being lower than the current NixOS release does **not** mean your system is
|
|
|
|
out of date, out of support, or vulnerable.
|
|
|
|
|
|
|
|
Do **not** change this value unless you have manually inspected all the changes it would
|
|
|
|
make to your configuration, and migrated your data accordingly.
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
configurationRevision = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "The Git revision of the top-level flake from which this configuration was built.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
config = {
|
|
|
|
|
|
|
|
system.nixos = {
|
|
|
|
# These defaults are set here rather than up there so that
|
|
|
|
# changing them would not rebuild the manual
|
|
|
|
version = mkDefault (cfg.release + cfg.versionSuffix);
|
|
|
|
};
|
|
|
|
|
|
|
|
# Generate /etc/os-release. See
|
|
|
|
# https://www.freedesktop.org/software/systemd/man/os-release.html for the
|
|
|
|
# format.
|
2022-03-05 16:20:37 +00:00
|
|
|
environment.etc = {
|
|
|
|
"lsb-release".text = attrsToText {
|
|
|
|
LSB_VERSION = "${cfg.release} (${cfg.codeName})";
|
2023-01-20 10:41:00 +00:00
|
|
|
DISTRIB_ID = "${cfg.distroId}";
|
2022-03-05 16:20:37 +00:00
|
|
|
DISTRIB_RELEASE = cfg.release;
|
|
|
|
DISTRIB_CODENAME = toLower cfg.codeName;
|
2023-01-20 10:41:00 +00:00
|
|
|
DISTRIB_DESCRIPTION = "${cfg.distroName} ${cfg.release} (${cfg.codeName})";
|
2022-03-05 16:20:37 +00:00
|
|
|
};
|
|
|
|
|
2022-04-03 18:54:34 +00:00
|
|
|
"os-release".text = attrsToText osReleaseContents;
|
|
|
|
};
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
2022-01-07 04:07:37 +00:00
|
|
|
# uses version info nixpkgs, which requires a full nixpkgs path
|
|
|
|
meta.buildDocsInSandbox = false;
|
2020-04-24 23:36:52 +00:00
|
|
|
}
|