2015-04-01 04:58:19 +02:00
|
|
|
{ runCommand, git, nix }: src:
|
2015-03-28 20:57:54 +01:00
|
|
|
|
2015-10-02 06:58:24 +02:00
|
|
|
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}
|
2016-01-05 00:08:45 +01:00
|
|
|
DOT_GIT=$(git rev-parse --resolve-git-dir .git) # path to repo
|
2015-10-02 06:58:24 +02:00
|
|
|
|
2016-01-05 00:08:45 +01:00
|
|
|
cp $DOT_GIT/index $DOT_GIT/index-user # backup index
|
2015-10-02 06:58:24 +02:00
|
|
|
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
|
|
|
|
|
2016-01-05 00:08:45 +01:00
|
|
|
mv $DOT_GIT/index-user $DOT_GIT/index # restore index
|
2015-10-02 06:58:24 +02:00
|
|
|
'';
|
|
|
|
|
|
|
|
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} \
|
2016-02-01 19:56:12 +01:00
|
|
|
| tar xf - -C $out
|
2015-10-02 06:58:24 +02:00
|
|
|
'';
|
|
|
|
|
|
|
|
in nixPath
|