incus-spawn: use update-source-version and passthru.sources

* Move srcs and git-remote-isx into passthru.
* Replace the custom update.sh with an inline writeShellScript
that uses update-source-version from common-updater-scripts,
following the pattern of bun and proton-pass-cli.
This commit is contained in:
Galder Zamarreño
2026-07-08 16:10:55 +02:00
parent 1a2873d119
commit 0037a21101
2 changed files with 54 additions and 95 deletions
+54 -38
View File
@@ -7,42 +7,23 @@
zlib,
testers,
incus-spawn,
writeShellScript,
curl,
jq,
common-updater-scripts,
}:
let
stdenv = stdenvNoCC;
stdenvNoCC.mkDerivation (finalAttrs: {
version = "0.2.7";
srcs = {
x86_64-linux = fetchurl {
url = "https://github.com/Sanne/incus-spawn/releases/download/v${version}/incus-spawn-linux-amd64";
hash = "sha256-jgdNuVfVshbg8piAGGpIy4cnJj5glbsGqOENDBoqpzI=";
};
aarch64-linux = fetchurl {
url = "https://github.com/Sanne/incus-spawn/releases/download/v${version}/incus-spawn-linux-aarch64";
hash = "sha256-Y7OaNgQKAN/HVt75+tawrCtkyZdAHfAiUxx2a0eD5P8=";
};
aarch64-darwin = fetchurl {
url = "https://github.com/Sanne/incus-spawn/releases/download/v${version}/incus-spawn-macos-aarch64";
hash = "sha256-Uv0v7LxIcB0oNEnW1vK9Iy6MOwxoUeqtszGfsS5wt6k=";
};
};
git-remote-isx = fetchurl {
url = "https://github.com/Sanne/incus-spawn/releases/download/v${version}/git-remote-isx";
hash = "sha256-I9zmdLzO7VcfLHdgFD2Lvwiq4fkDw885j1JWsL8c+hA=";
};
in
stdenv.mkDerivation (finalAttrs: {
pname = "incus-spawn";
inherit version;
src =
srcs.${stdenv.hostPlatform.system} or (throw "Unsupported platform: ${stdenv.hostPlatform.system}");
finalAttrs.passthru.sources.${stdenvNoCC.hostPlatform.system}
or (throw "Unsupported platform: ${stdenvNoCC.hostPlatform.system}");
dontUnpack = true;
dontBuild = true;
dontStrip = stdenv.hostPlatform.isDarwin;
dontStrip = stdenvNoCC.hostPlatform.isDarwin;
strictDeps = true;
__structuredAttrs = true;
@@ -50,9 +31,9 @@ stdenv.mkDerivation (finalAttrs: {
nativeBuildInputs = [
installShellFiles
]
++ lib.optional stdenv.hostPlatform.isLinux autoPatchelfHook;
++ lib.optional stdenvNoCC.hostPlatform.isLinux autoPatchelfHook;
buildInputs = lib.optionals stdenv.hostPlatform.isLinux [
buildInputs = lib.optionals stdenvNoCC.hostPlatform.isLinux [
zlib
];
@@ -60,7 +41,7 @@ stdenv.mkDerivation (finalAttrs: {
runHook preInstall
install -Dm755 $src $out/bin/isx
install -Dm755 ${git-remote-isx} $out/bin/git-remote-isx
install -Dm755 ${finalAttrs.passthru.git-remote-isx} $out/bin/git-remote-isx
runHook postInstall
'';
@@ -69,7 +50,7 @@ stdenv.mkDerivation (finalAttrs: {
# On Linux, autoPatchelfHook runs in postFixupHooks so we use installCheckPhase
# which runs after fixup is fully complete. On Darwin no patching is needed but
# we keep the same phase for consistency.
doInstallCheck = stdenv.buildPlatform.canExecute stdenv.hostPlatform;
doInstallCheck = stdenvNoCC.buildPlatform.canExecute stdenvNoCC.hostPlatform;
installCheckPhase = ''
runHook preInstallCheck
@@ -82,11 +63,50 @@ stdenv.mkDerivation (finalAttrs: {
'';
passthru = {
sources = {
"x86_64-linux" = fetchurl {
url = "https://github.com/Sanne/incus-spawn/releases/download/v${finalAttrs.version}/incus-spawn-linux-amd64";
hash = "sha256-jgdNuVfVshbg8piAGGpIy4cnJj5glbsGqOENDBoqpzI=";
};
"aarch64-linux" = fetchurl {
url = "https://github.com/Sanne/incus-spawn/releases/download/v${finalAttrs.version}/incus-spawn-linux-aarch64";
hash = "sha256-Y7OaNgQKAN/HVt75+tawrCtkyZdAHfAiUxx2a0eD5P8=";
};
"aarch64-darwin" = fetchurl {
url = "https://github.com/Sanne/incus-spawn/releases/download/v${finalAttrs.version}/incus-spawn-macos-aarch64";
hash = "sha256-Uv0v7LxIcB0oNEnW1vK9Iy6MOwxoUeqtszGfsS5wt6k=";
};
};
git-remote-isx = fetchurl {
url = "https://github.com/Sanne/incus-spawn/releases/download/v${finalAttrs.version}/git-remote-isx";
hash = "sha256-I9zmdLzO7VcfLHdgFD2Lvwiq4fkDw885j1JWsL8c+hA=";
};
tests.version = testers.testVersion {
package = incus-spawn;
command = "isx --version";
};
updateScript = ./update.sh;
updateScript = writeShellScript "update-incus-spawn" ''
set -o errexit
export PATH="${
lib.makeBinPath [
curl
jq
common-updater-scripts
]
}"
NEW_VERSION=$(curl --silent https://api.github.com/repos/Sanne/incus-spawn/releases/latest | jq '.tag_name | ltrimstr("v")' --raw-output)
if [[ "${finalAttrs.version}" = "$NEW_VERSION" ]]; then
echo "incus-spawn is already at $NEW_VERSION"
exit 0
fi
update-source-version incus-spawn "$NEW_VERSION" --source-key="git-remote-isx"
for platform in ${lib.escapeShellArgs finalAttrs.meta.platforms}; do
update-source-version incus-spawn "$NEW_VERSION" --ignore-same-version --source-key="sources.$platform"
done
'';
};
meta = {
@@ -97,14 +117,10 @@ stdenv.mkDerivation (finalAttrs: {
for credential isolation, and an interactive TUI.
'';
homepage = "https://github.com/Sanne/incus-spawn";
changelog = "https://github.com/Sanne/incus-spawn/releases/tag/v${version}";
changelog = "https://github.com/Sanne/incus-spawn/releases/tag/v${finalAttrs.version}";
license = lib.licenses.asl20;
sourceProvenance = with lib.sourceTypes; [ binaryNativeCode ];
platforms = [
"x86_64-linux"
"aarch64-linux"
"aarch64-darwin"
];
platforms = lib.attrNames finalAttrs.passthru.sources;
mainProgram = "isx";
maintainers = with lib.maintainers; [
galder
-57
View File
@@ -1,57 +0,0 @@
#!/usr/bin/env nix
#!nix shell --ignore-environment .#cacert .#coreutils .#curl .#bash .#jq .#nix --command bash
# Update script for incus-spawn in nixpkgs.
# Invoked by: nix-shell maintainers/scripts/update.nix --argstr commit true --argstr package incus-spawn
# Or manually: ./update.sh [version]
set -euo pipefail
cd "$(dirname "${BASH_SOURCE[0]}")"
REPO="Sanne/incus-spawn"
PACKAGE_NIX="package.nix"
# Determine target version
if [[ -n "${1:-}" ]]; then
VERSION="${1#v}"
else
VERSION=$(curl -fsSL "https://api.github.com/repos/$REPO/releases/latest" | jq -r '.tag_name' | sed 's/^v//')
fi
CURRENT=$(grep 'version = "' "$PACKAGE_NIX" | head -1 | sed 's/.*"\(.*\)".*/\1/')
if [[ "$VERSION" == "$CURRENT" ]]; then
echo "incus-spawn is already at $VERSION"
exit 0
fi
echo "Updating incus-spawn: $CURRENT -> $VERSION"
# Compute SRI hashes for each artifact
hash_for() {
local url="$1"
nix hash convert --hash-algo sha256 --to sri "$(nix-prefetch-url --type sha256 "$url" 2>/dev/null)"
}
BASE_URL="https://github.com/$REPO/releases/download/v$VERSION"
HASH_AMD64=$(hash_for "$BASE_URL/incus-spawn-linux-amd64")
HASH_AARCH64=$(hash_for "$BASE_URL/incus-spawn-linux-aarch64")
HASH_MACOS=$(hash_for "$BASE_URL/incus-spawn-macos-aarch64")
HASH_GIT_REMOTE=$(hash_for "$BASE_URL/git-remote-isx")
echo " linux-amd64: $HASH_AMD64"
echo " linux-aarch64: $HASH_AARCH64"
echo " macos-aarch64: $HASH_MACOS"
echo " git-remote-isx: $HASH_GIT_REMOTE"
# Update package.nix in place
sed -i \
-e "0,/version = \"[^\"]*\"/s/version = \"[^\"]*\"/version = \"$VERSION\"/" \
-e "/x86_64-linux/,/};/{s|hash = \"[^\"]*\"|hash = \"$HASH_AMD64\"|}" \
-e "/aarch64-linux/,/};/{s|hash = \"[^\"]*\"|hash = \"$HASH_AARCH64\"|}" \
-e "/aarch64-darwin/,/};/{s|hash = \"[^\"]*\"|hash = \"$HASH_MACOS\"|}" \
-e "/git-remote-isx/,/};/{s|hash = \"[^\"]*\"|hash = \"$HASH_GIT_REMOTE\"|}" \
"$PACKAGE_NIX"
echo "Updated $PACKAGE_NIX to $VERSION"