2023-07-07 08:02:38 +00:00
|
|
|
{ options, config, lib, ... }:
|
2017-10-01 14:11:17 +00:00
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.system;
|
|
|
|
|
2017-10-01 15:00:22 +00:00
|
|
|
defaultStateVersion = options.system.stateVersion.default;
|
|
|
|
|
2023-07-07 08:02:38 +00:00
|
|
|
# Based on `lib.trivial.revisionWithDefault` from nixpkgs.
|
|
|
|
gitRevision = path:
|
|
|
|
if pathIsGitRepo "${path}/.git"
|
|
|
|
then commitIdFromGitRepo "${path}/.git"
|
|
|
|
else if pathExists "${path}/.git-revision"
|
|
|
|
then fileContents "${path}/.git-revision"
|
|
|
|
else null;
|
|
|
|
|
|
|
|
nixpkgsSrc = config.nixpkgs.source;
|
|
|
|
|
|
|
|
# If `nixpkgs.constructedByUs` is true, then Nixpkgs was imported from
|
|
|
|
# `nixpkgs.source` and we can use revision information (flake input,
|
|
|
|
# `builtins.fetchGit`, etc.) from it. Otherwise `pkgs` could be
|
|
|
|
# anything and we can't reliably determine exact version information,
|
|
|
|
# but if the configuration explicitly sets `nixpkgs.source` we
|
|
|
|
# trust it.
|
|
|
|
useSourceRevision =
|
|
|
|
(config.nixpkgs.constructedByUs
|
|
|
|
|| options.nixpkgs.source.highestPrio < (lib.mkDefault {}).priority)
|
|
|
|
&& isAttrs nixpkgsSrc
|
|
|
|
&& (nixpkgsSrc._type or null == "flake"
|
|
|
|
|| isString (nixpkgsSrc.rev or null));
|
2017-10-01 14:11:17 +00:00
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
options = {
|
|
|
|
system.stateVersion = mkOption {
|
|
|
|
type = types.int;
|
2019-05-01 10:42:31 +00:00
|
|
|
default = 4;
|
2023-06-22 11:21:32 +00:00
|
|
|
description = lib.mdDoc ''
|
2017-10-01 14:11:17 +00: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
|
|
|
|
existing databases. To prevent such breakage, you can set the
|
|
|
|
value of this option to the NixOS release with which you want
|
|
|
|
to be compatible. The effect is that NixOS will option
|
|
|
|
defaults corresponding to the specified release (such as using
|
|
|
|
an older version of PostgreSQL).
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
system.darwinLabel = mkOption {
|
|
|
|
type = types.str;
|
2023-06-22 11:21:32 +00:00
|
|
|
description = lib.mdDoc "Label to be used in the names of generated outputs.";
|
2017-10-01 14:11:17 +00:00
|
|
|
};
|
|
|
|
|
2019-05-04 18:59:25 +00:00
|
|
|
system.darwinVersion = mkOption {
|
|
|
|
internal = true;
|
|
|
|
type = types.str;
|
2023-07-07 08:02:38 +00:00
|
|
|
default = "darwin${toString cfg.stateVersion}${cfg.darwinVersionSuffix}";
|
|
|
|
description = lib.mdDoc "The full darwin version (e.g. `darwin4.2abdb5a`).";
|
2019-05-04 18:59:25 +00:00
|
|
|
};
|
|
|
|
|
2020-10-18 10:57:15 +00:00
|
|
|
system.darwinVersionSuffix = mkOption {
|
|
|
|
internal = true;
|
|
|
|
type = types.str;
|
2023-07-07 08:02:38 +00:00
|
|
|
default = if cfg.darwinRevision != null
|
|
|
|
then ".${substring 0 7 cfg.darwinRevision}"
|
|
|
|
else "";
|
2023-06-22 11:21:32 +00:00
|
|
|
description = lib.mdDoc "The short darwin version suffix (e.g. `.2abdb5a`).";
|
2020-10-18 10:57:15 +00:00
|
|
|
};
|
|
|
|
|
2019-05-04 18:59:25 +00:00
|
|
|
system.darwinRevision = mkOption {
|
|
|
|
internal = true;
|
2023-07-07 08:02:38 +00:00
|
|
|
type = types.nullOr types.str;
|
2023-07-07 08:02:38 +00:00
|
|
|
default = gitRevision (toString ../..);
|
2023-06-22 11:21:32 +00:00
|
|
|
description = lib.mdDoc "The darwin git revision from which this configuration was built.";
|
2019-05-04 18:59:25 +00:00
|
|
|
};
|
|
|
|
|
2017-10-01 14:11:17 +00:00
|
|
|
system.nixpkgsRelease = mkOption {
|
|
|
|
readOnly = true;
|
|
|
|
type = types.str;
|
2023-07-07 08:02:38 +00:00
|
|
|
default = lib.trivial.release;
|
2023-06-22 11:21:32 +00:00
|
|
|
description = lib.mdDoc "The nixpkgs release (e.g. `16.03`).";
|
2017-10-01 14:11:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
system.nixpkgsVersion = mkOption {
|
|
|
|
internal = true;
|
|
|
|
type = types.str;
|
2023-07-07 08:02:38 +00:00
|
|
|
default = cfg.nixpkgsRelease + cfg.nixpkgsVersionSuffix;
|
2023-06-22 11:21:32 +00:00
|
|
|
description = lib.mdDoc "The full nixpkgs version (e.g. `16.03.1160.f2d4ee1`).";
|
2017-10-01 14:11:17 +00:00
|
|
|
};
|
|
|
|
|
2020-10-18 10:57:15 +00:00
|
|
|
system.nixpkgsVersionSuffix = mkOption {
|
|
|
|
internal = true;
|
|
|
|
type = types.str;
|
2023-07-07 08:02:38 +00:00
|
|
|
default = if useSourceRevision
|
|
|
|
then ".${lib.substring 0 8 (nixpkgsSrc.lastModifiedDate or nixpkgsSrc.lastModified or "19700101")}.${nixpkgsSrc.shortRev or "dirty"}"
|
|
|
|
else lib.trivial.versionSuffix;
|
2023-06-22 11:21:32 +00:00
|
|
|
description = lib.mdDoc "The short nixpkgs version suffix (e.g. `.1160.f2d4ee1`).";
|
2020-10-18 10:57:15 +00:00
|
|
|
};
|
|
|
|
|
2017-10-01 14:11:17 +00:00
|
|
|
system.nixpkgsRevision = mkOption {
|
|
|
|
internal = true;
|
2023-07-07 08:02:38 +00:00
|
|
|
type = types.nullOr types.str;
|
2023-07-07 08:02:38 +00:00
|
|
|
default = if useSourceRevision && nixpkgsSrc ? rev
|
|
|
|
then nixpkgsSrc.rev
|
|
|
|
else lib.trivial.revisionWithDefault null;
|
2023-06-22 11:21:32 +00:00
|
|
|
description = lib.mdDoc "The nixpkgs git revision from which this configuration was built.";
|
2017-10-01 14:11:17 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = {
|
2023-07-07 08:02:38 +00:00
|
|
|
# This default is set here rather than up there so that the options
|
|
|
|
# documentation is not reprocessed on every commit
|
2020-10-18 10:57:15 +00:00
|
|
|
system.darwinLabel = mkDefault "${cfg.nixpkgsVersion}+${cfg.darwinVersion}";
|
2017-10-01 15:00:22 +00:00
|
|
|
|
2023-07-07 08:02:38 +00:00
|
|
|
assertions = [ {
|
|
|
|
assertion = cfg.stateVersion <= defaultStateVersion;
|
|
|
|
message = "system.stateVersion = ${toString cfg.stateVersion}; is not a valid value";
|
|
|
|
} ];
|
2017-10-01 14:11:17 +00:00
|
|
|
};
|
|
|
|
}
|