at 18.09-beta 40 lines 1.1 kB view raw
1{ runCommand, git }: 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 DOT_GIT=$(git rev-parse --resolve-git-dir .git) # path to repo 14 15 cp $DOT_GIT/index $DOT_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 $DOT_GIT/index-user $DOT_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 xf - -C $out 38 ''; 39 40in nixPath