Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fetchgitlocal: fix permission problem #31937

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
37 changes: 20 additions & 17 deletions pkgs/build-support/fetchgitlocal/default.nix
@@ -1,27 +1,26 @@
{ runCommand, git, nix }: src:

let
tmpFolder = "/tmp/fetchgitlocal-${builtins.toString currentTime}";
currentTime = builtins.currentTime; # impure, do every time

srcStr = toString src;

# Adds the current directory (respecting ignored files) to the git store, and returns the hash
# Adds the current directory in the index (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
dummy = currentTime;
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
# we need write access to update index
cp -r ${srcStr}/.git ${tmpFolder}
chmod a+w ${tmpFolder}
export GIT_DIR=${tmpFolder}

# `tr` to remove trailing newline
res="$(git rev-parse --show-prefix)"
git write-tree --prefix="$res" | tr -d '\n' > $out
'';

gitHash = builtins.readFile gitHashFile; # cache against git hash
Expand All @@ -32,9 +31,13 @@ let
} ''
mkdir $out

# git annoyingly breaks without doing this since the hash does
# not correspond to repo root.
cd $(git -C ${srcStr} rev-parse --show-toplevel)

# dump tar of *current directory* at given revision
git -C ${srcStr} archive --format=tar ${gitHash} \
| tar xf - -C $out
hash="${gitHash}"
git archive --format=tar $hash | tar xv -C $out
'';

in nixPath