From 09a7ce962dbdf7aca2a0081bf8030a4776c843a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Mon, 26 May 2025 09:27:49 +0200 Subject: [PATCH] flakes: for detected git repository now assume shallow clones by default Shallow clones are faster to access because we don't have to compute the revCount, which in sparse checkouts might not even exists. This is especially useful in combination with lazy trees in mind on large repository such as nixpkgs. --- src/libflake/flakeref.cc | 6 ++++-- tests/functional/fetchGitShallow.sh | 5 +++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/libflake/flakeref.cc b/src/libflake/flakeref.cc index d56f2858f..c9e9a70ef 100644 --- a/src/libflake/flakeref.cc +++ b/src/libflake/flakeref.cc @@ -168,8 +168,10 @@ std::pair parsePathFlakeRefWithFragment( parsedURL.query.insert_or_assign("dir", subdir); } - if (pathExists(flakeRoot + "/.git/shallow")) - parsedURL.query.insert_or_assign("shallow", "1"); + if (!parsedURL.query.count("shallow")) { + // We assume shallow by default, so we don't need to compute the revCount, which is an expensive operation. + parsedURL.query.insert_or_assign("shallow", "1"); + } return fromParsedURL(fetchSettings, std::move(parsedURL), isFlake); } diff --git a/tests/functional/fetchGitShallow.sh b/tests/functional/fetchGitShallow.sh index cf7e5fd4f..7a937d9d1 100644 --- a/tests/functional/fetchGitShallow.sh +++ b/tests/functional/fetchGitShallow.sh @@ -65,3 +65,8 @@ fi # Verify that we can shallow fetch the worktree git -C "$TEST_ROOT/shallow-worktree" rev-list --count HEAD >/dev/null nix eval --impure --raw --expr "(builtins.fetchGit { url = \"file://$TEST_ROOT/shallow-worktree\"; shallow = true; }).rev" + +# Normal flake operation work because they use shallow by default +pushd "$TEST_ROOT/shallow-worktree" +nix flake metadata +popd