diff options
-rw-r--r-- | lib/trivial.nix | 10 | ||||
-rw-r--r-- | nixos/modules/misc/version.nix | 5 |
2 files changed, 11 insertions, 4 deletions
diff --git a/lib/trivial.nix b/lib/trivial.nix index b1eea0bf1247..938df6ced476 100644 --- a/lib/trivial.nix +++ b/lib/trivial.nix @@ -105,6 +105,16 @@ rec { then lib.strings.fileContents suffixFile else "pre-git"; + # Attempt to get the revision nixpkgs is from + revisionWithDefault = default: + let + revisionFile = "${toString ./..}/.git-revision"; + gitRepo = "${toString ./..}/.git"; + in if lib.pathIsDirectory gitRepo + then lib.commitIdFromGitRepo gitRepo + else if lib.pathExists revisionFile then lib.fileContents revisionFile + else default; + nixpkgsVersion = builtins.trace "`lib.nixpkgsVersion` is deprecated, use `lib.version` instead!" version; # Whether we're being called by nix-shell. diff --git a/nixos/modules/misc/version.nix b/nixos/modules/misc/version.nix index c593adcdae6e..6d78b7c593f8 100644 --- a/nixos/modules/misc/version.nix +++ b/nixos/modules/misc/version.nix @@ -5,7 +5,6 @@ with lib; let cfg = config.system.nixos; - revisionFile = "${toString pkgs.path}/.git-revision"; gitRepo = "${toString pkgs.path}/.git"; gitCommitId = lib.substring 0 7 (commitIdFromGitRepo gitRepo); in @@ -37,9 +36,7 @@ in nixos.revision = mkOption { internal = true; type = types.str; - default = if pathIsDirectory gitRepo then commitIdFromGitRepo gitRepo - else if pathExists revisionFile then fileContents revisionFile - else "master"; + default = lib.trivial.revisionWithDefault "master"; description = "The Git revision from which this NixOS configuration was built."; }; |