summary refs log tree commit diff
path: root/pkgs/build-support/dotnet/build-dotnet-module/default.nix
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/build-support/dotnet/build-dotnet-module/default.nix')
-rw-r--r--pkgs/build-support/dotnet/build-dotnet-module/default.nix22
1 files changed, 15 insertions, 7 deletions
diff --git a/pkgs/build-support/dotnet/build-dotnet-module/default.nix b/pkgs/build-support/dotnet/build-dotnet-module/default.nix
index a9c49d1e526..686d89f8c11 100644
--- a/pkgs/build-support/dotnet/build-dotnet-module/default.nix
+++ b/pkgs/build-support/dotnet/build-dotnet-module/default.nix
@@ -112,7 +112,11 @@ let
     if (nugetDeps != null) then
       if lib.isDerivation nugetDeps
       then nugetDeps
-      else mkNugetDeps { inherit name; nugetDeps = import nugetDeps; }
+      else mkNugetDeps {
+        inherit name;
+        nugetDeps = import nugetDeps;
+        sourceFile = nugetDeps;
+      }
     else throw "Defining the `nugetDeps` attribute is required, as to lock the NuGet dependencies. This file can be generated by running the `passthru.fetch-deps` script.";
 
   # contains the actual package dependencies
@@ -138,6 +142,8 @@ let
     name = "${name}-nuget-source";
     paths = [ dependenciesSource sdkSource ];
   };
+
+  nugetDepsFile = _nugetDeps.sourceFile;
 in
 stdenvNoCC.mkDerivation (args // {
   nativeBuildInputs = args.nativeBuildInputs or [ ] ++ [
@@ -166,7 +172,7 @@ stdenvNoCC.mkDerivation (args // {
 
   passthru = {
     inherit nuget-source;
-
+  } // lib.optionalAttrs (nugetDepsFile != null) {
     fetch-deps =
       let
         flags = dotnetFlags ++ dotnetRestoreFlags;
@@ -180,8 +186,8 @@ stdenvNoCC.mkDerivation (args // {
           # Note that toString is necessary here as it results in the path at
           # eval time (i.e. to the file in your local Nixpkgs checkout) rather
           # than the Nix store path of the path after it's been imported.
-          if lib.isPath nugetDeps && !lib.hasPrefix "${builtins.storeDir}/" (toString nugetDeps)
-          then toString nugetDeps
+          if lib.isPath nugetDepsFile && !lib.hasPrefix "${builtins.storeDir}/" (toString nugetDepsFile)
+          then toString nugetDepsFile
           else ''$(mktemp -t "${pname}-deps-XXXXXX.nix")'';
       in
       writeShellScript "fetch-${pname}-deps" ''
@@ -208,7 +214,7 @@ stdenvNoCC.mkDerivation (args // {
         if [[ ''${TMPDIR:-} == /run/user/* ]]; then
            # /run/user is usually a tmpfs in RAM, which may be too small
            # to store all downloaded dotnet packages
-           TMPDIR=
+           unset TMPDIR
         fi
 
         export tmp=$(mktemp -td "deps-${pname}-XXXXXX")
@@ -281,13 +287,15 @@ stdenvNoCC.mkDerivation (args // {
         echo "Succesfully restored project"
 
         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"
 
         excluded_sources="${lib.concatStringsSep " " sdkDeps}"
         for excluded_source in ''${excluded_sources[@]}; do
           ls "$excluded_source" >> "$tmp/excluded_list"
         done
-        nuget-to-nix "$tmp/nuget_pkgs" "$tmp/excluded_list" >> "$depsFile"
+        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"
+        nuget-to-nix "$tmp/nuget_pkgs" "$tmp/excluded_list" >> "$tmpFile"
+        mv "$tmpFile" "$depsFile"
         echo "Succesfully wrote lockfile to $depsFile"
       '';
   } // args.passthru or { };