at v206 40 lines 1.1 kB view raw
1{ runCommand, git, nix }: src: 2 3let 4 srcStr = toString src; 5 6 # Adds the current directory (respecting ignored files) to the git store, and returns the hash 7 gitHashFile = runCommand "put-in-git" { 8 nativeBuildInputs = [ git ]; 9 dummy = builtins.currentTime; # impure, do every time 10 preferLocalBuild = true; 11 } '' 12 cd ${srcStr} 13 ROOT=$(git rev-parse --show-toplevel) # path to repo 14 15 cp $ROOT/.git/index $ROOT/.git/index-user # backup index 16 git reset # reset index 17 git add . # add current directory 18 19 # hash of current directory 20 # remove trailing newline 21 git rev-parse $(git write-tree) \ 22 | tr -d '\n' > $out 23 24 mv $ROOT/.git/index-user $ROOT/.git/index # restore index 25 ''; 26 27 gitHash = builtins.readFile gitHashFile; # cache against git hash 28 29 nixPath = runCommand "put-in-nix" { 30 nativeBuildInputs = [ git ]; 31 preferLocalBuild = true; 32 } '' 33 mkdir $out 34 35 # dump tar of *current directory* at given revision 36 git -C ${srcStr} archive --format=tar ${gitHash} \ 37 | tar xvf - -C $out 38 ''; 39 40in nixPath