From 42d69ab59a80edf0c79b112f7a9b6dd86858c2cd Mon Sep 17 00:00:00 2001 From: David McFarland Date: Tue, 1 Oct 2024 22:14:39 -0300 Subject: [PATCH] dotnet: move dotnet_root to $out/share/dotnet --- .../manual/release-notes/rl-2411.section.md | 5 ++++ .../hooks/dotnet-fixup-hook.sh | 4 +-- pkgs/by-name/dy/dyalog/package.nix | 2 +- pkgs/by-name/ms/msbuild/package.nix | 6 ++--- pkgs/by-name/ne/netcoredbg/package.nix | 2 +- pkgs/by-name/pr/pre-commit/package.nix | 2 +- .../compilers/dotnet/build-dotnet.nix | 27 ++++++++++--------- .../compilers/dotnet/combine-packages.nix | 20 +++++++------- .../development/compilers/dotnet/packages.nix | 25 +++++++++-------- pkgs/development/compilers/dotnet/vmr.nix | 2 +- pkgs/development/compilers/dotnet/wrapper.nix | 4 +-- .../dotnet/use-dotnet-from-env/default.nix | 4 +-- 12 files changed, 57 insertions(+), 46 deletions(-) diff --git a/nixos/doc/manual/release-notes/rl-2411.section.md b/nixos/doc/manual/release-notes/rl-2411.section.md index 24481af73c87..d60d3006bdfe 100644 --- a/nixos/doc/manual/release-notes/rl-2411.section.md +++ b/nixos/doc/manual/release-notes/rl-2411.section.md @@ -724,6 +724,11 @@ reference the underlying dotnet distribution (DOTNET_ROOT) you should use e.g. `dotnet-runtime.unwrapped`. +- The root of dotnet distribution packages (DOTNET_ROOT) is now under e.g. + `${dotnet-sdk.unwrapped}/share/dotnet` instead of directly in the package + root. This is consistent with packaging guidelines and more friendly for FHS + environments. + ## Other Notable Changes {#sec-release-24.11-notable-changes} diff --git a/pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-fixup-hook.sh b/pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-fixup-hook.sh index 7b01a9f2c4c3..02d4718708bd 100644 --- a/pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-fixup-hook.sh +++ b/pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-fixup-hook.sh @@ -44,10 +44,10 @@ dotnetFromEnv' # if dotnet CLI is available, set DOTNET_ROOT based on it. Otherwise set to default .NET runtime dotnetRootFlagsArray+=("--suffix" "PATH" ":" "$wrapperPath") dotnetRootFlagsArray+=("--run" "$dotnetFromEnvScript") - dotnetRootFlagsArray+=("--set-default" "DOTNET_ROOT" "$dotnetRuntime") + dotnetRootFlagsArray+=("--set-default" "DOTNET_ROOT" "$dotnetRuntime/share/dotnet") dotnetRootFlagsArray+=("--suffix" "PATH" ":" "$dotnetRuntime/bin") else - dotnetRootFlagsArray+=("--set" "DOTNET_ROOT" "$dotnetRuntime") + dotnetRootFlagsArray+=("--set" "DOTNET_ROOT" "$dotnetRuntime/share/dotnet") dotnetRootFlagsArray+=("--prefix" "PATH" ":" "$dotnetRuntime/bin") fi fi diff --git a/pkgs/by-name/dy/dyalog/package.nix b/pkgs/by-name/dy/dyalog/package.nix index df0465079b12..310ec6a8bc34 100644 --- a/pkgs/by-name/dy/dyalog/package.nix +++ b/pkgs/by-name/dy/dyalog/package.nix @@ -32,7 +32,7 @@ let dyalogHome = "$out/lib/dyalog"; - makeWrapperArgs = lib.optional dotnetSupport "--set DOTNET_ROOT ${dotnet-sdk_8.unwrapped}"; + makeWrapperArgs = lib.optional dotnetSupport "--set DOTNET_ROOT ${dotnet-sdk_8.unwrapped}/share/dotnet"; licenseUrl = "https://www.dyalog.com/uploads/documents/Developer_Software_Licence.pdf"; diff --git a/pkgs/by-name/ms/msbuild/package.nix b/pkgs/by-name/ms/msbuild/package.nix index e60b71bb6582..e39afb86384f 100644 --- a/pkgs/by-name/ms/msbuild/package.nix +++ b/pkgs/by-name/ms/msbuild/package.nix @@ -72,7 +72,7 @@ mkPackage rec { # The provided libhostfxr.dylib is for x86_64-darwin, so we remove it rm artifacts/mono-msbuild/SdkResolvers/Microsoft.DotNet.MSBuildSdkResolver/libhostfxr.dylib - ln -s $(find ${dotnet-sdk.unwrapped} -name libhostfxr${sharedLibrary}) artifacts/mono-msbuild/SdkResolvers/Microsoft.DotNet.MSBuildSdkResolver/ + ln -s $(find ${dotnet-sdk.unwrapped}/share/dotnet -name libhostfxr${sharedLibrary}) artifacts/mono-msbuild/SdkResolvers/Microsoft.DotNet.MSBuildSdkResolver/ # overwrite the file echo "#!${stdenv.shell}" > eng/common/dotnet-install.sh @@ -82,7 +82,7 @@ mkPackage rec { echo "#!${stdenv.shell}" > mono/build/extract_and_copy_hostfxr.sh mkdir -p mono/dotnet-overlay/msbuild-bin - cp ${dotnet-sdk.unwrapped}/sdk/*/{Microsoft.NETCoreSdk.BundledVersions.props,RuntimeIdentifierGraph.json} mono/dotnet-overlay/msbuild-bin + cp ${dotnet-sdk.unwrapped}/share/dotnet/sdk/*/{Microsoft.NETCoreSdk.BundledVersions.props,RuntimeIdentifierGraph.json} mono/dotnet-overlay/msbuild-bin # DisableNerdbankVersioning https://gitter.im/Microsoft/msbuild/archives/2018/06/27?at=5b33dbc4ce3b0f268d489bfa # TODO there are some (many?) failing tests @@ -99,7 +99,7 @@ mkPackage rec { --set-default MONO_GC_PARAMS "nursery-size=64m" \ --add-flags "$out/lib/mono/msbuild/15.0/bin/MSBuild.dll" - ln -s $(find ${dotnet-sdk.unwrapped} -name libhostfxr${sharedLibrary}) $out/lib/mono/msbuild/Current/bin/SdkResolvers/Microsoft.DotNet.MSBuildSdkResolver/ + ln -s $(find ${dotnet-sdk.unwrapped}/share/dotnet -name libhostfxr${sharedLibrary}) $out/lib/mono/msbuild/Current/bin/SdkResolvers/Microsoft.DotNet.MSBuildSdkResolver/ ''; doInstallCheck = true; diff --git a/pkgs/by-name/ne/netcoredbg/package.nix b/pkgs/by-name/ne/netcoredbg/package.nix index 2695f9c2832e..6d091e257b6f 100644 --- a/pkgs/by-name/ne/netcoredbg/package.nix +++ b/pkgs/by-name/ne/netcoredbg/package.nix @@ -36,7 +36,7 @@ let cmakeFlags = [ "-DCORECLR_DIR=${coreclr-src}/src/coreclr" - "-DDOTNET_DIR=${dotnet-sdk.unwrapped}" + "-DDOTNET_DIR=${dotnet-sdk.unwrapped}/share/dotnet" "-DBUILD_MANAGED=0" ]; }; diff --git a/pkgs/by-name/pr/pre-commit/package.nix b/pkgs/by-name/pr/pre-commit/package.nix index b80d85b93330..d11b373aada0 100644 --- a/pkgs/by-name/pr/pre-commit/package.nix +++ b/pkgs/by-name/pr/pre-commit/package.nix @@ -90,7 +90,7 @@ buildPythonApplication rec { VIRTUALENV_NO_DOWNLOAD=1 PRE_COMMIT_NO_CONCURRENCY=1 LANG=en_US.UTF-8 # Resolve `.NET location: Not found` errors for dotnet tests - export DOTNET_ROOT="${dotnet-sdk.unwrapped}" + export DOTNET_ROOT="${dotnet-sdk.unwrapped}/share/dotnet" export HOME=$(mktemp -d) diff --git a/pkgs/development/compilers/dotnet/build-dotnet.nix b/pkgs/development/compilers/dotnet/build-dotnet.nix index 82710223628c..7ff441c39162 100644 --- a/pkgs/development/compilers/dotnet/build-dotnet.nix +++ b/pkgs/development/compilers/dotnet/build-dotnet.nix @@ -143,14 +143,15 @@ mkWrapper type (stdenv.mkDerivation rec { installPhase = '' runHook preInstall - mkdir -p $out/bin - cp -r ./ $out - mkdir -p $out/share/doc/$pname/$version - mv $out/LICENSE.txt $out/share/doc/$pname/$version/ - mv $out/ThirdPartyNotices.txt $out/share/doc/$pname/$version/ + mv LICENSE.txt $out/share/doc/$pname/$version/ + mv ThirdPartyNotices.txt $out/share/doc/$pname/$version/ - ln -s $out/dotnet $out/bin/dotnet + mkdir -p $out/share/dotnet + cp -r ./ $out/share/dotnet + + mkdir -p $out/bin + ln -s $out/share/dotnet/dotnet $out/bin/dotnet runHook postInstall ''; @@ -161,17 +162,17 @@ mkWrapper type (stdenv.mkDerivation rec { patchelf \ --add-needed libicui18n.so \ --add-needed libicuuc.so \ - $out/shared/Microsoft.NETCore.App/*/libcoreclr.so \ - $out/shared/Microsoft.NETCore.App/*/*System.Globalization.Native.so \ - $out/packs/Microsoft.NETCore.App.Host.${hostRid}/*/runtimes/${hostRid}/native/*host + $out/share/dotnet/shared/Microsoft.NETCore.App/*/libcoreclr.so \ + $out/share/dotnet/shared/Microsoft.NETCore.App/*/*System.Globalization.Native.so \ + $out/share/dotnet/packs/Microsoft.NETCore.App.Host.${hostRid}/*/runtimes/${hostRid}/native/*host patchelf \ --add-needed libgssapi_krb5.so \ - $out/shared/Microsoft.NETCore.App/*/*System.Net.Security.Native.so \ - $out/packs/Microsoft.NETCore.App.Host.${hostRid}/*/runtimes/${hostRid}/native/*host + $out/share/dotnet/shared/Microsoft.NETCore.App/*/*System.Net.Security.Native.so \ + $out/share/dotnet/packs/Microsoft.NETCore.App.Host.${hostRid}/*/runtimes/${hostRid}/native/*host patchelf \ --add-needed libssl.so \ - $out/shared/Microsoft.NETCore.App/*/*System.Security.Cryptography.Native.OpenSsl.so \ - $out/packs/Microsoft.NETCore.App.Host.${hostRid}/*/runtimes/${hostRid}/native/*host + $out/share/dotnet/shared/Microsoft.NETCore.App/*/*System.Security.Cryptography.Native.OpenSsl.so \ + $out/share/dotnet/packs/Microsoft.NETCore.App.Host.${hostRid}/*/runtimes/${hostRid}/native/*host ''; # fixes: Could not load ICU data. UErrorCode: 2 diff --git a/pkgs/development/compilers/dotnet/combine-packages.nix b/pkgs/development/compilers/dotnet/combine-packages.nix index d0f25c3ed3b1..90c85d6baa8c 100644 --- a/pkgs/development/compilers/dotnet/combine-packages.nix +++ b/pkgs/development/compilers/dotnet/combine-packages.nix @@ -21,20 +21,22 @@ assert lib.assertMsg ((builtins.length dotnetPackages) > 0) '' buildEnv { name = "dotnet-core-combined"; paths = map (x: x.unwrapped) dotnetPackages; - pathsToLink = [ - "/host" - "/packs" - "/sdk" - "/sdk-manifests" - "/shared" - "/templates" + pathsToLink = map (x: "/share/dotnet/${x}") [ + "host" + "packs" + "sdk" + "sdk-manifests" + "shared" + "templates" ]; ignoreCollisions = true; + nativeBuildInputs = [ makeWrapper ]; postBuild = '' - cp -R "${cli.unwrapped}"/dotnet $out/ + mkdir -p "$out"/share/dotnet + cp "${cli.unwrapped}"/share/dotnet/dotnet $out/share/dotnet cp -R "${cli}"/nix-support "$out"/ mkdir "$out"/bin - ln -s "$out"/dotnet "$out"/bin/dotnet + ln -s "$out"/share/dotnet/dotnet "$out"/bin/dotnet ''; passthru = { inherit (cli) icu; diff --git a/pkgs/development/compilers/dotnet/packages.nix b/pkgs/development/compilers/dotnet/packages.nix index 5f278d5a8dd2..abc7c0527291 100644 --- a/pkgs/development/compilers/dotnet/packages.nix +++ b/pkgs/development/compilers/dotnet/packages.nix @@ -115,10 +115,11 @@ let installPhase = '' runHook preInstall - cp -r "$src"/dotnet-sdk-${version}-${targetRid} "$out" - chmod +w "$out" + mkdir -p "$out"/share + cp -r "$src"/dotnet-sdk-${version}-${targetRid} "$out"/share/dotnet + chmod +w "$out"/share/dotnet mkdir "$out"/bin - ln -s "$out"/dotnet "$out"/bin/dotnet + ln -s "$out"/share/dotnet/dotnet "$out"/bin/dotnet mkdir -p "$artifacts" cp -r "$src"/Private.SourceBuilt.Artifacts.*.${targetRid}/* "$artifacts"/ @@ -160,10 +161,11 @@ let installPhase = '' runHook preInstall - cp -r "$src/dotnet-runtime-${version}-${targetRid}" "$out" - chmod +w "$out" + mkdir -p "$out"/share + cp -r "$src/dotnet-runtime-${version}-${targetRid}" "$out"/share/dotnet + chmod +w "$out"/share/dotnet mkdir "$out"/bin - ln -s "$out"/dotnet "$out"/bin/dotnet + ln -s "$out"/share/dotnet/dotnet "$out"/bin/dotnet runHook postInstall ''; @@ -185,13 +187,14 @@ let installPhase = '' runHook preInstall - cp -r "$src/dotnet-runtime-${releaseManifest.runtimeVersion}-${targetRid}" "$out" - chmod +w "$out" + mkdir -p "$out"/share + cp -r "$src/dotnet-runtime-${runtime.version}-${targetRid}" "$out"/share/dotnet + chmod +w "$out"/share/dotnet/shared mkdir "$out"/bin - ln -s "$out"/dotnet "$out"/bin/dotnet + ln -s "$out"/share/dotnet/dotnet "$out"/bin/dotnet - chmod +w "$out"/shared - cp -Tr "$src/aspnetcore-runtime-${version}-${targetRid}" "$out" + cp -Tr "$src/aspnetcore-runtime-${version}-${targetRid}" "$out"/share/dotnet + chmod +w "$out"/share/dotnet/shared runHook postInstall ''; diff --git a/pkgs/development/compilers/dotnet/vmr.nix b/pkgs/development/compilers/dotnet/vmr.nix index 525611c5001a..94a2eaaea746 100644 --- a/pkgs/development/compilers/dotnet/vmr.nix +++ b/pkgs/development/compilers/dotnet/vmr.nix @@ -361,7 +361,7 @@ stdenv.mkDerivation rec { # The build process tries to overwrite some things in the sdk (e.g. # SourceBuild.MSBuildSdkResolver.dll), so it needs to be mutable. - cp -Tr ${bootstrapSdk} .dotnet + cp -Tr ${bootstrapSdk}/share/dotnet .dotnet chmod -R +w .dotnet export HOME=$(mktemp -d) diff --git a/pkgs/development/compilers/dotnet/wrapper.nix b/pkgs/development/compilers/dotnet/wrapper.nix index 61a1e1ab2473..43affe153c38 100644 --- a/pkgs/development/compilers/dotnet/wrapper.nix +++ b/pkgs/development/compilers/dotnet/wrapper.nix @@ -31,7 +31,7 @@ stdenvNoCC.mkDerivation (finalAttrs: { installPhase = '' runHook preInstall - mkdir -p "$out"/bin + mkdir -p "$out"/bin "$out"/share/dotnet ln -s "$src"/bin/* "$out"/bin runHook postInstall ''; @@ -122,7 +122,7 @@ stdenvNoCC.mkDerivation (finalAttrs: { ( lib.optionalString (runtime != null) '' # TODO: use runtime here - export DOTNET_ROOT=${runtime.unwrapped} + export DOTNET_ROOT=${runtime.unwrapped}/share/dotnet '' + run ); diff --git a/pkgs/test/dotnet/use-dotnet-from-env/default.nix b/pkgs/test/dotnet/use-dotnet-from-env/default.nix index d26458a86a3d..2fedc633b176 100644 --- a/pkgs/test/dotnet/use-dotnet-from-env/default.nix +++ b/pkgs/test/dotnet/use-dotnet-from-env/default.nix @@ -46,7 +46,7 @@ in use-dotnet-root-env = testers.testEqualContents { assertion = "buildDotnetModule uses DOTNET_ROOT from environment in wrapper"; expected = runtimeVersionFile; - actual = runCommand "use-dotnet-from-env-root-test" { env.DOTNET_ROOT = dotnet-runtime.unwrapped; } '' + actual = runCommand "use-dotnet-from-env-root-test" { env.DOTNET_ROOT = "${dotnet-runtime.unwrapped}/share/dotnet"; } '' ${appWithoutFallback}/bin/Application >"$out" ''; }; @@ -54,7 +54,7 @@ in assertion = "buildDotnetModule uses DOTNET_ROOT from dotnet in PATH in wrapper"; expected = runtimeVersionFile; actual = runCommand "use-dotnet-from-env-path-test" { dotnetRuntime = dotnet-runtime; } '' - PATH=$dotnetRuntime''${PATH+:}$PATH ${appWithoutFallback}/bin/Application >"$out" + PATH=$dotnetRuntime/bin''${PATH+:}$PATH ${appWithoutFallback}/bin/Application >"$out" ''; }; }