Try to fetchGit the provided src

The goal is to filter the provided src tree based on Git tracked files
to avoid unexpected rebuild. If the provided src tree is a not valid Git
repository, no filtering is applied.
This commit is contained in:
Antoine Eiche 2020-06-16 11:14:17 +02:00
parent f012cc5092
commit 2c2a50af4d

View file

@ -54,8 +54,19 @@ let
assert flake.edition == 201909;
outputs;
src' =
(if src ? outPath then src else { outPath = src; })
src' = let
dir = builtins.readDir src;
gitDir = builtins.readDir (src + "/.git");
isGitDir = dir ? ".git" && dir.".git" == "directory";
isNotShallow = ! gitDir ? "shallow";
# Try to clean the source tree by using fetchGit, if this source
# tree is a valid git repository.
tryFetchGit = src:
if isGitDir && isNotShallow
then builtins.fetchGit src
else { outPath = src; };
in
(if src ? outPath then src else tryFetchGit src)
// { lastModified = 0; lastModifiedDate = formatSecondsSinceEpoch 0; };
# Format number of seconds in the Unix epoch as %Y%m%d%H%M%S.