buildDotnetGlobalTool: add default updateScript

This commit is contained in:
David McFarland
2024-12-02 22:32:11 -04:00
parent 07a92bc006
commit 04f1c8b4ea
5 changed files with 39 additions and 54 deletions
@@ -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)
@@ -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
-5
View File
@@ -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";
-1
View File
@@ -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";
-39
View File
@@ -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"