diff --git a/doc/languages-frameworks/dotnet.section.md b/doc/languages-frameworks/dotnet.section.md index 30a12d4e8ffa..2152f86165c0 100644 --- a/doc/languages-frameworks/dotnet.section.md +++ b/doc/languages-frameworks/dotnet.section.md @@ -88,7 +88,7 @@ To package Dotnet applications, you can use `buildDotnetModule`. This has simila * `runtimeDeps` is used to wrap libraries into `LD_LIBRARY_PATH`. This is how dotnet usually handles runtime dependencies. * `buildType` is used to change the type of build. Possible values are `Release`, `Debug`, etc. By default, this is set to `Release`. * `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. -* `dotnet-sdk` is useful in cases where you need to change what dotnet SDK is being used. +* `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. * `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. * `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. * `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. diff --git a/pkgs/build-support/dotnet/build-dotnet-module/default.nix b/pkgs/build-support/dotnet/build-dotnet-module/default.nix index 311eb2b293e5..32e8cbd2b1ad 100644 --- a/pkgs/build-support/dotnet/build-dotnet-module/default.nix +++ b/pkgs/build-support/dotnet/build-dotnet-module/default.nix @@ -121,11 +121,13 @@ let # this contains all the nuget packages that are implicitly referenced by the dotnet # build system. having them as separate deps allows us to avoid having to regenerate # a packages dependencies when the dotnet-sdk version changes - sdkDeps = dotnet-sdk.packages; + sdkDeps = lib.lists.flatten [ dotnet-sdk.packages ]; - sdkSource = mkNugetSource { - name = "dotnet-sdk-${dotnet-sdk.version}-source"; - deps = [ sdkDeps ]; + sdkSource = let + version = dotnet-sdk.version or (lib.concatStringsSep "-" dotnet-sdk.versions); + in mkNugetSource { + name = "dotnet-sdk-${version}-source"; + deps = sdkDeps; }; nuget-source = symlinkJoin { @@ -271,7 +273,12 @@ stdenvNoCC.mkDerivation (args // { echo "Writing lockfile..." echo -e "# This file was automatically generated by passthru.fetch-deps.\n# Please dont edit it manually, your changes might get overwritten!\n" > "$depsFile" - nuget-to-nix "$tmp/nuget_pkgs" "${sdkDeps}" >> "$depsFile" + + excluded_sources="${lib.concatStringsSep " " sdkDeps}" + for excluded_source in ''${excluded_sources[@]}; do + ls "$excluded_source" >> "$tmp/excluded_list" + done + nuget-to-nix "$tmp/nuget_pkgs" "$tmp/excluded_list" >> "$depsFile" echo "Succesfully wrote lockfile to $depsFile" ''; } // args.passthru or { }; diff --git a/pkgs/build-support/dotnet/nuget-to-nix/nuget-to-nix.sh b/pkgs/build-support/dotnet/nuget-to-nix/nuget-to-nix.sh index 390c96751fac..ce2a7070ea31 100755 --- a/pkgs/build-support/dotnet/nuget-to-nix/nuget-to-nix.sh +++ b/pkgs/build-support/dotnet/nuget-to-nix/nuget-to-nix.sh @@ -7,14 +7,15 @@ export PATH="@binPath@" export LC_ALL=C if [ $# -eq 0 ]; then - >&2 echo "Usage: $0 [path to excluded package source] > deps.nix" + >&2 echo "Usage: $0 [path to a file with a list of excluded packages] > deps.nix" exit 1 fi pkgs=$1 tmp=$(realpath "$(mktemp -td nuget-to-nix.XXXXXX)") trap 'rm -r "$tmp"' EXIT -excluded_source=$(realpath "${2:-$tmp/empty}") + +excluded_list=$(realpath "${2:-/dev/null}") export DOTNET_NOLOGO=1 export DOTNET_CLI_TELEMETRY_OPTOUT=1 @@ -37,7 +38,7 @@ for package in *; do for version in *; do id=$(xq -r .package.metadata.id "$version/$package".nuspec) - if [[ -e "$excluded_source/$id.$version".nupkg ]]; then + if grep -qxF "$id.$version.nupkg" "$excluded_list"; then continue fi diff --git a/pkgs/development/compilers/dotnet/build-dotnet.nix b/pkgs/development/compilers/dotnet/build-dotnet.nix index c51eca24b58c..05e145c48f6f 100644 --- a/pkgs/development/compilers/dotnet/build-dotnet.nix +++ b/pkgs/development/compilers/dotnet/build-dotnet.nix @@ -42,10 +42,10 @@ let sdk = ".NET SDK ${version}"; }; - packageDeps = mkNugetDeps { + packageDeps = if type == "sdk" then mkNugetDeps { name = "${pname}-${version}-deps"; nugetDeps = packages; - }; + } else null; in stdenv.mkDerivation (finalAttrs: rec { diff --git a/pkgs/development/compilers/dotnet/combine-packages.nix b/pkgs/development/compilers/dotnet/combine-packages.nix index 7ca28e2fdc43..930339d8dbbd 100644 --- a/pkgs/development/compilers/dotnet/combine-packages.nix +++ b/pkgs/development/compilers/dotnet/combine-packages.nix @@ -1,20 +1,20 @@ -packages: +dotnetPackages: { buildEnv, makeWrapper, lib }: # TODO: Rethink how we determine and/or get the CLI. # Possible options raised in #187118: # 1. A separate argument for the CLI (as suggested by IvarWithoutBones # 2. Use the highest version SDK for the CLI (as suggested by GGG) # 3. Something else? -let cli = builtins.head packages; +let cli = builtins.head dotnetPackages; in -assert lib.assertMsg ((builtins.length packages) > 0) +assert lib.assertMsg ((builtins.length dotnetPackages) > 0) ''You must include at least one package, e.g `with dotnetCorePackages; combinePackages [ sdk_3_1 aspnetcore_5_0 ];`'' ; buildEnv { name = "dotnet-core-combined"; - paths = packages; + paths = dotnetPackages; pathsToLink = [ "/host" "/packs" "/sdk" "/sdk-manifests" "/shared" "/templates" ]; ignoreCollisions = true; nativeBuildInputs = [ @@ -29,6 +29,11 @@ assert lib.assertMsg ((builtins.length packages) > 0) --prefix LD_LIBRARY_PATH : ${cli.icu}/lib ''; passthru = { - inherit (cli) icu packages; + inherit (cli) icu; + + versions = lib.catAttrs "version" dotnetPackages; + packages = lib.remove null (lib.catAttrs "packages" dotnetPackages); }; + + inherit (cli) meta; }