summaryrefslogtreecommitdiff
path: root/modules/system
diff options
context:
space:
mode:
authorDaiderd Jordan <daiderd@gmail.com>2023-07-09 12:34:19 +0200
committerGitHub <noreply@github.com>2023-07-09 12:34:19 +0200
commit66a3047fa88eb6aa5c5a2e675de91f0431fbe561 (patch)
treefe02b1b923540b82a7cc03488eaa4d5059863aa6 /modules/system
parent4e3fc1864712a534d30ef074d695e968f1fb1487 (diff)
parentf9724c4543035d6190c00168ebfa93f0b2e927d0 (diff)
Merge pull request #723 from emilazy/rationalize-nixpkgs-handling
Rationalize handling of Nixpkgs
Diffstat (limited to 'modules/system')
-rw-r--r--modules/system/flake-overrides.nix20
-rw-r--r--modules/system/version.nix84
2 files changed, 45 insertions, 59 deletions
diff --git a/modules/system/flake-overrides.nix b/modules/system/flake-overrides.nix
deleted file mode 100644
index df3eb16..0000000
--- a/modules/system/flake-overrides.nix
+++ /dev/null
@@ -1,20 +0,0 @@
-{ lib, inputs, ... }:
-
-with lib;
-
-let
- inherit (inputs) darwin nixpkgs;
-in
-
-{
- config = {
- system.checks.verifyNixPath = mkDefault false;
- system.checks.verifyNixChannels = mkDefault false;
-
- system.darwinVersionSuffix = ".${darwin.shortRev or "dirty"}";
- system.darwinRevision = mkIf (darwin ? rev) darwin.rev;
-
- system.nixpkgsVersionSuffix = ".${substring 0 8 (nixpkgs.lastModifiedDate or nixpkgs.lastModified or "19700101")}.${nixpkgs.shortRev or "dirty"}";
- system.nixpkgsRevision = mkIf (nixpkgs ? rev) nixpkgs.rev;
- };
-}
diff --git a/modules/system/version.nix b/modules/system/version.nix
index 6801918..e45f667 100644
--- a/modules/system/version.nix
+++ b/modules/system/version.nix
@@ -1,4 +1,4 @@
-{ options, config, lib, pkgs, ... }:
+{ options, config, lib, ... }:
with lib;
@@ -7,27 +7,28 @@ let
defaultStateVersion = options.system.stateVersion.default;
- parseGit = path:
- if pathExists "${path}/.git" then rec {
- rev = commitIdFromGitRepo "${path}/.git";
- shortRev = substring 0 7 rev;
- }
- else if pathExists "${path}/.git-revision" then rec {
- rev = fileContents "${path}/.git-revision";
- shortRev = substring 0 7 rev;
- }
- else {
- shortRev = "0000000";
- };
-
- darwin = parseGit (toString ../..);
- nixpkgs = parseGit (toString pkgs.path);
-
- releaseFile = "${toString pkgs.path}/.version";
- suffixFile = "${toString pkgs.path}/.version-suffix";
-
- nixpkgsSuffix = if pathExists suffixFile then fileContents suffixFile
- else ".git." + nixpkgs.shortRev;
+ # 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));
in
{
@@ -56,62 +57,67 @@ in
system.darwinVersion = mkOption {
internal = true;
type = types.str;
- description = lib.mdDoc "The full darwin version (e.g. `darwin4.master`).";
+ default = "darwin${toString cfg.stateVersion}${cfg.darwinVersionSuffix}";
+ description = lib.mdDoc "The full darwin version (e.g. `darwin4.2abdb5a`).";
};
system.darwinVersionSuffix = mkOption {
internal = true;
type = types.str;
+ default = if cfg.darwinRevision != null
+ then ".${substring 0 7 cfg.darwinRevision}"
+ else "";
description = lib.mdDoc "The short darwin version suffix (e.g. `.2abdb5a`).";
};
system.darwinRevision = mkOption {
internal = true;
- type = types.str;
- default = "master";
+ type = types.nullOr types.str;
+ default = gitRevision (toString ../..);
description = lib.mdDoc "The darwin git revision from which this configuration was built.";
};
system.nixpkgsRelease = mkOption {
readOnly = true;
type = types.str;
+ default = lib.trivial.release;
description = lib.mdDoc "The nixpkgs release (e.g. `16.03`).";
};
system.nixpkgsVersion = mkOption {
internal = true;
type = types.str;
+ default = cfg.nixpkgsRelease + cfg.nixpkgsVersionSuffix;
description = lib.mdDoc "The full nixpkgs version (e.g. `16.03.1160.f2d4ee1`).";
};
system.nixpkgsVersionSuffix = mkOption {
internal = true;
type = types.str;
+ default = if useSourceRevision
+ then ".${lib.substring 0 8 (nixpkgsSrc.lastModifiedDate or nixpkgsSrc.lastModified or "19700101")}.${nixpkgsSrc.shortRev or "dirty"}"
+ else lib.trivial.versionSuffix;
description = lib.mdDoc "The short nixpkgs version suffix (e.g. `.1160.f2d4ee1`).";
};
system.nixpkgsRevision = mkOption {
internal = true;
- type = types.str;
+ type = types.nullOr types.str;
+ default = if useSourceRevision && nixpkgsSrc ? rev
+ then nixpkgsSrc.rev
+ else lib.trivial.revisionWithDefault null;
description = lib.mdDoc "The nixpkgs git revision from which this configuration was built.";
};
};
config = {
-
- # These defaults are set here rather than up there so that
- # changing them would not rebuild the manual
+ # This default is set here rather than up there so that the options
+ # documentation is not reprocessed on every commit
system.darwinLabel = mkDefault "${cfg.nixpkgsVersion}+${cfg.darwinVersion}";
- system.darwinVersion = mkDefault "darwin${toString cfg.stateVersion}${cfg.darwinVersionSuffix}";
- system.darwinVersionSuffix = mkDefault ".${darwin.shortRev}";
- system.darwinRevision = mkIf (darwin ? rev) (mkDefault darwin.rev);
-
- system.nixpkgsVersion = mkDefault "${cfg.nixpkgsRelease}${cfg.nixpkgsVersionSuffix}";
- system.nixpkgsRelease = mkDefault (fileContents releaseFile);
- system.nixpkgsVersionSuffix = mkDefault nixpkgsSuffix;
- system.nixpkgsRevision = mkIf (nixpkgs ? rev) (mkDefault nixpkgs.rev);
-
- assertions = [ { assertion = cfg.stateVersion <= defaultStateVersion; message = "system.stateVersion = ${toString cfg.stateVersion}; is not a valid value"; } ];
+ assertions = [ {
+ assertion = cfg.stateVersion <= defaultStateVersion;
+ message = "system.stateVersion = ${toString cfg.stateVersion}; is not a valid value";
+ } ];
};
}