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 88 * `runtimeDeps` is used to wrap libraries into `LD_LIBRARY_PATH`. This is how dotnet usually handles runtime dependencies. 89 89 * `buildType` is used to change the type of build. Possible values are `Release`, `Debug`, etc. By default, this is set to `Release`. 90 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. 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 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 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 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 121 # this contains all the nuget packages that are implicitly referenced by the dotnet 122 122 # build system. having them as separate deps allows us to avoid having to regenerate 123 123 # a packages dependencies when the dotnet-sdk version changes 124 - sdkDeps = dotnet-sdk.packages; 124 + sdkDeps = lib.lists.flatten [ dotnet-sdk.packages ]; 125 125 126 - sdkSource = mkNugetSource { 127 - name = "dotnet-sdk-${dotnet-sdk.version}-source"; 128 - deps = [ sdkDeps ]; 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; 129 131 }; 130 132 131 133 nuget-source = symlinkJoin { ··· 271 273 272 274 echo "Writing lockfile..." 273 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" 274 - nuget-to-nix "$tmp/nuget_pkgs" "${sdkDeps}" >> "$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" 275 282 echo "Succesfully wrote lockfile to $depsFile" 276 283 ''; 277 284 } // args.passthru or { };
+4 -3
pkgs/build-support/dotnet/nuget-to-nix/nuget-to-nix.sh
··· 7 7 export LC_ALL=C 8 8 9 9 if [ $# -eq 0 ]; then 10 - >&2 echo "Usage: $0 <packages directory> [path to excluded package source] > deps.nix" 10 + >&2 echo "Usage: $0 <packages directory> [path to a file with a list of excluded packages] > deps.nix" 11 11 exit 1 12 12 fi 13 13 14 14 pkgs=$1 15 15 tmp=$(realpath "$(mktemp -td nuget-to-nix.XXXXXX)") 16 16 trap 'rm -r "$tmp"' EXIT 17 - excluded_source=$(realpath "${2:-$tmp/empty}") 17 + 18 + excluded_list=$(realpath "${2:-/dev/null}") 18 19 19 20 export DOTNET_NOLOGO=1 20 21 export DOTNET_CLI_TELEMETRY_OPTOUT=1 ··· 37 38 for version in *; do 38 39 id=$(xq -r .package.metadata.id "$version/$package".nuspec) 39 40 40 - if [[ -e "$excluded_source/$id.$version".nupkg ]]; then 41 + if grep -qxF "$id.$version.nupkg" "$excluded_list"; then 41 42 continue 42 43 fi 43 44
+2 -2
pkgs/development/compilers/dotnet/build-dotnet.nix
··· 42 42 sdk = ".NET SDK ${version}"; 43 43 }; 44 44 45 - packageDeps = mkNugetDeps { 45 + packageDeps = if type == "sdk" then mkNugetDeps { 46 46 name = "${pname}-${version}-deps"; 47 47 nugetDeps = packages; 48 - }; 48 + } else null; 49 49 50 50 in 51 51 stdenv.mkDerivation (finalAttrs: rec {
+10 -5
pkgs/development/compilers/dotnet/combine-packages.nix
··· 1 - packages: 1 + dotnetPackages: 2 2 { buildEnv, makeWrapper, lib }: 3 3 # TODO: Rethink how we determine and/or get the CLI. 4 4 # Possible options raised in #187118: 5 5 # 1. A separate argument for the CLI (as suggested by IvarWithoutBones 6 6 # 2. Use the highest version SDK for the CLI (as suggested by GGG) 7 7 # 3. Something else? 8 - let cli = builtins.head packages; 8 + let cli = builtins.head dotnetPackages; 9 9 in 10 - assert lib.assertMsg ((builtins.length packages) > 0) 10 + assert lib.assertMsg ((builtins.length dotnetPackages) > 0) 11 11 ''You must include at least one package, e.g 12 12 `with dotnetCorePackages; combinePackages [ 13 13 sdk_3_1 aspnetcore_5_0 14 14 ];`'' ; 15 15 buildEnv { 16 16 name = "dotnet-core-combined"; 17 - paths = packages; 17 + paths = dotnetPackages; 18 18 pathsToLink = [ "/host" "/packs" "/sdk" "/sdk-manifests" "/shared" "/templates" ]; 19 19 ignoreCollisions = true; 20 20 nativeBuildInputs = [ ··· 29 29 --prefix LD_LIBRARY_PATH : ${cli.icu}/lib 30 30 ''; 31 31 passthru = { 32 - inherit (cli) icu packages; 32 + inherit (cli) icu; 33 + 34 + versions = lib.catAttrs "version" dotnetPackages; 35 + packages = lib.remove null (lib.catAttrs "packages" dotnetPackages); 33 36 }; 37 + 38 + inherit (cli) meta; 34 39 }