summary refs log tree commit diff
path: root/pkgs/build-support/dotnet
diff options
context:
space:
mode:
authorDavid McFarland <corngood@gmail.com>2022-09-26 12:28:58 -0300
committerDavid McFarland <corngood@gmail.com>2022-10-02 16:09:24 -0300
commit4b40579b2d3758e5940cf33602001bfe1d44f230 (patch)
treeb643f03e799eb511bb0921304a70e04580deac0d /pkgs/build-support/dotnet
parente295c223cd6706aec0d7c498cd39272e23605e52 (diff)
downloadnixpkgs-4b40579b2d3758e5940cf33602001bfe1d44f230.tar
nixpkgs-4b40579b2d3758e5940cf33602001bfe1d44f230.tar.gz
nixpkgs-4b40579b2d3758e5940cf33602001bfe1d44f230.tar.bz2
nixpkgs-4b40579b2d3758e5940cf33602001bfe1d44f230.tar.lz
nixpkgs-4b40579b2d3758e5940cf33602001bfe1d44f230.tar.xz
nixpkgs-4b40579b2d3758e5940cf33602001bfe1d44f230.tar.zst
nixpkgs-4b40579b2d3758e5940cf33602001bfe1d44f230.zip
build-dotnet-module: clean up tmp file handling
Having:

rm -rf "$src" "$HOME"

Was slightly terrifying IMO, especially where the trap was installed
before HOME was set.
Diffstat (limited to 'pkgs/build-support/dotnet')
-rw-r--r--pkgs/build-support/dotnet/build-dotnet-module/default.nix18
1 files changed, 10 insertions, 8 deletions
diff --git a/pkgs/build-support/dotnet/build-dotnet-module/default.nix b/pkgs/build-support/dotnet/build-dotnet-module/default.nix
index b65aecd7e05..54d03bc242b 100644
--- a/pkgs/build-support/dotnet/build-dotnet-module/default.nix
+++ b/pkgs/build-support/dotnet/build-dotnet-module/default.nix
@@ -188,14 +188,17 @@ stdenvNoCC.mkDerivation (args // {
             esac
         done
 
+        export tmp=$(mktemp -td "${pname}-tmp-XXXXXX")
+        HOME=$tmp/home
+
         exitTrap() {
             test -n "''${ranTrap-}" && return
             ranTrap=1
 
             if test -n "''${keepSources-}"; then
-                echo -e "Path to the source: $src\nPath to the fake home: $HOME"
+                echo -e "Path to the source: $tmp/src\nPath to the fake home: $tmp/home"
             else
-                rm -rf "$src" "$HOME"
+                rm -rf "$tmp"
             fi
 
             # Since mktemp is used this will be empty if the script didnt succesfully complete
@@ -211,7 +214,7 @@ stdenvNoCC.mkDerivation (args // {
             dotnet restore ''${project-} \
                 -p:ContinuousIntegrationBuild=true \
                 -p:Deterministic=true \
-                --packages "$HOME/nuget_pkgs" \
+                --packages "$tmp/nuget_pkgs" \
                 --runtime "$rid" \
                 ${lib.optionalString (!enableParallelBuilding) "--disable-parallel"} \
                 ${lib.optionalString (flags != []) (toString flags)}
@@ -220,15 +223,14 @@ stdenvNoCC.mkDerivation (args // {
         declare -a projectFiles=( ${toString (lib.toList projectFile)} )
         declare -a testProjectFiles=( ${toString (lib.toList testProjectFile)} )
 
-        export HOME=$(mktemp -td "${pname}-home-XXXXXX")
         export DOTNET_NOLOGO=1
         export DOTNET_CLI_TELEMETRY_OPTOUT=1
 
-        depsFile="$(realpath "''${1:-$(mktemp -t "${pname}-deps-XXXXXX.nix")}")"
-        mkdir -p "$HOME/nuget_pkgs"
+        depsFile=$(realpath "''${1:-$(mktemp -t "${pname}-deps-XXXXXX.nix")}")
+        mkdir -p "$tmp/nuget_pkgs"
 
         storeSrc="${srcOnly args}"
-        src="$(mktemp -td "${pname}-src-XXXXXX")"
+        src=$tmp/src
         cp -rT "$storeSrc" "$src"
         chmod -R +w "$src"
 
@@ -247,7 +249,7 @@ stdenvNoCC.mkDerivation (args // {
 
         echo "Writing lockfile..."
         echo -e "# This file was automatically generated by passthru.fetch-deps.\n# Please dont edit it manually, your changes might get overwritten!\n" > "$depsFile"
-        nuget-to-nix "$HOME/nuget_pkgs" "${exclusions}" >> "$depsFile"
+        nuget-to-nix "$tmp/nuget_pkgs" "${exclusions}" >> "$depsFile"
         echo "Succesfully wrote lockfile to $depsFile"
       '';
   } // args.passthru or { };