diff --git a/pkgs/build-support/dotnet/build-dotnet-global-tool/default.nix b/pkgs/build-support/dotnet/build-dotnet-global-tool/default.nix index 4b8ad583d82d..f6a832386b9f 100644 --- a/pkgs/build-support/dotnet/build-dotnet-global-tool/default.nix +++ b/pkgs/build-support/dotnet/build-dotnet-global-tool/default.nix @@ -29,6 +29,15 @@ buildDotnetModule ( dotnet-runtime ? dotnet-sdk, ... }@args: + let + nupkg = fetchNupkg { + pname = nugetName; + inherit version; + sha256 = nugetSha256; + hash = nugetHash; + installable = true; + }; + in args // { inherit @@ -40,15 +49,7 @@ buildDotnetModule ( src = emptyDirectory; - buildInputs = [ - (fetchNupkg { - pname = nugetName; - inherit version; - sha256 = nugetSha256; - hash = nugetHash; - installable = true; - }) - ]; + buildInputs = [ nupkg ]; dotnetGlobalTool = true; @@ -67,6 +68,11 @@ buildDotnetModule ( runHook postInstall ''; + + passthru = { + updateScript = ./update.sh; + nupkg = nupkg; + } // args.passthru or {}; } ) (if lib.isFunction fnOrAttrs then fnOrAttrs finalAttrs else fnOrAttrs) diff --git a/pkgs/build-support/dotnet/build-dotnet-global-tool/update.sh b/pkgs/build-support/dotnet/build-dotnet-global-tool/update.sh new file mode 100755 index 000000000000..e00fae9ace36 --- /dev/null +++ b/pkgs/build-support/dotnet/build-dotnet-global-tool/update.sh @@ -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 diff --git a/pkgs/by-name/cs/csharp-ls/package.nix b/pkgs/by-name/cs/csharp-ls/package.nix index 1ae39b36d2bb..4f2972575637 100644 --- a/pkgs/by-name/cs/csharp-ls/package.nix +++ b/pkgs/by-name/cs/csharp-ls/package.nix @@ -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"; diff --git a/pkgs/development/tools/fable/default.nix b/pkgs/development/tools/fable/default.nix index ea5362daa90f..172c3d310321 100644 --- a/pkgs/development/tools/fable/default.nix +++ b/pkgs/development/tools/fable/default.nix @@ -5,7 +5,6 @@ buildDotnetGlobalTool { version = "4.20.0"; nugetHash = "sha256-K3908gEbl9crT4wmZfBtvag5Z6qYABfalBfLZlqZuDk="; - passthru.updateScript = ./update.sh; meta = with lib; { description = "Fable is an F# to JavaScript compiler"; diff --git a/pkgs/development/tools/fable/update.sh b/pkgs/development/tools/fable/update.sh deleted file mode 100755 index 181570d1a0de..000000000000 --- a/pkgs/development/tools/fable/update.sh +++ /dev/null @@ -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"