Skip to content

Commit

Permalink
dotnet: november 2024 upgrades and infrastructure changes (NixOS#355753)
Browse files Browse the repository at this point in the history
  • Loading branch information
corngood authored Nov 19, 2024
2 parents 9bb6359 + fd3d60b commit b0d941e
Show file tree
Hide file tree
Showing 59 changed files with 1,620 additions and 1,477 deletions.
75 changes: 9 additions & 66 deletions maintainers/scripts/update-dotnet-lockfiles.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,69 +8,12 @@
to 'fetch-deps', 'nuget-to-nix', or other changes to the dotnet build
infrastructure. Regular updates should be done through the individual packages
update scripts.
*/
{ startWith ? null }:
let
pkgs = import ../.. { config.allowAliases = false; };

inherit (pkgs) lib;

packagesWith = cond: pkgs:
let
packagesWithInner = attrs:
lib.concatLists (
lib.mapAttrsToList (name: elem:
let
result = builtins.tryEval elem;
in
if result.success then
let
value = result.value;
in
if lib.isDerivation value then
lib.optional (cond value) value
else
if lib.isAttrs value && (value.recurseForDerivations or false || value.recurseForRelease or false) then
packagesWithInner value
else []
else []) attrs);
in
packagesWithInner pkgs;

packages = lib.unique
(lib.filter (p:
(builtins.tryEval p.outPath).success ||
builtins.trace "warning: skipping ${p.name} because it failed to evaluate" false)
((pkgs: (lib.drop (lib.lists.findFirstIndex (p: p.name == startWith) 0 pkgs) pkgs))
(packagesWith (p: p ? fetch-deps) pkgs)));

helpText = ''
Please run:
% nix-shell maintainers/scripts/update-dotnet-lockfiles.nix
'';

fetchScripts = map (p: p.fetch-deps) packages;

in pkgs.stdenv.mkDerivation {
name = "nixpkgs-update-dotnet-lockfiles";
buildCommand = ''
echo ""
echo "----------------------------------------------------------------"
echo ""
echo "Not possible to update packages using \`nix-build\`"
echo ""
echo "${helpText}"
echo "----------------------------------------------------------------"
exit 1
'';
shellHook = ''
unset shellHook # do not contaminate nested shells
set -e
for x in $fetchScripts; do
$x
done
exit
'';
inherit fetchScripts;
}
*/
{ ... }@args:
import ./update.nix (
{
predicate = _: _: true;
get-script = pkg: pkg.fetch-deps or null;
}
// args
)
22 changes: 12 additions & 10 deletions maintainers/scripts/update.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
{ package ? null
, maintainer ? null
, predicate ? null
, get-script ? pkg: pkg.updateScript or null
, path ? null
, max-workers ? null
, include-overlays ? false
Expand All @@ -17,13 +18,13 @@
}:

let
pkgs = import ./../../default.nix (
pkgs = import ./../../default.nix ((
if include-overlays == false then
{ overlays = []; }
else if include-overlays == true then
{ } # Let Nixpkgs include overlays impurely.
else { overlays = include-overlays; }
);
) // { config.allowAliases = false; });

inherit (pkgs) lib;

Expand Down Expand Up @@ -56,7 +57,7 @@ let

somewhatUniqueRepresentant =
{ package, attrPath }: {
inherit (package) updateScript;
updateScript = (get-script package);
# Some updaters use the same `updateScript` value for all packages.
# Also compare `meta.description`.
position = package.meta.position or null;
Expand Down Expand Up @@ -89,7 +90,7 @@ let
/* Recursively find all packages in `pkgs` with updateScript matching given predicate.
*/
packagesWithUpdateScriptMatchingPredicate = cond:
packagesWith (path: pkg: builtins.hasAttr "updateScript" pkg && cond path pkg);
packagesWith (path: pkg: (get-script pkg != null) && cond path pkg);

/* Recursively find all packages in `pkgs` with updateScript by given maintainer.
*/
Expand Down Expand Up @@ -121,7 +122,7 @@ let
if pathContent == null then
builtins.throw "Attribute path `${path}` does not exist."
else
packagesWithPath prefix (path: pkg: builtins.hasAttr "updateScript" pkg)
packagesWithPath prefix (path: pkg: (get-script pkg != null))
pathContent;

/* Find a package under `path` in `pkgs` and require that it has an updateScript.
Expand All @@ -132,7 +133,7 @@ let
in
if package == null then
builtins.throw "Package with an attribute name `${path}` does not exist."
else if ! builtins.hasAttr "updateScript" package then
else if get-script package == null then
builtins.throw "Package with an attribute name `${path}` does not have a `passthru.updateScript` attribute defined."
else
{ attrPath = path; inherit package; };
Expand Down Expand Up @@ -193,13 +194,13 @@ let

/* Transform a matched package into an object for update.py.
*/
packageData = { package, attrPath }: {
packageData = { package, attrPath }: let updateScript = get-script package; in {
name = package.name;
pname = lib.getName package;
oldVersion = lib.getVersion package;
updateScript = map builtins.toString (lib.toList (package.updateScript.command or package.updateScript));
supportedFeatures = package.updateScript.supportedFeatures or [];
attrPath = package.updateScript.attrPath or attrPath;
updateScript = map builtins.toString (lib.toList (updateScript.command or updateScript));
supportedFeatures = updateScript.supportedFeatures or [];
attrPath = updateScript.attrPath or attrPath;
};

/* JSON file with data for update.py.
Expand Down Expand Up @@ -230,4 +231,5 @@ in pkgs.stdenv.mkDerivation {
unset shellHook # do not contaminate nested shells
exec ${pkgs.python3.interpreter} ${./update.py} ${builtins.concatStringsSep " " args}
'';
nativeBuildInputs = [ pkgs.git pkgs.nix pkgs.cacert ];
}
14 changes: 14 additions & 0 deletions nixos/doc/manual/release-notes/rl-2411.section.md
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,20 @@
- `python3Packages.nose` has been removed, as it has been deprecated and unmaintained for almost a decade and does not work on Python 3.12.
Please switch to `pytest` or another test runner/framework.

- `dotnet-sdk`, `dotnet-runtime`, and all other dotnet packages now use a
wrapper package containing `bin/dotnet`, build hooks, etc. If you need to
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.

- `dotnet-sdk`, `dotnet-runtime`, and `dotnet-aspnetcore` now point to dotnet 8
rather than dotnet 6. For packages that still need dotnet 6, use
`dotnet-sdk_6`, etc.

## Other Notable Changes {#sec-release-24.11-notable-changes}

<!-- To avoid merge conflicts, consider adding your item at an arbitrary place in the list instead. -->
Expand Down
10 changes: 7 additions & 3 deletions pkgs/build-support/dotnet/build-dotnet-module/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
dotnetCorePackages,
cacert,
addNuGetDeps,
dotnet-sdk,
}:
let
default-sdk = dotnet-sdk;
transformArgs =
finalAttrs:
{
Expand Down Expand Up @@ -82,9 +84,9 @@ let
# Whether to explicitly enable UseAppHost when building. This is redundant if useDotnetFromEnv is enabled
useAppHost ? true,
# The dotnet SDK to use.
dotnet-sdk ? dotnetCorePackages.sdk_6_0,
dotnet-sdk ? default-sdk,
# The dotnet runtime to use.
dotnet-runtime ? dotnetCorePackages.runtime_6_0,
dotnet-runtime ? dotnet-sdk.runtime,
...
}@args:
let
Expand Down Expand Up @@ -188,7 +190,9 @@ let

# propagate the runtime sandbox profile since the contents apply to published
# executables
propagatedSandboxProfile = toString dotnet-runtime.__propagatedSandboxProfile;
propagatedSandboxProfile = lib.optionalString (dotnet-runtime != null) (
toString dotnet-runtime.__propagatedSandboxProfile
);

meta = (args.meta or { }) // {
inherit platforms;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@
{
name = "dotnet-fixup-hook";
substitutions = {
dotnetRuntime = dotnet-runtime;
# this is used for DOTNET_ROOT, so we need unwrapped
dotnetRuntime = if (dotnet-runtime != null) then dotnet-runtime.unwrapped else null;
wrapperPath = lib.makeBinPath [ which coreutils ];
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ dotnetBuildHook() {
local -r parallelBuildFlag="false"
fi

if [[ -n ${dotnetSelfContainedBuild-} ]]; then
dotnetBuildFlagsArray+=("-p:SelfContained=true")
else
dotnetBuildFlagsArray+=("-p:SelfContained=false")
if [[ -v dotnetSelfContainedBuild ]]; then
if [[ -n $dotnetSelfContainedBuild ]]; then
dotnetBuildFlagsArray+=("-p:SelfContained=true")
else
dotnetBuildFlagsArray+=("-p:SelfContained=false")
fi
fi

if [[ -n ${dotnetUseAppHost-} ]]; then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ dotnetConfigureHook() {
local -r parallelFlag="--disable-parallel"
fi

if [[ -v dotnetSelfContainedBuild ]]; then
if [[ -n $dotnetSelfContainedBuild ]]; then
dotnetRestoreFlagsArray+=("-p:SelfContained=true")
else
dotnetRestoreFlagsArray+=("-p:SelfContained=false")
fi
fi

dotnetRestore() {
local -r projectFile="${1-}"
for runtimeId in "${dotnetRuntimeIdsArray[@]}"; do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,12 @@ 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+=("--suffix" "PATH" ":" "$dotnetRuntime/bin")
else
dotnetRootFlagsArray+=("--set" "DOTNET_ROOT" "$dotnetRuntime")
if [[ -n $dotnetRuntime ]]; then
dotnetRootFlagsArray+=("--set-default" "DOTNET_ROOT" "$dotnetRuntime/share/dotnet")
dotnetRootFlagsArray+=("--suffix" "PATH" ":" "$dotnetRuntime/bin")
fi
elif [[ -n $dotnetRuntime ]]; then
dotnetRootFlagsArray+=("--set" "DOTNET_ROOT" "$dotnetRuntime/share/dotnet")
dotnetRootFlagsArray+=("--prefix" "PATH" ":" "$dotnetRuntime/bin")
fi
fi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ dotnetInstallHook() {
local dotnetRuntimeIdsArray=($dotnetRuntimeIds)
fi

if [[ -n ${dotnetSelfContainedBuild-} ]]; then
dotnetInstallFlagsArray+=("--self-contained")
else
dotnetInstallFlagsArray+=("--no-self-contained")
# https://learn.microsoft.com/en-us/dotnet/core/deploying/trimming/trim-self-contained
# Trimming is only available for self-contained build, so force disable it here
dotnetInstallFlagsArray+=("-p:PublishTrimmed=false")
if [[ -v dotnetSelfContainedBuild ]]; then
if [[ -n $dotnetSelfContainedBuild ]]; then
dotnetInstallFlagsArray+=("--self-contained")
else
dotnetInstallFlagsArray+=("--no-self-contained")
# https://learn.microsoft.com/en-us/dotnet/core/deploying/trimming/trim-self-contained
# Trimming is only available for self-contained build, so force disable it here
dotnetInstallFlagsArray+=("-p:PublishTrimmed=false")
fi
fi

if [[ -n ${dotnetUseAppHost-} ]]; then
Expand Down
6 changes: 6 additions & 0 deletions pkgs/build-support/writers/scripts.nix
Original file line number Diff line number Diff line change
Expand Up @@ -1181,11 +1181,17 @@ rec {
};

fsi = writeBash "fsi" ''
set -euo pipefail
export HOME=$NIX_BUILD_TOP/.home
export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1
export DOTNET_CLI_TELEMETRY_OPTOUT=1
export DOTNET_NOLOGO=1
export DOTNET_SKIP_WORKLOAD_INTEGRITY_CHECK=1
script="$1"; shift
(
${lib.getExe dotnet-sdk} new nugetconfig
${lib.getExe dotnet-sdk} nuget disable source nuget
) > /dev/null
${lib.getExe dotnet-sdk} fsi --quiet --nologo --readline- ${fsi-flags} "$@" < "$script"
'';

Expand Down
2 changes: 1 addition & 1 deletion pkgs/by-name/al/alttpr-opentracker/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ buildDotnetModule rec {

patches = [./remove-project.patch];

dotnet-runtime = dotnetCorePackages.runtime_6_0;
dotnet-sdk = dotnetCorePackages.sdk_6_0;

nugetDeps = ./deps.nix;

Expand Down
2 changes: 2 additions & 0 deletions pkgs/by-name/am/am2rlauncher/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
, glib-networking
, wrapGAppsHook3
, gsettings-desktop-schemas
, dotnetCorePackages
}:
let
am2r-run = buildFHSEnv {
Expand Down Expand Up @@ -54,6 +55,7 @@ buildDotnetModule {
hash = "sha256-/nHqo8jh3sOUngbpqdfiQjUWO/8Uzpc5jtW7Ep4q6Wg=";
};

dotnet-sdk = dotnetCorePackages.sdk_6_0;
projectFile = "AM2RLauncher/AM2RLauncher.Gtk/AM2RLauncher.Gtk.csproj";

nugetDeps = ./deps.nix;
Expand Down
2 changes: 1 addition & 1 deletion pkgs/by-name/av/avalonia/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ let
dotnet-sdk =
with dotnetCorePackages;
combinePackages [
sdk_6_0
sdk_7_0_1xx
runtime_6_0
];

npmDepsFile = ./npm-deps.nix;
Expand Down
1 change: 1 addition & 0 deletions pkgs/by-name/az/azure-functions-core-tools/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ buildDotnetModule rec {
pname = "azure-functions-core-tools";
inherit src version;

dotnet-sdk = dotnetCorePackages.sdk_6_0;
dotnet-runtime = dotnetCorePackages.sdk_6_0;
nugetDeps = ./deps.nix;
useDotnetFromEnv = true;
Expand Down
Loading

0 comments on commit b0d941e

Please sign in to comment.