push sheeet
Some checks failed
Periodic Merges (6h) / master → staging-nixos (push) Failing after 12m50s
Periodic Merges (6h) / master → staging-next (push) Failing after 12m54s
Periodic Merges (24h) / merge-base(master,staging) → haskell-updates (push) Failing after 11m54s
Periodic Merges (6h) / staging-next → staging (push) Failing after 12m13s
Periodic Merges (24h) / staging-next-25.05 → staging-25.05 (push) Failing after 13m24s
Periodic Merges (24h) / release-25.05 → staging-next-25.05 (push) Failing after 14m28s

This commit is contained in:
Dark Steveneq
2025-10-09 14:15:47 +02:00
commit 646b892680
49168 changed files with 5897842 additions and 0 deletions

View File

@@ -0,0 +1,235 @@
{
lib,
runtimeShell,
stdenvNoCC,
callPackage,
writeShellScript,
makeWrapper,
dotnetCorePackages,
cacert,
addNuGetDeps,
dotnet-sdk,
}:
let
default-sdk = dotnet-sdk;
transformArgs =
finalAttrs:
{
enableParallelBuilding ? true,
# Flags to pass to `makeWrapper`. This is done to avoid double wrapping.
makeWrapperArgs ? [ ],
# Flags to pass to `dotnet restore`.
dotnetRestoreFlags ? [ ],
# Flags to pass to `dotnet build`.
dotnetBuildFlags ? [ ],
# Flags to pass to `dotnet test`, if running tests is enabled.
dotnetTestFlags ? [ ],
# Flags to pass to `dotnet install`.
dotnetInstallFlags ? [ ],
# Flags to pass to `dotnet pack`.
dotnetPackFlags ? [ ],
# Flags to pass to dotnet in all phases.
dotnetFlags ? [ ],
# The path to publish the project to. When unset, the directory "$out/lib/$pname" is used.
installPath ? null,
# The binaries that should get installed to `$out/bin`, relative to `$installPath/`. These get wrapped accordingly.
# Unfortunately, dotnet has no method for doing this automatically.
# If unset, all executables in the projects root will get installed. This may cause bloat!
executables ? null,
# Packs a project as a `nupkg`, and installs it to `$out/share`. If set to `true`, the derivation can be used as a dependency for another dotnet project by adding it to `projectReferences`.
packNupkg ? false,
# The packages project file, which contains instructions on how to compile it. This can be an array of multiple project files as well.
projectFile ? null,
# The NuGet dependency file. This locks all NuGet dependency versions, as otherwise they cannot be deterministically fetched.
# This can be generated by running the `passthru.fetch-deps` script.
nugetDeps ? null,
# A list of derivations containing nupkg packages for local project references.
# Referenced derivations can be built with `buildDotnetModule` with `packNupkg=true` flag.
# Since we are sharing them as nugets they must be added to csproj/fsproj files as `PackageReference` as well.
# For example, your project has a local dependency:
# <ProjectReference Include="../foo/bar.fsproj" />
# To enable discovery through `projectReferences` you would need to add a line:
# <ProjectReference Include="../foo/bar.fsproj" />
# <PackageReference Include="bar" Version="*" Condition=" '$(ContinuousIntegrationBuild)'=='true' "/>
projectReferences ? [ ],
# Libraries that need to be available at runtime should be passed through this.
# These get wrapped into `LD_LIBRARY_PATH`.
runtimeDeps ? [ ],
# The dotnet runtime ID. If null, fetch-deps will gather dependencies for all
# platforms in meta.platforms which are supported by the sdk.
runtimeId ? null,
# Test filters. This gets passed to `dotnet test --filter`, concatenated using `&`.
# You may also use `disabledTests` to filter tests based on their name.
# See https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-test#filter-option-details for more details.
testFilters ? [ ],
# Tests to disable. This gets passed to `dotnet test --filter "FullyQualifiedName!={}"`, to ensure compatibility with all frameworks.
# You may also use `testFilters` to pass more generic filters to `dotnet test --filter`.
# See https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-test#filter-option-details for more details.
disabledTests ? [ ],
# The project file to run unit tests against. This is usually referenced in the regular project file, but sometimes it needs to be manually set.
# It gets restored and build, but not installed. You may need to regenerate your nuget lockfile after setting this.
testProjectFile ? null,
# The type of build to perform. This is passed to `dotnet` with the `--configuration` flag. Possible values are `Release`, `Debug`, etc.
buildType ? "Release",
# If set to true, builds the application as a self-contained - removing the runtime dependency on dotnet
selfContainedBuild ? false,
# Whether to use an alternative wrapper, that executes the application DLL using the dotnet runtime from the user environment. `dotnet-runtime` is provided as a default in case no .NET is installed
# This is useful for .NET tools and applications that may need to run under different .NET runtimes
useDotnetFromEnv ? false,
# Whether to explicitly enable UseAppHost when building. This is redundant if useDotnetFromEnv is enabled
useAppHost ? true,
# The dotnet SDK to use.
dotnet-sdk ? default-sdk,
# The dotnet runtime to use.
dotnet-runtime ? dotnet-sdk.runtime,
...
}@args:
let
projectFiles = lib.optionals (projectFile != null) (lib.toList projectFile);
testProjectFiles = lib.optionals (testProjectFile != null) (lib.toList testProjectFile);
platforms =
if args ? meta.platforms then
lib.intersectLists args.meta.platforms dotnet-sdk.meta.platforms
else
dotnet-sdk.meta.platforms;
hook = callPackage ./hook { inherit dotnet-runtime; };
inherit (dotnetCorePackages) systemToDotnetRid;
in
args
// {
dotnetInstallPath = installPath;
dotnetExecutables = executables;
dotnetBuildType = buildType;
dotnetProjectFiles = projectFiles;
dotnetTestProjectFiles = testProjectFiles;
dotnetTestFilters = testFilters;
dotnetDisabledTests = disabledTests;
dotnetRuntimeIds = lib.singleton (
if runtimeId != null then runtimeId else systemToDotnetRid stdenvNoCC.hostPlatform.system
);
dotnetRuntimeDeps = map lib.getLib runtimeDeps;
dotnetSelfContainedBuild = selfContainedBuild;
dotnetUseAppHost = useAppHost;
inherit
enableParallelBuilding
dotnetRestoreFlags
dotnetBuildFlags
dotnetTestFlags
dotnetInstallFlags
dotnetPackFlags
dotnetFlags
packNupkg
useDotnetFromEnv
nugetDeps
runtimeId
dotnet-sdk
;
nativeBuildInputs = args.nativeBuildInputs or [ ] ++ [
hook
cacert
makeWrapper
dotnet-sdk
];
buildInputs = args.buildInputs or [ ] ++ dotnet-sdk.packages ++ projectReferences;
# Parse the version attr into a format acceptable for the Version msbuild property
# The actual version attr is saved in InformationalVersion, which accepts an arbitrary string
versionForDotnet =
if !(lib.hasAttr "version" args) || args.version == null then
null
else
let
components = lib.pipe args.version [
lib.splitVersion
(lib.filter (x: (lib.strings.match "[0-9]+" x) != null))
(lib.filter (x: (lib.toIntBase10 x) < 65535)) # one version component in dotnet has to fit in 16 bits
];
in
if (lib.length components) == 0 then
null
else
lib.concatStringsSep "." (
(lib.take 4 components)
++ (if (lib.length components) < 4 then lib.replicate (4 - (lib.length components)) "0" else [ ])
);
makeWrapperArgs = args.makeWrapperArgs or [ ] ++ [
"--prefix"
"LD_LIBRARY_PATH"
":"
"${dotnet-sdk.icu}/lib"
];
# Stripping breaks the executable
dontStrip = args.dontStrip or true;
# gappsWrapperArgs gets included when wrapping for dotnet, as to avoid double wrapping
dontWrapGApps = args.dontWrapGApps or true;
# propagate the runtime sandbox profile since the contents apply to published
# executables
propagatedSandboxProfile = lib.optionalString (dotnet-runtime != null) (
toString dotnet-runtime.__propagatedSandboxProfile
);
meta = (args.meta or { }) // {
inherit platforms;
};
};
in
fnOrAttrs:
stdenvNoCC.mkDerivation (
finalAttrs:
let
args = if lib.isFunction fnOrAttrs then fnOrAttrs (args' // finalAttrs) else fnOrAttrs;
args' = transformArgs finalAttrs args;
inherit (args')
nugetDeps
runtimeId
meta
dotnet-sdk
;
args'' = removeAttrs args' [
"nugetDeps"
"runtimeId"
"installPath"
"executables"
"projectFile"
"projectReferences"
"runtimeDeps"
"disabledTests"
"testProjectFile"
"buildType"
"selfContainedBuild"
"useDotnet"
"useAppHost"
"dotnet-sdk"
];
in
if nugetDeps != null then
addNuGetDeps {
inherit nugetDeps;
overrideFetchAttrs =
old:
lib.optionalAttrs ((args'.runtimeId or null) == null) rec {
dotnetRuntimeIds = map (system: dotnetCorePackages.systemToDotnetRid system) meta.platforms;
buildInputs =
old.buildInputs
++ lib.concatLists (lib.attrValues (lib.getAttrs dotnetRuntimeIds dotnet-sdk.targetPackages));
};
} args'' finalAttrs
else
args''
)

View File

@@ -0,0 +1,18 @@
{
lib,
which,
coreutils,
makeSetupHook,
# Passed from ../default.nix
dotnet-runtime,
}:
makeSetupHook {
name = "dotnet-hook";
substitutions = {
dotnetRuntime = dotnet-runtime;
wrapperPath = lib.makeBinPath [
which
coreutils
];
};
} ./dotnet-hook.sh

View File

@@ -0,0 +1,450 @@
# shellcheck shell=bash
_dotnetIsSolution() {
dotnet sln ${1:+"$1"} list 2>/dev/null
}
dotnetConfigurePhase() {
echo "Executing dotnetConfigureHook"
runHook preConfigure
local -a projectFiles flags runtimeIds
concatTo projectFiles dotnetProjectFiles dotnetTestProjectFiles
concatTo flags dotnetFlags dotnetRestoreFlags
concatTo runtimeIds dotnetRuntimeIds
if [[ -z ${enableParallelBuilding-} ]]; then
flags+=(--disable-parallel)
fi
if [[ -v dotnetSelfContainedBuild ]]; then
if [[ -n $dotnetSelfContainedBuild ]]; then
flags+=("-p:SelfContained=true")
else
flags+=("-p:SelfContained=false")
fi
fi
dotnetRestore() {
local -r projectFile="${1-}"
for runtimeId in "${runtimeIds[@]}"; do
dotnet restore ${1+"$projectFile"} \
-p:ContinuousIntegrationBuild=true \
-p:Deterministic=true \
-p:NuGetAudit=false \
--runtime "$runtimeId" \
"${flags[@]}"
done
}
if [[ -f .config/dotnet-tools.json || -f dotnet-tools.json ]]; then
dotnet tool restore
fi
# dotnetGlobalTool is set in buildDotnetGlobalTool to patch dependencies but
# avoid other project-specific logic. This is a hack, but the old behavior
# is worse as it relied on a bug: setting projectFile to an empty string
# made the hooks actually skip all project-specific logic. Its hard to keep
# backwards compatibility with this odd behavior now since we are using
# arrays, so instead we just pass a variable to indicate that we dont have
# projects.
if [[ -z ${dotnetGlobalTool-} ]]; then
if (( ${#projectFiles[@]} == 0 )); then
dotnetRestore
fi
local projectFile
for projectFile in "${projectFiles[@]}"; do
dotnetRestore "$projectFile"
done
fi
runHook postConfigure
echo "Finished dotnetConfigureHook"
}
if [[ -z "${dontDotnetConfigure-}" && -z "${configurePhase-}" ]]; then
configurePhase=dotnetConfigurePhase
fi
dotnetBuildPhase() {
echo "Executing dotnetBuildHook"
runHook preBuild
local -r dotnetBuildType="${dotnetBuildType-Release}"
local -a projectFiles flags runtimeIds
concatTo projectFiles dotnetProjectFiles dotnetTestProjectFiles
concatTo flags dotnetFlags dotnetBuildFlags
concatTo runtimeIds dotnetRuntimeIds
if [[ -n "${enableParallelBuilding-}" ]]; then
local -r maxCpuFlag="$NIX_BUILD_CORES"
local -r parallelBuildFlag="true"
else
local -r maxCpuFlag="1"
local -r parallelBuildFlag="false"
fi
if [[ -v dotnetSelfContainedBuild ]]; then
if [[ -n $dotnetSelfContainedBuild ]]; then
flags+=("-p:SelfContained=true")
else
flags+=("-p:SelfContained=false")
fi
fi
if [[ -n ${dotnetUseAppHost-} ]]; then
flags+=("-p:UseAppHost=true")
fi
if [[ -n ${version-} ]]; then
flags+=("-p:InformationalVersion=$version")
fi
if [[ -n ${versionForDotnet-} ]]; then
flags+=("-p:Version=$versionForDotnet")
fi
dotnetBuild() {
local -r projectFile="${1-}"
local useRuntime=
_dotnetIsSolution "$projectFile" || useRuntime=1
for runtimeId in "${runtimeIds[@]}"; do
local runtimeIdFlags=()
if [[ -n $useRuntime ]]; then
runtimeIdFlags+=("--runtime" "$runtimeId")
fi
dotnet build ${1+"$projectFile"} \
-maxcpucount:"$maxCpuFlag" \
-p:BuildInParallel="$parallelBuildFlag" \
-p:ContinuousIntegrationBuild=true \
-p:Deterministic=true \
-p:OverwriteReadOnlyFiles=true \
--configuration "$dotnetBuildType" \
--no-restore \
"${runtimeIdFlags[@]}" \
"${flags[@]}"
done
}
if (( ${#projectFiles[@]} == 0 )); then
dotnetBuild
fi
local projectFile
for projectFile in "${projectFiles[@]}"; do
dotnetBuild "$projectFile"
done
runHook postBuild
echo "Finished dotnetBuildHook"
}
if [[ -z ${dontDotnetBuild-} && -z ${buildPhase-} ]]; then
buildPhase=dotnetBuildPhase
fi
dotnetCheckPhase() {
echo "Executing dotnetCheckHook"
runHook preCheck
local -r dotnetBuildType="${dotnetBuildType-Release}"
local -a projectFiles testProjectFiles testFilters disabledTests flags runtimeIds runtimeDeps
concatTo projectFiles dotnetProjectFiles
concatTo testProjectFiles dotnetTestProjectFiles
concatTo testFilters dotnetTestFilters
concatTo disabledTests dotnetDisabledTests
concatTo flags dotnetFlags dotnetTestFlags
concatTo runtimeIds dotnetRuntimeIds
concatTo runtimeDeps dotnetRuntimeDeps
if (( ${#disabledTests[@]} > 0 )); then
local disabledTestsFilters=("${disabledTests[@]/#/FullyQualifiedName!=}")
testFilters=( "${testFilters[@]}" "${disabledTestsFilters[@]//,/%2C}" )
fi
if (( ${#testFilters[@]} > 0 )); then
local OLDIFS="$IFS" IFS='&'
flags+=("--filter:${testFilters[*]}")
IFS="$OLDIFS"
fi
local libraryPath="${LD_LIBRARY_PATH-}"
if (( ${#runtimeDeps[@]} > 0 )); then
local libraryPaths=("${runtimeDeps[@]/%//lib}")
local OLDIFS="$IFS" IFS=':'
libraryPath="${libraryPaths[*]}${libraryPath:+':'}$libraryPath"
IFS="$OLDIFS"
fi
if [[ -n ${enableParallelBuilding-} ]]; then
local -r maxCpuFlag="$NIX_BUILD_CORES"
else
local -r maxCpuFlag="1"
fi
local projectFile runtimeId
for projectFile in "${testProjectFiles[@]-${projectFiles[@]}}"; do
local useRuntime=
_dotnetIsSolution "$projectFile" || useRuntime=1
for runtimeId in "${runtimeIds[@]}"; do
local runtimeIdFlags=()
if [[ -n $useRuntime ]]; then
runtimeIdFlags=("--runtime" "$runtimeId")
fi
LD_LIBRARY_PATH=$libraryPath \
dotnet test "$projectFile" \
-maxcpucount:"$maxCpuFlag" \
-p:ContinuousIntegrationBuild=true \
-p:Deterministic=true \
--configuration "$dotnetBuildType" \
--no-restore \
--no-build \
--logger "console;verbosity=normal" \
"${runtimeIdFlags[@]}" \
"${flags[@]}"
done
done
runHook postCheck
echo "Finished dotnetCheckHook"
}
if [[ -z "${dontDotnetCheck-}" && -z "${checkPhase-}" ]]; then
checkPhase=dotnetCheckPhase
fi
# For compatibility, convert makeWrapperArgs to an array unless we are using
# structured attributes. That is, we ensure that makeWrapperArgs is always an
# array.
# See https://github.com/NixOS/nixpkgs/blob/858f4db3048c5be3527e183470e93c1a72c5727c/pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-fixup-hook.sh#L1-L3
# and https://github.com/NixOS/nixpkgs/pull/313005#issuecomment-2175482920
# shellcheck disable=2206
if [[ -z $__structuredAttrs ]]; then
makeWrapperArgs=( ${makeWrapperArgs-} )
fi
# First argument is the executable you want to wrap,
# the second is the destination for the wrapper.
wrapDotnetProgram() {
local -r dotnetRuntime=@dotnetRuntime@
local -r wrapperPath=@wrapperPath@
# shellcheck disable=2016
local -r dotnetFromEnvScript='dotnetFromEnv() {
local dotnetPath
if command -v dotnet 2>&1 >/dev/null; then
dotnetPath=$(which dotnet) && \
dotnetPath=$(realpath "$dotnetPath") && \
dotnetPath=$(dirname "$dotnetPath") && \
export DOTNET_ROOT="$dotnetPath"
fi
}
dotnetFromEnv'
# shellcheck disable=2206
local -a runtimeDeps
concatTo runtimeDeps dotnetRuntimeDeps
local wrapperFlags=()
if (( ${#runtimeDeps[@]} > 0 )); then
local libraryPath=("${runtimeDeps[@]/%//lib}")
local OLDIFS="$IFS" IFS=':'
wrapperFlags+=("--suffix" "LD_LIBRARY_PATH" ":" "${libraryPath[*]}")
IFS="$OLDIFS"
fi
if [[ -z ${dotnetSelfContainedBuild-} ]]; then
if [[ -n ${useDotnetFromEnv-} ]]; then
# if dotnet CLI is available, set DOTNET_ROOT based on it. Otherwise set to default .NET runtime
wrapperFlags+=("--suffix" "PATH" ":" "$wrapperPath")
wrapperFlags+=("--run" "$dotnetFromEnvScript")
if [[ -n $dotnetRuntime ]]; then
wrapperFlags+=("--set-default" "DOTNET_ROOT" "$dotnetRuntime/share/dotnet")
wrapperFlags+=("--suffix" "PATH" ":" "$dotnetRuntime/bin")
fi
elif [[ -n $dotnetRuntime ]]; then
wrapperFlags+=("--set" "DOTNET_ROOT" "$dotnetRuntime/share/dotnet")
wrapperFlags+=("--prefix" "PATH" ":" "$dotnetRuntime/bin")
fi
fi
# shellcheck disable=2154
makeWrapper "$1" "$2" \
"${wrapperFlags[@]}" \
"${gappsWrapperArgs[@]}" \
"${makeWrapperArgs[@]}"
echo "installed wrapper to $2"
}
dotnetFixupPhase() {
local -r dotnetInstallPath="${dotnetInstallPath-$out/lib/$pname}"
local executable executableBasename
# check if dotnetExecutables is declared (including empty values, in which case we generate no executables)
# shellcheck disable=2154
if declare -p dotnetExecutables &>/dev/null; then
# shellcheck disable=2206
local -a executables
concatTo executables dotnetExecutables
for executable in "${executables[@]}"; do
executableBasename=$(basename "$executable")
local path="$dotnetInstallPath/$executable"
if test -x "$path"; then
wrapDotnetProgram "$path" "$out/bin/$executableBasename"
else
echo "Specified binary \"$executable\" is either not an executable or does not exist!"
echo "Looked in $path"
exit 1
fi
done
else
while IFS= read -r -d '' executable; do
executableBasename=$(basename "$executable")
wrapDotnetProgram "$executable" "$out/bin/$executableBasename" \;
done < <(find "$dotnetInstallPath" ! -name "*.dll" -executable -type f -print0)
fi
}
if [[ -z "${dontFixup-}" && -z "${dontDotnetFixup-}" ]]; then
appendToVar preFixupPhases dotnetFixupPhase
fi
dotnetInstallPhase() {
echo "Executing dotnetInstallHook"
runHook preInstall
local -r dotnetInstallPath="${dotnetInstallPath-$out/lib/$pname}"
local -r dotnetBuildType="${dotnetBuildType-Release}"
local -a projectFiles flags installFlags packFlags runtimeIds
concatTo projectFiles dotnetProjectFiles
concatTo flags dotnetFlags
concatTo installFlags dotnetInstallFlags
concatTo packFlags dotnetPackFlags
concatTo runtimeIds dotnetRuntimeIds
if [[ -v dotnetSelfContainedBuild ]]; then
if [[ -n $dotnetSelfContainedBuild ]]; then
installFlags+=("--self-contained")
else
installFlags+=("--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
installFlags+=("-p:PublishTrimmed=false")
fi
fi
if [[ -n ${dotnetUseAppHost-} ]]; then
installFlags+=("-p:UseAppHost=true")
fi
if [[ -n ${enableParallelBuilding-} ]]; then
local -r maxCpuFlag="$NIX_BUILD_CORES"
else
local -r maxCpuFlag="1"
fi
dotnetPublish() {
local -r projectFile="${1-}"
local useRuntime=
_dotnetIsSolution "$projectFile" || useRuntime=1
for runtimeId in "${runtimeIds[@]}"; do
local runtimeIdFlags=()
if [[ -n $useRuntime ]]; then
runtimeIdFlags+=("--runtime" "$runtimeId")
fi
dotnet publish ${1+"$projectFile"} \
-maxcpucount:"$maxCpuFlag" \
-p:ContinuousIntegrationBuild=true \
-p:Deterministic=true \
-p:OverwriteReadOnlyFiles=true \
--output "$dotnetInstallPath" \
--configuration "$dotnetBuildType" \
--no-restore \
--no-build \
"${runtimeIdFlags[@]}" \
"${flags[@]}" \
"${installFlags[@]}"
done
}
dotnetPack() {
local -r projectFile="${1-}"
local useRuntime=
_dotnetIsSolution "$projectFile" || useRuntime=1
for runtimeId in "${runtimeIds[@]}"; do
local runtimeIdFlags=()
if [[ -n $useRuntime ]]; then
runtimeIdFlags+=("--runtime" "$runtimeId")
# set RuntimeIdentifier because --runtime is broken:
# https://github.com/dotnet/sdk/issues/13983
runtimeIdFlags+=(-p:RuntimeIdentifier="$runtimeId")
fi
dotnet pack ${1+"$projectFile"} \
-maxcpucount:"$maxCpuFlag" \
-p:ContinuousIntegrationBuild=true \
-p:Deterministic=true \
-p:OverwriteReadOnlyFiles=true \
--output "$out/share/nuget/source" \
--configuration "$dotnetBuildType" \
--no-restore \
--no-build \
"${runtimeIdFlags[@]}" \
"${flags[@]}" \
"${packFlags[@]}"
done
}
if (( ${#projectFiles[@]} == 0 )); then
dotnetPublish
else
local projectFile
for projectFile in "${projectFiles[@]}"; do
dotnetPublish "$projectFile"
done
fi
if [[ -n ${packNupkg-} ]]; then
if (( ${#projectFiles[@]} == 0 )); then
dotnetPack
else
local projectFile
for projectFile in "${projectFiles[@]}"; do
dotnetPack "$projectFile"
done
fi
fi
runHook postInstall
echo "Finished dotnetInstallHook"
}
if [[ -z "${dontDotnetInstall-}" && -z "${installPhase-}" ]]; then
installPhase=dotnetInstallPhase
fi