buildDotnetModule: add support for using combinePackages as dotnet-sdk This allows packages that require several dotnet versions to build (like BeatSaberModManager) to properly depend on the dotnet-sdk specific deps. This in turns avoids having to regenerate the deps of those packages after each dotnet-sdk update.

This also changes nuget-to-nix to accept a file with a list of
exclusions instead of a folder.

mdarocha d093086a 26ff0e4a

+29 -16
+1 -1
doc/languages-frameworks/dotnet.section.md
··· 88 * `runtimeDeps` is used to wrap libraries into `LD_LIBRARY_PATH`. This is how dotnet usually handles runtime dependencies. 89 * `buildType` is used to change the type of build. Possible values are `Release`, `Debug`, etc. By default, this is set to `Release`. 90 * `selfContainedBuild` allows to enable the [self-contained](https://docs.microsoft.com/en-us/dotnet/core/deploying/#publish-self-contained) build flag. By default, it is set to false and generated applications have a dependency on the selected dotnet runtime. If enabled, the dotnet runtime is bundled into the executable and the built app has no dependency on Dotnet. 91 - * `dotnet-sdk` is useful in cases where you need to change what dotnet SDK is being used. 92 * `dotnet-runtime` is useful in cases where you need to change what dotnet runtime is being used. This can be either a regular dotnet runtime, or an aspnetcore. 93 * `dotnet-test-sdk` is useful in cases where unit tests expect a different dotnet SDK. By default, this is set to the `dotnet-sdk` attribute. 94 * `testProjectFile` is useful in cases where the regular project file does not contain the unit tests. It gets restored and build, but not installed. You may need to regenerate your nuget lockfile after setting this.
··· 88 * `runtimeDeps` is used to wrap libraries into `LD_LIBRARY_PATH`. This is how dotnet usually handles runtime dependencies. 89 * `buildType` is used to change the type of build. Possible values are `Release`, `Debug`, etc. By default, this is set to `Release`. 90 * `selfContainedBuild` allows to enable the [self-contained](https://docs.microsoft.com/en-us/dotnet/core/deploying/#publish-self-contained) build flag. By default, it is set to false and generated applications have a dependency on the selected dotnet runtime. If enabled, the dotnet runtime is bundled into the executable and the built app has no dependency on Dotnet. 91 + * `dotnet-sdk` is useful in cases where you need to change what dotnet SDK is being used. You can also set this to the result of `dotnetSdkPackages.combinePackages`, if the project uses multiple SDKs to build. 92 * `dotnet-runtime` is useful in cases where you need to change what dotnet runtime is being used. This can be either a regular dotnet runtime, or an aspnetcore. 93 * `dotnet-test-sdk` is useful in cases where unit tests expect a different dotnet SDK. By default, this is set to the `dotnet-sdk` attribute. 94 * `testProjectFile` is useful in cases where the regular project file does not contain the unit tests. It gets restored and build, but not installed. You may need to regenerate your nuget lockfile after setting this.
+12 -5
pkgs/build-support/dotnet/build-dotnet-module/default.nix
··· 121 # this contains all the nuget packages that are implicitly referenced by the dotnet 122 # build system. having them as separate deps allows us to avoid having to regenerate 123 # a packages dependencies when the dotnet-sdk version changes 124 - sdkDeps = dotnet-sdk.packages; 125 126 - sdkSource = mkNugetSource { 127 - name = "dotnet-sdk-${dotnet-sdk.version}-source"; 128 - deps = [ sdkDeps ]; 129 }; 130 131 nuget-source = symlinkJoin { ··· 271 272 echo "Writing lockfile..." 273 echo -e "# This file was automatically generated by passthru.fetch-deps.\n# Please dont edit it manually, your changes might get overwritten!\n" > "$depsFile" 274 - nuget-to-nix "$tmp/nuget_pkgs" "${sdkDeps}" >> "$depsFile" 275 echo "Succesfully wrote lockfile to $depsFile" 276 ''; 277 } // args.passthru or { };
··· 121 # this contains all the nuget packages that are implicitly referenced by the dotnet 122 # build system. having them as separate deps allows us to avoid having to regenerate 123 # a packages dependencies when the dotnet-sdk version changes 124 + sdkDeps = lib.lists.flatten [ dotnet-sdk.packages ]; 125 126 + sdkSource = let 127 + version = dotnet-sdk.version or (lib.concatStringsSep "-" dotnet-sdk.versions); 128 + in mkNugetSource { 129 + name = "dotnet-sdk-${version}-source"; 130 + deps = sdkDeps; 131 }; 132 133 nuget-source = symlinkJoin { ··· 273 274 echo "Writing lockfile..." 275 echo -e "# This file was automatically generated by passthru.fetch-deps.\n# Please dont edit it manually, your changes might get overwritten!\n" > "$depsFile" 276 + 277 + excluded_sources="${lib.concatStringsSep " " sdkDeps}" 278 + for excluded_source in ''${excluded_sources[@]}; do 279 + ls "$excluded_source" >> "$tmp/excluded_list" 280 + done 281 + nuget-to-nix "$tmp/nuget_pkgs" "$tmp/excluded_list" >> "$depsFile" 282 echo "Succesfully wrote lockfile to $depsFile" 283 ''; 284 } // args.passthru or { };
+4 -3
pkgs/build-support/dotnet/nuget-to-nix/nuget-to-nix.sh
··· 7 export LC_ALL=C 8 9 if [ $# -eq 0 ]; then 10 - >&2 echo "Usage: $0 <packages directory> [path to excluded package source] > deps.nix" 11 exit 1 12 fi 13 14 pkgs=$1 15 tmp=$(realpath "$(mktemp -td nuget-to-nix.XXXXXX)") 16 trap 'rm -r "$tmp"' EXIT 17 - excluded_source=$(realpath "${2:-$tmp/empty}") 18 19 export DOTNET_NOLOGO=1 20 export DOTNET_CLI_TELEMETRY_OPTOUT=1 ··· 37 for version in *; do 38 id=$(xq -r .package.metadata.id "$version/$package".nuspec) 39 40 - if [[ -e "$excluded_source/$id.$version".nupkg ]]; then 41 continue 42 fi 43
··· 7 export LC_ALL=C 8 9 if [ $# -eq 0 ]; then 10 + >&2 echo "Usage: $0 <packages directory> [path to a file with a list of excluded packages] > deps.nix" 11 exit 1 12 fi 13 14 pkgs=$1 15 tmp=$(realpath "$(mktemp -td nuget-to-nix.XXXXXX)") 16 trap 'rm -r "$tmp"' EXIT 17 + 18 + excluded_list=$(realpath "${2:-/dev/null}") 19 20 export DOTNET_NOLOGO=1 21 export DOTNET_CLI_TELEMETRY_OPTOUT=1 ··· 38 for version in *; do 39 id=$(xq -r .package.metadata.id "$version/$package".nuspec) 40 41 + if grep -qxF "$id.$version.nupkg" "$excluded_list"; then 42 continue 43 fi 44
+2 -2
pkgs/development/compilers/dotnet/build-dotnet.nix
··· 42 sdk = ".NET SDK ${version}"; 43 }; 44 45 - packageDeps = mkNugetDeps { 46 name = "${pname}-${version}-deps"; 47 nugetDeps = packages; 48 - }; 49 50 in 51 stdenv.mkDerivation (finalAttrs: rec {
··· 42 sdk = ".NET SDK ${version}"; 43 }; 44 45 + packageDeps = if type == "sdk" then mkNugetDeps { 46 name = "${pname}-${version}-deps"; 47 nugetDeps = packages; 48 + } else null; 49 50 in 51 stdenv.mkDerivation (finalAttrs: rec {
+10 -5
pkgs/development/compilers/dotnet/combine-packages.nix
··· 1 - packages: 2 { buildEnv, makeWrapper, lib }: 3 # TODO: Rethink how we determine and/or get the CLI. 4 # Possible options raised in #187118: 5 # 1. A separate argument for the CLI (as suggested by IvarWithoutBones 6 # 2. Use the highest version SDK for the CLI (as suggested by GGG) 7 # 3. Something else? 8 - let cli = builtins.head packages; 9 in 10 - assert lib.assertMsg ((builtins.length packages) > 0) 11 ''You must include at least one package, e.g 12 `with dotnetCorePackages; combinePackages [ 13 sdk_3_1 aspnetcore_5_0 14 ];`'' ; 15 buildEnv { 16 name = "dotnet-core-combined"; 17 - paths = packages; 18 pathsToLink = [ "/host" "/packs" "/sdk" "/sdk-manifests" "/shared" "/templates" ]; 19 ignoreCollisions = true; 20 nativeBuildInputs = [ ··· 29 --prefix LD_LIBRARY_PATH : ${cli.icu}/lib 30 ''; 31 passthru = { 32 - inherit (cli) icu packages; 33 }; 34 }
··· 1 + dotnetPackages: 2 { buildEnv, makeWrapper, lib }: 3 # TODO: Rethink how we determine and/or get the CLI. 4 # Possible options raised in #187118: 5 # 1. A separate argument for the CLI (as suggested by IvarWithoutBones 6 # 2. Use the highest version SDK for the CLI (as suggested by GGG) 7 # 3. Something else? 8 + let cli = builtins.head dotnetPackages; 9 in 10 + assert lib.assertMsg ((builtins.length dotnetPackages) > 0) 11 ''You must include at least one package, e.g 12 `with dotnetCorePackages; combinePackages [ 13 sdk_3_1 aspnetcore_5_0 14 ];`'' ; 15 buildEnv { 16 name = "dotnet-core-combined"; 17 + paths = dotnetPackages; 18 pathsToLink = [ "/host" "/packs" "/sdk" "/sdk-manifests" "/shared" "/templates" ]; 19 ignoreCollisions = true; 20 nativeBuildInputs = [ ··· 29 --prefix LD_LIBRARY_PATH : ${cli.icu}/lib 30 ''; 31 passthru = { 32 + inherit (cli) icu; 33 + 34 + versions = lib.catAttrs "version" dotnetPackages; 35 + packages = lib.remove null (lib.catAttrs "packages" dotnetPackages); 36 }; 37 + 38 + inherit (cli) meta; 39 }