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