diff options
author | github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> | 2023-06-21 00:03:02 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-21 00:03:02 +0000 |
commit | 74d0f1c45269764544059d08935ac5a21af3b747 (patch) | |
tree | 0be665df694c99cfe7bd9e3eb1e1cdd4899b8f5a /pkgs/build-support | |
parent | f09649254a3eae38ba4b353afba7e2f58e3c0bc9 (diff) | |
parent | e71099eef107de68b16a8c6a2d8afed1bec504c5 (diff) |
Merge staging-next into staging
Diffstat (limited to 'pkgs/build-support')
5 files changed, 83 insertions, 8 deletions
diff --git a/pkgs/build-support/dotnet/build-dotnet-global-tool/default.nix b/pkgs/build-support/dotnet/build-dotnet-global-tool/default.nix new file mode 100644 index 0000000000000..5e63aa669c568 --- /dev/null +++ b/pkgs/build-support/dotnet/build-dotnet-global-tool/default.nix @@ -0,0 +1,48 @@ +{ buildDotnetModule, emptyDirectory, mkNugetDeps, dotnet-sdk }: + +{ pname +, version + # Name of the nuget package to install, if different from pname +, nugetName ? pname + # Hash of the nuget package to install, will be given on first build +, nugetSha256 ? "" + # Additional nuget deps needed by the tool package +, nugetDeps ? (_: []) + # Executables to wrap into `$out/bin`, same as in `buildDotnetModule`, but with + # a default of `pname` instead of null, to avoid auto-wrapping everything +, executables ? pname + # The dotnet runtime to use, dotnet tools need a full SDK to function +, dotnet-runtime ? dotnet-sdk +, ... +} @ args: + +buildDotnetModule (args // { + inherit pname version dotnet-runtime executables; + + src = emptyDirectory; + + nugetDeps = mkNugetDeps { + name = pname; + nugetDeps = { fetchNuGet }: [ + (fetchNuGet { pname = nugetName; inherit version; sha256 = nugetSha256; }) + ] ++ (nugetDeps fetchNuGet); + }; + + projectFile = ""; + + useDotnetFromEnv = true; + + dontBuld = true; + + installPhase = '' + runHook preInstall + + dotnet tool install --tool-path $out/lib/${pname} ${nugetName} + + # remove files that contain nix store paths to temp nuget sources we made + find $out -name 'project.assets.json' -delete + find $out -name '.nupkg.metadata' -delete + + runHook postInstall + ''; +}) diff --git a/pkgs/build-support/dotnet/build-dotnet-module/default.nix b/pkgs/build-support/dotnet/build-dotnet-module/default.nix index 07e62835956fa..a9c49d1e526eb 100644 --- a/pkgs/build-support/dotnet/build-dotnet-module/default.nix +++ b/pkgs/build-support/dotnet/build-dotnet-module/default.nix @@ -12,6 +12,7 @@ , nuget-to-nix , cacert , coreutils +, runtimeShellPackage }: { name ? "${args.pname}-${args.version}" @@ -74,7 +75,10 @@ , buildType ? "Release" # If set to true, builds the application as a self-contained - removing the runtime dependency on dotnet , selfContainedBuild ? false - # Whether to explicitly enable UseAppHost when building + # 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 enabledz , useAppHost ? true # The dotnet SDK to use. , dotnet-sdk ? dotnetCorePackages.sdk_6_0 @@ -158,7 +162,7 @@ stdenvNoCC.mkDerivation (args // { # gappsWrapperArgs gets included when wrapping for dotnet, as to avoid double wrapping dontWrapGApps = args.dontWrapGApps or true; - inherit selfContainedBuild useAppHost; + inherit selfContainedBuild useAppHost useDotnetFromEnv; passthru = { inherit nuget-source; @@ -183,7 +187,7 @@ stdenvNoCC.mkDerivation (args // { writeShellScript "fetch-${pname}-deps" '' set -euo pipefail - export PATH="${lib.makeBinPath [ coreutils dotnet-sdk (nuget-to-nix.override { inherit dotnet-sdk; }) ]}" + export PATH="${lib.makeBinPath [ coreutils runtimeShellPackage dotnet-sdk (nuget-to-nix.override { inherit dotnet-sdk; }) ]}" for arg in "$@"; do case "$arg" in @@ -262,7 +266,7 @@ stdenvNoCC.mkDerivation (args // { echo "Restoring project..." ${dotnet-sdk}/bin/dotnet tool restore - mv $HOME/.nuget/packages/* $tmp/nuget_pkgs || true + cp -r $HOME/.nuget/packages/* $tmp/nuget_pkgs || true for rid in "${lib.concatStringsSep "\" \"" runtimeIds}"; do (( ''${#projectFiles[@]} == 0 )) && dotnetRestore "" "$rid" @@ -271,6 +275,8 @@ stdenvNoCC.mkDerivation (args // { dotnetRestore "$project" "$rid" done done + # Second copy, makes sure packages restored by ie. paket are included + cp -r $HOME/.nuget/packages/* $tmp/nuget_pkgs || true echo "Succesfully restored project" diff --git a/pkgs/build-support/dotnet/build-dotnet-module/hooks/default.nix b/pkgs/build-support/dotnet/build-dotnet-module/hooks/default.nix index a72f0291a872b..99d9644f8b701 100644 --- a/pkgs/build-support/dotnet/build-dotnet-module/hooks/default.nix +++ b/pkgs/build-support/dotnet/build-dotnet-module/hooks/default.nix @@ -1,4 +1,7 @@ { lib +, stdenv +, which +, coreutils , callPackage , makeSetupHook , makeWrapper @@ -67,6 +70,9 @@ in substitutions = { dotnetRuntime = dotnet-runtime; runtimeDeps = libraryPath; + shell = stdenv.shell; + which = "${which}/bin/which"; + dirname = "${coreutils}/bin/dirname"; }; } ./dotnet-fixup-hook.sh) { }; } diff --git a/pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-configure-hook.sh b/pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-configure-hook.sh index 0e502fe6a14d0..20e353e2b418f 100644 --- a/pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-configure-hook.sh +++ b/pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-configure-hook.sh @@ -25,8 +25,6 @@ dotnetConfigureHook() { ${dotnetFlags[@]} } - (( "${#projectFile[@]}" == 0 )) && dotnetRestore - # Generate a NuGet.config file to make sure everything, # including things like <Sdk /> dependencies, is restored from the proper source cat <<EOF > "./NuGet.config" @@ -39,8 +37,16 @@ cat <<EOF > "./NuGet.config" </configuration> EOF + # Patch paket.dependencies and paket.lock (if found) to use the proper source. This ensures + # paket restore works correctly + # We use + instead of / in sed to avoid problems with slashes + find -name paket.dependencies -exec sed -i 's+source .*+source @nugetSource@/lib+g' {} \; + find -name paket.lock -exec sed -i 's+remote:.*+remote: @nugetSource@/lib+g' {} \; + env dotnet tool restore --add-source "@nugetSource@/lib" + (( "${#projectFile[@]}" == 0 )) && dotnetRestore + for project in ${projectFile[@]} ${testProjectFile[@]-}; do dotnetRestore "$project" done 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 27885238ef7bf..70728e4321ede 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 @@ -5,13 +5,22 @@ makeWrapperArgs=( "${derivationMakeWrapperArgs[@]}" ) # First argument is the executable you want to wrap, # the second is the destination for the wrapper. wrapDotnetProgram() { + local dotnetRootFlags=() + if [ ! "${selfContainedBuild-}" ]; then - local -r dotnetRootFlag=("--set" "DOTNET_ROOT" "@dotnetRuntime@") + if [ "${useDotnetFromEnv-}" ]; then + # if dotnet CLI is available, set DOTNET_ROOT based on it. Otherwise set to default .NET runtime + dotnetRootFlags+=("--run" 'command -v dotnet &>/dev/null && export DOTNET_ROOT="$(@dirname@ "$(@dirname@ "$(@which@ dotnet)")")" || export DOTNET_ROOT="@dotnetRuntime@"') + dotnetRootFlags+=("--suffix" "PATH" ":" "@dotnetRuntime@/bin") + else + dotnetRootFlags+=("--set" "DOTNET_ROOT" "@dotnetRuntime@") + dotnetRootFlags+=("--prefix" "PATH" ":" "@dotnetRuntime@/bin") + fi fi makeWrapper "$1" "$2" \ --suffix "LD_LIBRARY_PATH" : "@runtimeDeps@" \ - "${dotnetRootFlag[@]}" \ + "${dotnetRootFlags[@]}" \ "${gappsWrapperArgs[@]}" \ "${makeWrapperArgs[@]}" |