about summary refs log tree commit diff
path: root/lib
diff options
context:
space:
mode:
authorFranz Pletz <fpletz@fnordicwalking.de>2020-01-24 14:58:31 +0000
committerGitHub <noreply@github.com>2020-01-24 14:58:31 +0000
commit402b97fa1ecae97cbbce7211de3e754b347a4a60 (patch)
treee35433a8f24aa487ed7498d0dc647caa70de9bef /lib
parent2a8ad18258d3cf839e9e1a57994822d9c523a72e (diff)
parent46773a15b3af302c3fb2a6e31fb589553a903099 (diff)
downloadnixlib-402b97fa1ecae97cbbce7211de3e754b347a4a60.tar
nixlib-402b97fa1ecae97cbbce7211de3e754b347a4a60.tar.gz
nixlib-402b97fa1ecae97cbbce7211de3e754b347a4a60.tar.bz2
nixlib-402b97fa1ecae97cbbce7211de3e754b347a4a60.tar.lz
nixlib-402b97fa1ecae97cbbce7211de3e754b347a4a60.tar.xz
nixlib-402b97fa1ecae97cbbce7211de3e754b347a4a60.tar.zst
nixlib-402b97fa1ecae97cbbce7211de3e754b347a4a60.zip
Merge pull request #78058 from mayflower/nixos/version-gitdir-symlink
nixos/version: fix case where .git is a symlink
Diffstat (limited to 'lib')
-rw-r--r--lib/default.nix2
-rw-r--r--lib/sources.nix1
-rw-r--r--lib/trivial.nix2
3 files changed, 3 insertions, 2 deletions
diff --git a/lib/default.nix b/lib/default.nix
index 5abafe1b2acf..d2e9f0e8086c 100644
--- a/lib/default.nix
+++ b/lib/default.nix
@@ -101,7 +101,7 @@ let
     inherit (sources) pathType pathIsDirectory cleanSourceFilter
       cleanSource sourceByRegex sourceFilesBySuffices
       commitIdFromGitRepo cleanSourceWith pathHasContext
-      canCleanSource pathIsRegularFile;
+      canCleanSource pathIsRegularFile pathIsGitRepo;
     inherit (modules) evalModules unifyModuleSyntax
       applyIfFunction mergeModules
       mergeModules' mergeOptionDecls evalOptionValue mergeDefinitions
diff --git a/lib/sources.nix b/lib/sources.nix
index a5765c0fda5b..05519c3e392e 100644
--- a/lib/sources.nix
+++ b/lib/sources.nix
@@ -105,6 +105,7 @@ rec {
       in type == "directory" || lib.any (ext: lib.hasSuffix ext base) exts;
     in cleanSourceWith { inherit filter; src = path; };
 
+  pathIsGitRepo = path: (builtins.tryEval (commitIdFromGitRepo path)).success;
 
   # Get the commit id of a git repo
   # Example: commitIdFromGitRepo <nixpkgs/.git>
diff --git a/lib/trivial.nix b/lib/trivial.nix
index 940ec1a3d59e..a281cd70fb0e 100644
--- a/lib/trivial.nix
+++ b/lib/trivial.nix
@@ -191,7 +191,7 @@ rec {
     let
       revisionFile = "${toString ./..}/.git-revision";
       gitRepo      = "${toString ./..}/.git";
-    in if builtins.pathExists gitRepo
+    in if lib.pathIsGitRepo gitRepo
        then lib.commitIdFromGitRepo gitRepo
        else if lib.pathExists revisionFile then lib.fileContents revisionFile
        else default;