diff --git a/pkgs/by-name/kr/krunker/darwin.nix b/pkgs/by-name/kr/krunker/darwin.nix new file mode 100644 index 000000000000..e5c0be3a8c46 --- /dev/null +++ b/pkgs/by-name/kr/krunker/darwin.nix @@ -0,0 +1,32 @@ +{ + stdenvNoCC, + fetchurl, + makeBinaryWrapper, + undmg, +}: + +stdenvNoCC.mkDerivation (finalAttrs: { + pname = "krunker"; + version = "2.1.3"; + + src = fetchurl { + url = "https://client2.krunker.io/Official%20Krunker.io%20Client-${finalAttrs.version}.dmg"; + hash = "sha512-brvrOPCsXkkrUGcRxsa8bzpFsrY7GF3llt29ZIax6dC0XBsILKXUleESJ5LpurMOgSBsfxNYjZLPJhicIAtuUA=="; + }; + + sourceRoot = "."; + + nativeBuildInputs = [ + makeBinaryWrapper + undmg + ]; + + postInstall = '' + mkdir -p $out/Applications + cp -r *.app $out/Applications + + makeBinaryWrapper \ + $out/Applications/Official\ Krunker.io\ Client.app/Contents/MacOS/Official\ Krunker.io\ Client \ + $out/bin/krunker + ''; +}) diff --git a/pkgs/by-name/kr/krunker/linux.nix b/pkgs/by-name/kr/krunker/linux.nix new file mode 100644 index 000000000000..53ba2687952f --- /dev/null +++ b/pkgs/by-name/kr/krunker/linux.nix @@ -0,0 +1,30 @@ +{ appimageTools, fetchurl }: + +let + pname = "krunker"; + version = "2.1.3"; + + appId = "io.krunker.desktop"; + + src = fetchurl { + url = "https://client2.krunker.io/Official%20Krunker.io%20Client-${version}.AppImage"; + hash = "sha512-a8E5heLsKXOtv/wRKlrnV0GD48cY1mOiSSDW93c7YZ+HoeuBQDxtRaHKg5EqU51Yi+d4tPF5nOh10jZW36c7WQ=="; + }; + + appimageContents = appimageTools.extractType2 { + inherit pname version src; + }; +in + +appimageTools.wrapType2 { + inherit pname version src; + + extraInstallCommands = '' + mkdir -p $out/share/{applications,pixmaps} + install -Dm644 ${appimageContents}/${appId}.desktop -t $out/share/applications + install -Dm644 ${appimageContents}/${appId}.png -t $out/share/pixmaps + + substituteInPlace $out/share/applications/${appId}.desktop \ + --replace-fail 'Exec=AppRun' "Exec=$pname" + ''; +} diff --git a/pkgs/by-name/kr/krunker/package.nix b/pkgs/by-name/kr/krunker/package.nix new file mode 100644 index 000000000000..76430102a0e6 --- /dev/null +++ b/pkgs/by-name/kr/krunker/package.nix @@ -0,0 +1,32 @@ +{ + lib, + stdenv, + callPackage, +}: + +let + package = + if stdenv.hostPlatform.isDarwin then callPackage ./darwin.nix { } else callPackage ./linux.nix { }; +in + +package.overrideAttrs ( + finalAttrs: oldAttrs: { + passthru = { + updateScript = ./update.sh; + } // oldAttrs.passthru or { }; + + # Point `nix edit`, etc. to the file that defines the attribute, not this + # entry point + pos = builtins.unsafeGetAttrPos "pname" finalAttrs; + + meta = { + description = "Easy to get into fully moddable First Person Shooter with advanced movement mechanics"; + homepage = "https://krunker.io"; + license = lib.licenses.unfree; + maintainers = with lib.maintainers; [ getchoo ]; + mainProgram = "krunker"; + platforms = [ "x86_64-linux" ] ++ lib.platforms.darwin; + sourceProvenance = with lib.sourceTypes; [ binaryNativeCode ]; + } // oldAttrs.meta or { }; + } +) diff --git a/pkgs/by-name/kr/krunker/update.sh b/pkgs/by-name/kr/krunker/update.sh new file mode 100755 index 000000000000..9d68f1239f73 --- /dev/null +++ b/pkgs/by-name/kr/krunker/update.sh @@ -0,0 +1,58 @@ +#!/usr/bin/env nix-shell +#! nix-shell --pure -i bash -p bash cacert common-updater-scripts curl yq +# shellcheck shell=bash +set -euo pipefail + +root=$(readlink -f "$0" | xargs dirname) +script_name="krunker-update" +updater_url="client2.krunker.io" + +log() { + echo "$script_name: $*" +} + +panic() { + log "$*" + exit 1 +} + +update() { + platform="${1:-}" + if [ -z "$platform" ]; then + panic "error: a platform must be supplied to \`update()\`!" + fi + + nixfile="$root"/"$platform".nix + if [ ! -f "$nixfile" ]; then + panic "error: $platform is not supported!" + fi + + electron_suffix="" + system="x86_64-linux" + if [ "$platform" == "darwin" ]; then + electron_suffix="-mac" + system="aarch64-darwin" + elif [ "$platform" == "linux" ]; then + electron_suffix="-linux" + fi + + url="https://$updater_url/latest${electron_suffix}.yml" + log "fetching update information from from $url" + response="$(curl -sSL "$url")" + version="$(yq --raw-output '.version' <<<"$response")" + sha512="$(yq \ + --raw-output \ + '.files | map(select(.url | contains("dmg") or contains("AppImage"))) | first | .sha512' \ + <<<"$response")" + + update-source-version krunker "$version" sha512-"$sha512" --file="$nixfile" --system="$system" +} + +supported_platforms=( + "darwin" + "linux" +) + +for platform in "${supported_platforms[@]}"; do + update "$platform" +done