From 5123929a70e353f13b99d78a2491d8395917eae1 Mon Sep 17 00:00:00 2001 From: Lily Foster Date: Thu, 3 Nov 2022 10:23:43 -0400 Subject: [PATCH] kodelife: add updateScript --- .../graphics/kodelife/default.nix | 2 + pkgs/applications/graphics/kodelife/update.sh | 54 +++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100755 pkgs/applications/graphics/kodelife/update.sh diff --git a/pkgs/applications/graphics/kodelife/default.nix b/pkgs/applications/graphics/kodelife/default.nix index a05dbc28be02..45688725c2af 100644 --- a/pkgs/applications/graphics/kodelife/default.nix +++ b/pkgs/applications/graphics/kodelife/default.nix @@ -95,6 +95,8 @@ stdenv.mkDerivation rec { runHook postInstall ''; + passthru.updateScript = ./update.sh; + meta = with lib; { homepage = "https://hexler.net/kodelife"; description = "Real-time GPU shader editor"; diff --git a/pkgs/applications/graphics/kodelife/update.sh b/pkgs/applications/graphics/kodelife/update.sh new file mode 100755 index 000000000000..992f7c2bf434 --- /dev/null +++ b/pkgs/applications/graphics/kodelife/update.sh @@ -0,0 +1,54 @@ +#!/usr/bin/env nix-shell +#!nix-shell -i bash -p nix curl libxml2 jq + +set -euo pipefail + +nixpkgs="$(git rev-parse --show-toplevel || (printf 'Could not find root of nixpkgs repo\nAre we running from within the nixpkgs git repo?\n' >&2; exit 1))" + +attr="${UPDATE_NIX_ATTR_PATH:-kodelife}" +version="$(curl -sSL https://hexler.net/kodelife/appcast/linux | xmllint --xpath '/rss/channel/item/enclosure/@*[local-name()="version"]' - | cut -d= -f2- | tr -d '"' | head -n1)" + +narhash() { + nix --extra-experimental-features nix-command store prefetch-file --json "$url" | jq -r .hash +} + +nixeval() { + if [ "$#" -ge 2 ]; then + systemargs=(--argstr system "$2") + else + systemargs=() + fi + + nix --extra-experimental-features nix-command eval --json --impure "${systemargs[@]}" -f "$nixpkgs" "$1" | jq -r . +} + +findpath() { + path="$(nix --extra-experimental-features nix-command eval --json --impure -f "$nixpkgs" "$1.meta.position" | jq -r . | cut -d: -f1)" + outpath="$(nix --extra-experimental-features nix-command eval --json --impure --expr "builtins.fetchGit \"$nixpkgs\"")" + + if [ -n "$outpath" ]; then + path="${path/$(echo "$outpath" | jq -r .)/$nixpkgs}" + fi + + echo "$path" +} + +oldversion="${UPDATE_NIX_OLD_VERSION:-$(nixeval "$attr".version)}" + +pkgpath="$(findpath "$attr")" + +if [ "$version" = "$oldversion" ]; then + echo 'update.sh: New version same as old version, nothing to do.' + exit 0 +fi + +sed -i -e "/version\s*=/ s|\"$oldversion\"|\"$version\"|" "$pkgpath" + +for system in aarch64-linux armv7l-linux x86_64-linux; do + url="$(nixeval "$attr".src.url "$system")" + + curhash="$(nixeval "$attr".src.outputHash "$system")" + newhash="$(narhash "$url")" + + sed -i -e "s|\"$curhash\"|\"$newhash\"|" "$pkgpath" +done