From c94c5087cc19cc8339e2c4b3e7a1546f6e990fcc Mon Sep 17 00:00:00 2001 From: GGG Date: Thu, 5 Dec 2024 19:41:20 -0300 Subject: [PATCH] buildDotnetModule.fetch-deps: use json lockfiles by default --- .../dotnet/add-nuget-deps/default.nix | 8 +++-- .../dotnet/add-nuget-deps/fetch-deps.sh | 31 ++++++++++++++----- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/pkgs/build-support/dotnet/add-nuget-deps/default.nix b/pkgs/build-support/dotnet/add-nuget-deps/default.nix index b47a5b427cb4..38ed44cdc772 100644 --- a/pkgs/build-support/dotnet/add-nuget-deps/default.nix +++ b/pkgs/build-support/dotnet/add-nuget-deps/default.nix @@ -6,6 +6,7 @@ substituteAll, nuget-to-nix, nixfmt-rfc-style, + nuget-to-json, cacert, fetchNupkg, callPackage, @@ -87,8 +88,11 @@ attrs src = ./fetch-deps.sh; isExecutable = true; inherit cacert; - nugetToNix = nuget-to-nix; - nixfmt = nixfmt-rfc-style; + binPath = lib.makeBinPath [ + nuget-to-nix + nixfmt-rfc-style + nuget-to-json + ]; }; defaultDepsFile = 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 4ffba4783677..809f5c4b26d8 100644 --- a/pkgs/build-support/dotnet/add-nuget-deps/fetch-deps.sh +++ b/pkgs/build-support/dotnet/add-nuget-deps/fetch-deps.sh @@ -1,13 +1,28 @@ -set -e +# shellcheck shell=bash +set -euo pipefail + +export PATH="@binPath@:$PATH" + +LOCKFILE_OUTPUT="$1" genericBuild -( - 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 +nuget-to-json "${NUGET_PACKAGES%/}" >deps.json -@nixfmt@/bin/nixfmt deps.nix +if [[ "$LOCKFILE_OUTPUT" == *.nix ]]; then + trap 'rm deps.json' exit -mv deps.nix "$1" -echo "Succesfully wrote lockfile to $1" + ( + echo "# This file was automatically generated by passthru.fetch-deps." + echo "# Please dont edit it manually, your changes might get overwritten!" + echo -e "# TODO: This format file is obsolete, consider migrating to JSON.\n" + nuget-to-nix --convert deps.json + ) >deps.nix + nixfmt deps.nix + + mv deps.nix "$LOCKFILE_OUTPUT" +else + mv deps.json "$LOCKFILE_OUTPUT" +fi + +echo "Succesfully wrote lockfile to $LOCKFILE_OUTPUT"