fetchgit: Support sparse checkout#135881
Conversation
|
Result of 15 packages built successfully:
Result of 14 packages built successfully:
|
|
Looks useful, could you add documentation for it too? https://nixos.org/manual/nixpkgs/stable/#fetchgit Should something be added to fetchFromGitHub to make it possible to use this with it? |
|
Could you add a test case in |
|
Could you please give some tips about how to write and run tests? I read https://nixos.org/manual/nixpkgs/stable/#sec-package-tests, but can not figure out. |
|
Package tests are different to fetcher tests https://nixos.org/manual/nixpkgs/unstable/#sec-pkgs-invalidateFetcherByDrvHash example in this pr #138869 |
|
Originally I introduced an extra attribute for the purpose of running the tests, but in the end I cut it because it shouldn't be necessary. You can run them from or Neither of these run all tests though, so maybe |
|
Test case added, anything else need to be done? |
roberth
left a comment
There was a problem hiding this comment.
Just a question and a comment. Otherwise, LGTM.
There was a problem hiding this comment.
Did you consider using git sparse-checkout set --stdin?
There was a problem hiding this comment.
This doesn't seem necessary. If you want to make it "correct" you could use printf %q, but the real solution is to replace this code by something simple, like a loop that pops arguments using shift.
I'll ignore it for now.
There was a problem hiding this comment.
This is necessary because --sparse-checkout arg may contain "\n", without this change, the following test fails.
~/src/nixpkgs master* ⇣⇡
❯ git diff
diff --git a/pkgs/build-support/fetchgit/nix-prefetch-git b/pkgs/build-support/fetchgit/nix-prefetch-git
index f940d10b2ae..be595e59b0c 100755
--- a/pkgs/build-support/fetchgit/nix-prefetch-git
+++ b/pkgs/build-support/fetchgit/nix-prefetch-git
@@ -98,7 +98,7 @@ for arg; do
case $argfun in
set_*)
var=${argfun#set_}
- eval $var="\"$arg\""
+ eval $var=$arg
;;
esac
argfun=""
~/src/nixpkgs master* ⇣⇡
❯ nix repl .
Welcome to Nix version 2.5pre20211007_844dd90. Type :? for help.
Loading '.'...
Added 15361 variables.
nix-repl> :b fetchgit.tests.sparseCheckout
error: builder for '/nix/store/cnh4q2g2vmxl6l4cjq28677hqdxrwxbx-nix-source-salted-bydqcp0cva5n.drv' failed with exit code 127;
last 2 log lines:
> exporting https://github.com/NixOS/nix (rev 9d9dbe6ed05854e03811c361a3380e09183f4f4a) into /nix/store/yw6ycpfg088q7jswqjgjj19724drl3ji-nix-source-salted-bydqcp0cva5n
> /nix/store/k4wdi6yqznx8qww12v715sz46vd4p1jf-nix-prefetch-git: line 101: tests: command not found
For full logs, run 'nix log /nix/store/cnh4q2g2vmxl6l4cjq28677hqdxrwxbx-nix-source-salted-bydqcp0cva5n.drv'.
The tests comes from:
sparseCheckout = ''
src
tests
'';
eval without quote leads to code injection.
There was a problem hiding this comment.
How about something like eval "$var=$(printf %q "$arg")"
It could also append to the previous value, so it can be used multiple times on the command line. I guess that'd be append_* although I think the argument parsing should be turned into a simple loop that consumes one or more arguments per iteration. Much simpler than this weird state machine business.
|
Please review the new changes. |
roberth
left a comment
There was a problem hiding this comment.
I'll ignore the preexisting problem of the overcomplicated argument parsing and consider this PR an incremental improvement.
SuperSandro2000
left a comment
There was a problem hiding this comment.
Can we forward that option to the various fetchFrom*?
This allow git checkout small parts of a large repo, and avoid fetching unnecessary blobs from server.
|
Rebase to master, add fetchFromGitHub. |
|
@ofborg build tests.fetchgit tests.fetchFromGitHub |
|
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: |
Motivation for this change
This allow git checkout small parts of a large repo, and avoid fetching
unnecessary blobs from server.
For example, the nerd-fonts git repo, even with
--depth=1, need network transfer > 2G. Using sparse checkout andpartialclonefilter "blob:none", we can fetch a subdir for < 20M:Things done
sandbox = trueset innix.conf? (See Nix manual)nix-shell -p nixpkgs-review --run "nixpkgs-review wip"./result/bin/)