buildDotnetModule: exclude sdk-specific packages in fetch-deps result

This commit is contained in:
mdarocha 2022-07-15 16:54:02 +02:00
parent 886280e8a9
commit a3fff0c947
3 changed files with 15 additions and 3 deletions

View File

@ -134,7 +134,9 @@ in stdenvNoCC.mkDerivation (args // {
passthru = {
inherit nuget-source;
fetch-deps = writeScript "fetch-${pname}-deps" ''
fetch-deps = let
exclusions = dotnet-sdk.passthru.packages { fetchNuGet = attrs: attrs.pname; };
in writeScript "fetch-${pname}-deps" ''
set -euo pipefail
cd "$(dirname "''${BASH_SOURCE[0]}")"
@ -164,8 +166,10 @@ in stdenvNoCC.mkDerivation (args // {
${lib.optionalString (dotnetFlags != []) (builtins.toString dotnetFlags)}
done
echo "${lib.concatStringsSep "\n" exclusions}" > "$HOME/package_exclusions"
echo "Writing lockfile..."
${nuget-to-nix}/bin/nuget-to-nix "$HOME/nuget_pkgs" > "$deps_file"
${nuget-to-nix}/bin/nuget-to-nix "$HOME/nuget_pkgs" "$HOME/package_exclusions" > "$deps_file"
echo "Succesfully wrote lockfile to: $deps_file"
'';
} // args.passthru or {};

View File

@ -8,6 +8,7 @@
, gnused
, jq
, curl
, gnugrep
}:
runCommandLocal "nuget-to-nix" {
@ -22,6 +23,7 @@ runCommandLocal "nuget-to-nix" {
gnused
jq
curl
gnugrep
];
};

View File

@ -5,11 +5,12 @@ set -euo pipefail
export PATH="@binPath@"
if [ $# -eq 0 ]; then
>&2 echo "Usage: $0 [packages directory] > deps.nix"
>&2 echo "Usage: $0 <packages directory> [path to file with a list of excluded packages] > deps.nix"
exit 1
fi
pkgs=$1
exclusions=$2
tmpfile=$(mktemp /tmp/nuget-to-nix.XXXXXX)
trap "rm -f ${tmpfile}" EXIT
@ -21,6 +22,11 @@ while read pkg_spec; do
{ read pkg_name; read pkg_version; } < <(
# Build version part should be ignored: `3.0.0-beta2.20059.3+77df2220` -> `3.0.0-beta2.20059.3`
sed -nE 's/.*<id>([^<]*).*/\1/p; s/.*<version>([^<+]*).*/\1/p' "$pkg_spec")
if grep "$pkg_name" "$exclusions" > /dev/null; then
continue
fi
pkg_sha256="$(nix-hash --type sha256 --flat --base32 "$(dirname "$pkg_spec")"/*.nupkg)"
pkg_src="$(jq --raw-output '.source' "$(dirname "$pkg_spec")/.nupkg.metadata")"