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