2024-05-02 00:46:19 +00:00
|
|
|
{
|
|
|
|
runCommand,
|
|
|
|
git,
|
|
|
|
lib,
|
|
|
|
}:
|
|
|
|
|
|
|
|
lib.makeOverridable (
|
|
|
|
src:
|
2024-06-30 08:16:52 +00:00
|
|
|
|
2024-05-02 00:46:19 +00:00
|
|
|
let
|
|
|
|
srcStr = toString src;
|
2024-06-30 08:16:52 +00:00
|
|
|
|
2024-05-02 00:46:19 +00:00
|
|
|
# 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
|
2024-06-30 08:16:52 +00:00
|
|
|
|
2024-05-02 00:46:19 +00:00
|
|
|
cp $DOT_GIT/index $DOT_GIT/index-user # backup index
|
|
|
|
git reset # reset index
|
|
|
|
git add . # add current directory
|
2024-06-30 08:16:52 +00:00
|
|
|
|
2024-05-02 00:46:19 +00:00
|
|
|
# hash of current directory
|
|
|
|
# remove trailing newline
|
|
|
|
git rev-parse $(git write-tree) \
|
|
|
|
| tr -d '\n' > $out
|
2024-06-30 08:16:52 +00:00
|
|
|
|
2024-05-02 00:46:19 +00:00
|
|
|
mv $DOT_GIT/index-user $DOT_GIT/index # restore index
|
|
|
|
'';
|
2024-06-30 08:16:52 +00:00
|
|
|
|
2024-05-02 00:46:19 +00:00
|
|
|
gitHash = builtins.readFile gitHashFile; # cache against git hash
|
2024-06-30 08:16:52 +00:00
|
|
|
|
2024-05-02 00:46:19 +00:00
|
|
|
nixPath =
|
|
|
|
runCommand "put-in-nix"
|
|
|
|
{
|
|
|
|
nativeBuildInputs = [ git ];
|
|
|
|
preferLocalBuild = true;
|
|
|
|
}
|
|
|
|
''
|
|
|
|
mkdir $out
|
2024-06-30 08:16:52 +00:00
|
|
|
|
2024-05-02 00:46:19 +00:00
|
|
|
# dump tar of *current directory* at given revision
|
|
|
|
git -C ${srcStr} archive --format=tar ${gitHash} \
|
|
|
|
| tar xf - -C $out
|
|
|
|
'';
|
2024-06-30 08:16:52 +00:00
|
|
|
|
2024-05-02 00:46:19 +00:00
|
|
|
in
|
|
|
|
nixPath
|
|
|
|
)
|