@@ -1,3 +1,18 @@
1+# copied from libgit2 source code 'repo-template.h'
2+makeGitTemplate() {
3+ local target="$1"
4+ mkdir -p -m777 "$target/info" "$target/pack" "$target/objects" "$target/refs"
5+ mkdir -p -m777 "$target/refs/heads" "$target/refs/tags" "$target/objects/info" "$target/objects/pack"
6+ cat <<'EOF' > "$target/description"
7+Unnamed repository; edit this file 'description' to name the repository.
8+EOF
9+ chmod 666 "$target/description"
10+ cat <<'EOF' > "$target/info/exclude"
11+# File patterns to ignore; see `git help ignore` for more information.
12+# Lines that start with '#' are comments.
13+EOF
14+}
15+
116fetchCargoDeps() {
217 src=$(realpath $1)
318 out=$(realpath $2)
@@ -6,6 +21,23 @@ fetchCargoDeps() {
621
722 mkdir $out
823
24+ # Configure git template dir to make libgit2 more deterministic
25+ #
26+ # Without a template dir, libgit2 defaults to /usr/share/git-core/templates,
27+ # which can vary between systems if sandboxed builds aren't used.
28+ #
29+ # Note: we explictly set --tmpdir for mktemp here to make it more friendly
30+ # for nix-shell users, where $TMPDIR is not necessarily set to NIX_BUILD_TOP
31+ echo "Setting up git templatedir"
32+ export GIT_TEMPLATE_DIR="$(mktemp -d --tmpdir=$NIX_BUILD_TOP git-template.XXX)"
33+ makeGitTemplate "$GIT_TEMPLATE_DIR"
34+ export XDG_CONFIG_HOME="$(mktemp -d --tmpdir=$NIX_BUILD_TOP home.XXX)"
35+ mkdir -p $XDG_CONFIG_HOME/git
36+ cat <<EOF > $XDG_CONFIG_HOME/git/config
37+[init]
38+ templatedir = $GIT_TEMPLATE_DIR
39+EOF
40+
941 # Configure cargo to fetch from a local copy of the crates.io registry
1042
1143 echo "Using rust registry from $rustRegistry"