diff --git a/pkgs/by-name/sp/sparkle/package.nix b/pkgs/by-name/sp/sparkle/package.nix new file mode 100644 index 000000000000..6ebb29124fef --- /dev/null +++ b/pkgs/by-name/sp/sparkle/package.nix @@ -0,0 +1,91 @@ +{ + lib, + stdenv, + fetchurl, + dpkg, + autoPatchelfHook, + nss, + nspr, + alsa-lib, + openssl, + webkitgtk_4_0, + udev, + libayatana-appindicator, + libGL, +}: + +stdenv.mkDerivation (finalAttrs: { + pname = "sparkle"; + version = "1.6.2"; + + src = + let + selectSystem = + attrs: + attrs.${stdenv.hostPlatform.system} or (throw "Unsupported system: ${stdenv.hostPlatform.system}"); + arch = selectSystem { + x86_64-linux = "amd64"; + aarch64-linux = "arm64"; + }; + in + fetchurl { + url = "https://github.com/xishang0128/sparkle/releases/download/${finalAttrs.version}/sparkle-linux-${finalAttrs.version}-${arch}.deb"; + hash = selectSystem { + x86_64-linux = "sha256-lUsKTEtUevBKmz21gu/AEAGXCmp0zcdSafRdncLBlQk="; + aarch64-linux = "sha256-sdsrUnOnvZYxs9tHSFf1k4sgJ9anp9P4s3Wz4oJY5ZU="; + }; + }; + + nativeBuildInputs = [ + dpkg + autoPatchelfHook + ]; + + buildInputs = [ + nss + nspr + alsa-lib + openssl + webkitgtk_4_0 + (lib.getLib stdenv.cc.cc) + ]; + + installPhase = '' + runHook preInstall + + mkdir -p $out/bin + cp -r opt $out/opt + cp -r usr/share $out/share + substituteInPlace $out/share/applications/sparkle.desktop \ + --replace-fail "/opt/Sparkle/sparkle" "sparkle" + ln -s $out/opt/Sparkle/sparkle $out/bin/sparkle + + runHook postInstall + ''; + + preFixup = '' + patchelf --add-needed libGL.so.1 \ + --add-rpath ${ + lib.makeLibraryPath [ + libGL + udev + libayatana-appindicator + ] + } $out/opt/Sparkle/sparkle + ''; + + passthru.updateScript = ./update.sh; + + meta = { + description = "Another Mihomo GUI"; + homepage = "https://github.com/xishang0128/sparkle"; + mainProgram = "sparkle"; + platforms = [ + "aarch64-linux" + "x86_64-linux" + ]; + license = lib.licenses.gpl3Plus; + sourceProvenance = with lib.sourceTypes; [ binaryNativeCode ]; + maintainers = with lib.maintainers; [ emaryn ]; + }; +}) diff --git a/pkgs/by-name/sp/sparkle/update.sh b/pkgs/by-name/sp/sparkle/update.sh new file mode 100755 index 000000000000..76c09d502e29 --- /dev/null +++ b/pkgs/by-name/sp/sparkle/update.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env nix-shell +#!nix-shell -i bash -p bash nix curl coreutils common-updater-scripts nix-update + +currentVersion=$(nix-instantiate --eval -E "with import ./. {}; sparkle.version or (lib.getVersion sparkle)" | tr -d '"') +nix-update sparkle +latestVersion=$(nix-instantiate --eval -E "with import ./. {}; sparkle.version or (lib.getVersion sparkle)" | tr -d '"') + +echo "latest version: $latestVersion" +echo "current version: $currentVersion" + +if [[ "$latestVersion" == "$currentVersion" ]]; then + echo "package is up-to-date" + exit 0 +fi + +hash=$(nix hash convert --to sri --hash-algo sha256 $(nix-prefetch-url $(nix-instantiate --eval -E "with import ./. {}; sparkle.src.url" --system aarch64-linux | tr -d '"'))) +update-source-version sparkle $latestVersion $hash --system=aarch64-linux --ignore-same-version