dotnet: improve buildDotnetGlobalTool (#361464)
This commit is contained in:
@@ -1,53 +1,79 @@
|
||||
{ buildDotnetModule, emptyDirectory, fetchNupkg, dotnet-sdk }:
|
||||
{
|
||||
buildDotnetModule,
|
||||
emptyDirectory,
|
||||
fetchNupkg,
|
||||
dotnet-sdk,
|
||||
lib,
|
||||
}:
|
||||
|
||||
{ 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
|
||||
# nugetHash uses SRI hash and should be preferred
|
||||
, nugetHash ? ""
|
||||
, 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:
|
||||
fnOrAttrs:
|
||||
|
||||
buildDotnetModule (args // {
|
||||
inherit pname version dotnet-runtime executables;
|
||||
buildDotnetModule (
|
||||
finalAttrs:
|
||||
(
|
||||
{
|
||||
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
|
||||
# nugetHash uses SRI hash and should be preferred
|
||||
nugetHash ? "",
|
||||
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:
|
||||
let
|
||||
nupkg = fetchNupkg {
|
||||
pname = nugetName;
|
||||
inherit version;
|
||||
sha256 = nugetSha256;
|
||||
hash = nugetHash;
|
||||
installable = true;
|
||||
};
|
||||
in
|
||||
args
|
||||
// {
|
||||
inherit
|
||||
pname
|
||||
version
|
||||
dotnet-runtime
|
||||
executables
|
||||
;
|
||||
|
||||
src = emptyDirectory;
|
||||
src = emptyDirectory;
|
||||
|
||||
buildInputs = [
|
||||
(fetchNupkg {
|
||||
pname = nugetName;
|
||||
inherit version;
|
||||
sha256 = nugetSha256;
|
||||
hash = nugetHash;
|
||||
installable = true;
|
||||
})
|
||||
];
|
||||
buildInputs = [ nupkg ];
|
||||
|
||||
dotnetGlobalTool = true;
|
||||
dotnetGlobalTool = true;
|
||||
|
||||
useDotnetFromEnv = true;
|
||||
useDotnetFromEnv = true;
|
||||
|
||||
dontBuild = true;
|
||||
dontBuild = true;
|
||||
|
||||
installPhase = ''
|
||||
runHook preInstall
|
||||
installPhase = ''
|
||||
runHook preInstall
|
||||
|
||||
dotnet tool install --tool-path $out/lib/${pname} ${nugetName}
|
||||
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
|
||||
# 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
|
||||
'';
|
||||
})
|
||||
runHook postInstall
|
||||
'';
|
||||
|
||||
passthru = {
|
||||
updateScript = ./update.sh;
|
||||
nupkg = nupkg;
|
||||
} // args.passthru or {};
|
||||
}
|
||||
)
|
||||
(if lib.isFunction fnOrAttrs then fnOrAttrs finalAttrs else fnOrAttrs)
|
||||
)
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
#!/usr/bin/env nix-shell
|
||||
#!nix-shell -I nixpkgs=./. -i bash -p curl jq nix common-updater-scripts
|
||||
# shellcheck shell=bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
attr=$UPDATE_NIX_ATTR_PATH
|
||||
|
||||
nixeval() {
|
||||
nix --extra-experimental-features nix-command eval --json --impure -f . "$1" | jq -r .
|
||||
}
|
||||
|
||||
nugetName=$(nixeval "$attr.nupkg.pname")
|
||||
|
||||
# always skip prerelease versions for now
|
||||
version=$(curl -fsSL "https://api.nuget.org/v3-flatcontainer/$nugetName/index.json" |
|
||||
jq -er '.versions | last(.[] | select(match("^[0-9]+\\.[0-9]+\\.[0-9]+$")))')
|
||||
|
||||
if [[ $version == $(nixeval "$attr.version") ]]; then
|
||||
echo "$attr" is already version "$version"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
update-source-version "$attr" "$version" --source-key=nupkg.src
|
||||
@@ -2,7 +2,6 @@
|
||||
lib,
|
||||
buildDotnetGlobalTool,
|
||||
dotnetCorePackages,
|
||||
nix-update-script,
|
||||
}:
|
||||
let
|
||||
inherit (dotnetCorePackages) sdk_8_0;
|
||||
@@ -17,10 +16,6 @@ buildDotnetGlobalTool rec {
|
||||
dotnet-sdk = sdk_8_0;
|
||||
dotnet-runtime = sdk_8_0;
|
||||
|
||||
passthru = {
|
||||
updateScript = nix-update-script { };
|
||||
};
|
||||
|
||||
meta = {
|
||||
description = "Roslyn-based LSP language server for C#";
|
||||
mainProgram = "csharp-ls";
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
|
||||
buildDotnetGlobalTool {
|
||||
pname = "csharpier";
|
||||
version = "0.29.1";
|
||||
version = "0.30.2";
|
||||
executables = "dotnet-csharpier";
|
||||
|
||||
nugetHash = "sha256-VW9QzbQfbY3Tz+Gz3hQ7VC4wOtwfIYV1Yq2WJz6bL04=";
|
||||
nugetHash = "sha256-MrpsVlIYyrlu3VvEPcLQRgD2lhfu8ZTN3pUZrZ9nQcA=";
|
||||
|
||||
meta = with lib; {
|
||||
description = "Opinionated code formatter for C#";
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
|
||||
buildDotnetGlobalTool {
|
||||
pname = "pbm";
|
||||
version = "1.3.2";
|
||||
version = "1.4.3";
|
||||
|
||||
nugetHash = "sha256-xu3g8NFLZYnHzBuoIhIiAzaPJqY0xhLWLYi+ORRADH8=";
|
||||
nugetHash = "sha256-R6dmF3HPI2BAcNGLCm6WwBlk4ev6T6jaiJUAWYKf2S4=";
|
||||
|
||||
meta = with lib; {
|
||||
description = "CLI for managing Akka.NET applications and Akka.NET Clusters";
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
{ lib, buildDotnetGlobalTool }:
|
||||
buildDotnetGlobalTool {
|
||||
pname = "upgrade-assistant";
|
||||
version = "0.5.820";
|
||||
version = "0.5.829";
|
||||
|
||||
nugetHash = "sha256-GB+q5aZRkBTeXUbIPjkPsll6pSI/H6Iyh5mY53uT284=";
|
||||
nugetHash = "sha256-N0xEmPQ88jfirGPLJykeAJQYGwELFzKwUWdFxIgiwhY=";
|
||||
|
||||
meta = {
|
||||
homepage = "https://github.com/dotnet/upgrade-assistant";
|
||||
|
||||
@@ -1,11 +1,21 @@
|
||||
{ buildDotnetGlobalTool, lib }:
|
||||
{
|
||||
buildDotnetGlobalTool,
|
||||
lib,
|
||||
testers,
|
||||
}:
|
||||
|
||||
buildDotnetGlobalTool {
|
||||
buildDotnetGlobalTool (finalAttrs: {
|
||||
pname = "fable";
|
||||
version = "4.20.0";
|
||||
version = "4.24.0";
|
||||
|
||||
nugetHash = "sha256-K3908gEbl9crT4wmZfBtvag5Z6qYABfalBfLZlqZuDk=";
|
||||
passthru.updateScript = ./update.sh;
|
||||
nugetHash = "sha256-ERewWqfEyyZKpHFFALpMGJT0fDWywBYY5buU/wTZZTg=";
|
||||
|
||||
passthru.tests = testers.testVersion {
|
||||
package = finalAttrs.finalPackage;
|
||||
# the version is written with an escape sequence for colour, and I couldn't
|
||||
# find a way to disable it
|
||||
version = "[37m${finalAttrs.version}";
|
||||
};
|
||||
|
||||
meta = with lib; {
|
||||
description = "Fable is an F# to JavaScript compiler";
|
||||
@@ -14,6 +24,9 @@ buildDotnetGlobalTool {
|
||||
changelog = "https://github.com/fable-compiler/fable/releases/tag/v${version}";
|
||||
license = licenses.mit;
|
||||
platforms = platforms.linux;
|
||||
maintainers = with maintainers; [ anpin mdarocha ];
|
||||
maintainers = with maintainers; [
|
||||
anpin
|
||||
mdarocha
|
||||
];
|
||||
};
|
||||
}
|
||||
})
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
#!/usr/bin/env nix-shell
|
||||
#!nix-shell -i bash -p curl gnused nix-prefetch jq
|
||||
|
||||
set -euo pipefail
|
||||
URL="https://github.com/fable-compiler/fable"
|
||||
PKG="Fable"
|
||||
ROOT="$(dirname "$(readlink -f "$0")")"
|
||||
NIX_DRV="$ROOT/default.nix"
|
||||
if [ ! -f "$NIX_DRV" ]; then
|
||||
echo "ERROR: cannot find default.nix in $ROOT"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
TMP="$(mktemp -d)"
|
||||
clean_up() {
|
||||
rm -rf "$TMP"
|
||||
}
|
||||
trap clean_up EXIT SIGINT SIGTERM
|
||||
PACKAGES="$TMP/packages"
|
||||
SRC_RW="$TMP/src"
|
||||
|
||||
mkdir -p $SRC_RW
|
||||
mkdir -p $PACKAGES
|
||||
|
||||
|
||||
VER=$(curl -s "https://api.github.com/repos/fable-compiler/fable/releases/latest" | jq -r .tag_name | grep -oP '\d+\.\d+\.\d+' )
|
||||
|
||||
CURRENT_VER=$(grep -oP '(?<=version = ")[^"]+' "$NIX_DRV")
|
||||
if [[ "$CURRENT_VER" == "$VER" ]]; then
|
||||
echo "$PKG is already up to date: $CURRENT_VER"
|
||||
exit
|
||||
fi
|
||||
|
||||
|
||||
NUGET_URL="$(curl -f "https://api.nuget.org/v3/index.json" | jq --raw-output '.resources[] | select(."@type" == "PackageBaseAddress/3.0.0")."@id"')$PKG/$VER/$PKG.$VER.nupkg"
|
||||
HASH=$(nix-hash --to-sri --type sha256 "$(nix-prefetch-url "$NUGET_URL")")
|
||||
|
||||
sed -i "s/version = \".*\"/version = \"$VER\"/" "$NIX_DRV"
|
||||
sed -i "s#nugetHash = \"sha256-.\{44\}\"#nugetHash = \"$HASH\"#" "$NIX_DRV"
|
||||
Reference in New Issue
Block a user