From 490b4b47733a25dd953fc4d3326294c65a35b1e4 Mon Sep 17 00:00:00 2001 From: aszlig Date: Fri, 25 Aug 2017 22:35:28 +0200 Subject: pkgs/games: Add Invisigun Heroes This introduces support for fetching games from itch.io, because the Humble Bundle version unfortunately only provides a Steam key and we obviously don't want that. I only played two levels, but so far it works as intended. Signed-off-by: aszlig --- pkgs/games/itch/default.nix | 28 +++++++++++++++++ pkgs/games/itch/fetch-itch/default.nix | 54 +++++++++++++++++++++++++++++++++ pkgs/games/itch/invisigun-heroes.nix | 55 ++++++++++++++++++++++++++++++++++ 3 files changed, 137 insertions(+) create mode 100644 pkgs/games/itch/default.nix create mode 100644 pkgs/games/itch/fetch-itch/default.nix create mode 100644 pkgs/games/itch/invisigun-heroes.nix (limited to 'pkgs/games/itch') diff --git a/pkgs/games/itch/default.nix b/pkgs/games/itch/default.nix new file mode 100644 index 00000000..34ffc6ed --- /dev/null +++ b/pkgs/games/itch/default.nix @@ -0,0 +1,28 @@ +{ config, lib, pkgs, ... }: + +let + cfg = config.itch; + + self = rec { + callPackage = pkgs.lib.callPackageWith (pkgs // self); + callPackage_i686 = pkgs.lib.callPackageWith (pkgs.pkgsi686Linux // self); + + fetchItch = callPackage ./fetch-itch { + inherit (config.itch) apiKey; + }; + + invisigun-heroes = callPackage ./invisigun-heroes.nix {}; + }; +in { + options.itch.apiKey = lib.mkOption { + type = lib.types.nullOr lib.types.str; + default = null; + description = '' + The API key of your itch.io + account, can be retrieved by heading to . + ''; + }; + + config.packages.itch = lib.mkIf (cfg.apiKey != null) self; +} diff --git a/pkgs/games/itch/fetch-itch/default.nix b/pkgs/games/itch/fetch-itch/default.nix new file mode 100644 index 00000000..ed1ac7f6 --- /dev/null +++ b/pkgs/games/itch/fetch-itch/default.nix @@ -0,0 +1,54 @@ +{ stdenv, curl, cacert, writeText, python3Packages + +, apiKey +}: + +{ name, gameId, uploadId, sha256 }: + +let + cafile = "${cacert}/etc/ssl/certs/ca-bundle.crt"; + + getDownloadURL = writeText "getitch.py" '' + import os, sys, json + + from urllib.parse import urljoin + from urllib.request import urlopen + + API_KEY = os.getenv('apiKey') + API_URL = 'https://itch.io/api/1/' + API_BASE = urljoin(API_URL, API_KEY) + '/' + + NAME = os.getenv('name') + GAME_ID = int(os.getenv('gameId')) + UPLOAD_ID = int(os.getenv('uploadId')) + + def request(path): + with urlopen(urljoin(API_BASE, path)) as u: + return json.loads(u.read()) + + for key in request('my-owned-keys')['owned_keys']: + if key['game']['id'] == GAME_ID: + url = 'download-key/{}/download/{}'.format(key['id'], UPLOAD_ID) + sys.stdout.write(request(url)['url'] + '\n') + raise SystemExit(0) + + sys.stderr.write('Unable to find download for game {}!'.format(NAME)) + raise SystemExit(1) + ''; + +in stdenv.mkDerivation { + inherit name apiKey gameId uploadId; + outputHashAlgo = "sha256"; + outputHash = sha256; + + SSL_CERT_FILE = "${cacert}/etc/ssl/certs/ca-bundle.crt"; + + nativeBuildInputs = [ python3Packages.python ]; + + buildCommand = '' + url="$(python "${getDownloadURL}")" + header "downloading $name from $url" + "${curl.bin or curl}/bin/curl" --fail --output "$out" "$url" + stopNest + ''; +} diff --git a/pkgs/games/itch/invisigun-heroes.nix b/pkgs/games/itch/invisigun-heroes.nix new file mode 100644 index 00000000..86350033 --- /dev/null +++ b/pkgs/games/itch/invisigun-heroes.nix @@ -0,0 +1,55 @@ +{ stdenv, fetchItch, unzip, mesa, xorg, libpulseaudio, libudev +, gtk2-x11, gdk_pixbuf, glib +}: + +stdenv.mkDerivation rec { + name = "invisigun-heroes-${version}"; + version = "1.5.1"; + + src = fetchItch { + name = "${name}.zip"; + gameId = 25561; + uploadId = 208583; + sha256 = "0k92xj3q7yv3pgsb992y0lxp59f1gkl12vw18qipsm1vby6b7j2s"; + }; + + unpackCmd = '' + ${unzip}/bin/unzip -qq -d invisigun-heroes "$src" || : + ''; + + arch = if stdenv.system == "x86_64-linux" then "x86_64" else "x86"; + executable = "Invisigun Heroes.${arch}"; + + buildPhase = let + rpath = stdenv.lib.makeLibraryPath [ + stdenv.cc.cc mesa xorg.libX11 xorg.libXcursor xorg.libXrandr + libpulseaudio libudev + ]; + + ssRpath = stdenv.lib.makeLibraryPath [ + stdenv.cc.cc gtk2-x11 gdk_pixbuf glib + ]; + in '' + patchelf \ + --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \ + --set-rpath ${stdenv.lib.escapeShellArg rpath} "$executable" + + patchelf --set-rpath ${stdenv.lib.escapeShellArg ssRpath} \ + "Invisigun Heroes_Data/Plugins/x86_64/ScreenSelector.so" + ''; + + installPhase = '' + install -vD "$executable" "$out/libexec/invisigun-heroes/invisigun-heroes" + ln -s "$out/share/invisigun-heroes" "$out/libexec/invisigun-heroes/Data" + + mkdir -p "$out/bin" + ln -s "$out/libexec/invisigun-heroes/invisigun-heroes" \ + "$out/bin/invisigun-heroes" + + mkdir -p "$out/share" + cp -vRd "Invisigun Heroes_Data" "$out/share/invisigun-heroes" + ''; + + dontStrip = true; + dontPatchELF = true; +} -- cgit 1.4.1