Skip to content

Commit

Permalink
addNuGetDeps: fix fetch-deps output path handling
Browse files Browse the repository at this point in the history
  • Loading branch information
corngood committed Sep 17, 2024
1 parent 988b57f commit 424bbc4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
31 changes: 18 additions & 13 deletions pkgs/build-support/dotnet/add-nuget-deps/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -66,27 +66,32 @@ attrs
src = ./fetch-deps.sh;
isExecutable = true;
inherit cacert;
defaultDepsFile =
# Wire in the depsFile such that running the script with no args
# runs it agains the correct deps file by default.
# 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.isStorePath nugetDeps then
toString nugetDeps
else
''$(mktemp -t "${finalAttrs.pname or finalPackage.name}-deps-XXXXXX.nix")'';
nugetToNix = nuget-to-nix;
};

defaultDepsFile =
# Wire in the depsFile such that running the script with no args
# runs it agains the correct deps file by default.
# 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.isStorePath nugetDeps then
toString nugetDeps
else
''$(mktemp -t "${finalAttrs.pname or finalPackage.name}-deps-XXXXXX.nix")'';

in
writeShellScript "${finalPackage.name}-fetch-deps" ''
set -eu
echo 'fetching dependencies for' ${lib.escapeShellArg finalPackage.name} >&2
# this needs to be before TMPDIR is changed, so the output isn't deleted
# if it uses mktemp
depsFile=$(realpath "''${1:-${lib.escapeShellArg defaultDepsFile}}")
export TMPDIR
TMPDIR=$(mktemp -d -t fetch-deps-${finalPackage.name}.XXXXXX)
TMPDIR=$(mktemp -d -t fetch-deps-${lib.escapeShellArg finalPackage.name}.XXXXXX)
trap 'chmod -R +w "$TMPDIR" && rm -fr "$TMPDIR"' EXIT
export NUGET_HTTP_CACHE_PATH=''${NUGET_HTTP_CACHE_PATH-~/.local/share/NuGet/v3-cache}
Expand All @@ -96,8 +101,8 @@ attrs
cd "$TMPDIR"
NIX_BUILD_SHELL="${runtimeShell}" ${nix}/bin/nix-shell \
--pure --keep NUGET_HTTP_CACHE_PATH --run 'source "${innerScript}"' "${drv}"
NIX_BUILD_SHELL=${lib.escapeShellArg runtimeShell} ${nix}/bin/nix-shell \
--pure --keep NUGET_HTTP_CACHE_PATH --run 'source '${lib.escapeShellArg innerScript}' '"''${depsFile@Q}" "${drv}"
'';
};
}
6 changes: 2 additions & 4 deletions pkgs/build-support/dotnet/add-nuget-deps/fetch-deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ set -e

genericBuild

depsFile=$(realpath "${1:-@defaultDepsFile@}")

(
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"
mv deps.nix "$1"
echo "Succesfully wrote lockfile to $1"

0 comments on commit 424bbc4

Please sign in to comment.