From c693cb8ec6ddb76f0195cafe61399500459ad5b7 Mon Sep 17 00:00:00 2001 From: David McFarland Date: Sun, 8 Sep 2024 21:34:04 -0300 Subject: [PATCH] addNuGetDeps: move TMPDIR handling out of fetch-deps We now handle creating TMPDIR and setting the working directory outide of nix-shell. This allows nix-shell to set NIX_BUILD_TOP correctly. --- .../dotnet/add-nuget-deps/default.nix | 7 ++++++- .../dotnet/add-nuget-deps/fetch-deps.sh | 20 +++++++++---------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/pkgs/build-support/dotnet/add-nuget-deps/default.nix b/pkgs/build-support/dotnet/add-nuget-deps/default.nix index afa68b0b92b5..51a7a7c2ace6 100644 --- a/pkgs/build-support/dotnet/add-nuget-deps/default.nix +++ b/pkgs/build-support/dotnet/add-nuget-deps/default.nix @@ -79,7 +79,12 @@ attrs in writeShellScript "${finalPackage.name}-fetch-deps" '' - NIX_BUILD_SHELL="${runtimeShell}" exec ${nix}/bin/nix-shell \ + set -eu + export TMPDIR + TMPDIR=$(mktemp -d -t fetch-deps-${finalPackage.name}.XXXXXX) + trap 'chmod -R +w "$TMPDIR" && rm -fr "$TMPDIR"' EXIT + cd "$TMPDIR" + NIX_BUILD_SHELL="${runtimeShell}" {nix}/bin/nix-shell \ --pure --run 'source "${innerScript}"' "${drv}" ''; }; diff --git a/pkgs/build-support/dotnet/add-nuget-deps/fetch-deps.sh b/pkgs/build-support/dotnet/add-nuget-deps/fetch-deps.sh index 7891b5434c13..73963824646d 100644 --- a/pkgs/build-support/dotnet/add-nuget-deps/fetch-deps.sh +++ b/pkgs/build-support/dotnet/add-nuget-deps/fetch-deps.sh @@ -1,20 +1,18 @@ set -e -tmp=$(mktemp -d) -trap 'chmod -R +w "$tmp" && rm -fr "$tmp"' EXIT - -HOME=$tmp/.home -export TMPDIR="$tmp/.tmp" -mkdir "$HOME" "$TMPDIR" -cd "$tmp" +HOME=$NIX_BUILD_TOP/home +mkdir "$HOME" export NIX_SSL_CERT_FILE=@cacert@/etc/ssl/certs/ca-bundle.crt genericBuild depsFile=$(realpath "${1:-@defaultDepsFile@}") -tmpFile="$tmp"/deps.nix -echo -e "# This file was automatically generated by passthru.fetch-deps.\n# Please dont edit it manually, your changes might get overwritten!\n" > "$tmpFile" -@nugetToNix@/bin/nuget-to-nix "${NUGET_PACKAGES%/}" >> "$tmpFile" -mv "$tmpFile" "$depsFile" + +( + echo -e "# This file was automatically generated by passthru.fetch-deps.\n# Please dont edit it manually, your changes might get overwritten!\n" + @nugetToNix@/bin/nuget-to-nix "${NUGET_PACKAGES%/}" +) > deps.nix + +mv deps.nix "$depsFile" echo "Succesfully wrote lockfile to $depsFile"