From deee2d91ca66d8138a842430087b5479ff0f4ded Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torjus=20H=C3=A5kestad?= Date: Sun, 21 Jul 2024 02:41:47 +0200 Subject: [PATCH] Initial commit --- .gitignore | 1 + flake.lock | 27 +++++ flake.nix | 40 ++++++++ pkgs/awakened-poe-trade/default.nix | 137 +++++++++++++++++++++++++ pkgs/path-of-building-beta/default.nix | 94 +++++++++++++++++ scripts/update-pob.sh | 28 +++++ 6 files changed, 327 insertions(+) create mode 100644 .gitignore create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 pkgs/awakened-poe-trade/default.nix create mode 100644 pkgs/path-of-building-beta/default.nix create mode 100755 scripts/update-pob.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b2be92b --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +result diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..685f6f6 --- /dev/null +++ b/flake.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1721379653, + "narHash": "sha256-8MUgifkJ7lkZs3u99UDZMB4kbOxvMEXQZ31FO3SopZ0=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "1d9c2c9b3e71b9ee663d11c5d298727dace8d374", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..a2a0317 --- /dev/null +++ b/flake.nix @@ -0,0 +1,40 @@ +{ + description = "Various packages not in nixpkgs"; + + inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + + outputs = + { self, nixpkgs }: + let + allSystems = [ + "x86_64-linux" + "aarch64-linux" + "x86_64-darwin" + "aarch64-darwin" + ]; + forAllSystems = + f: nixpkgs.lib.genAttrs allSystems (system: f { pkgs = import nixpkgs { inherit system; }; }); + in + { + overlays = { + default = final: prev: { + ghettoptt = self.packages.${prev.system}.awakened-poe-trade; + path-of-building-beta = self.packages.${prev.system}.path-of-building-beta; + }; + awakened-poe-trade = final: prev: { + awakened-poe-trade = self.packages.${prev.system}.awakened-poe-trade; + }; + path-of-building-beta = final: prev: { + awakened-poe-trade = self.packages.${prev.system}.path-of-building-beta; + }; + }; + + packages = forAllSystems ( + { pkgs }: + { + awakened-poe-trade = pkgs.callPackage ./pkgs/awakened-poe-trade { }; + path-of-building-beta = pkgs.qt6Packages.callPackage ./pkgs/path-of-building-beta { }; + } + ); + }; +} diff --git a/pkgs/awakened-poe-trade/default.nix b/pkgs/awakened-poe-trade/default.nix new file mode 100644 index 0000000..45a795d --- /dev/null +++ b/pkgs/awakened-poe-trade/default.nix @@ -0,0 +1,137 @@ +{ + stdenv, + lib, + fetchFromGitHub, + fetchYarnDeps, + yarn, + yarnConfigHook, + yarnBuildHook, + makeWrapper, + libGL, + nodejs, + electron, + xorg, + wayland, + libglvnd, +}: +let + pkgVersion = "3.24.10004"; + + pkgSrc = fetchFromGitHub { + owner = "SnosMe"; + repo = "awakened-poe-trade"; + rev = "v${pkgVersion}"; + hash = "sha256-khIJIOT5Us792YThruNZfnpfBrcPS/vjoAdLI6V4Nwo="; + }; + + yarnCacheRenderer = fetchYarnDeps { + yarnLock = pkgSrc + "/renderer/yarn.lock"; + hash = "sha256-hOfE8XCu1Y4yZzOKHhaNkqKxJ6gxZS5SLRlBxvq3LwY="; + }; + + yarnCacheMain = fetchYarnDeps { + yarnLock = pkgSrc + "/main/yarn.lock"; + hash = "sha256-VLDsqCKrNF7Smywg3yRrjgMG0lmZt8uzeTHKr5n2JMw="; + }; + + renderer = stdenv.mkDerivation (finalAttrs: { + pname = "awakened-poe-trade-renderer"; + version = "${pkgVersion}"; + src = pkgSrc; + sourceRoot = "${finalAttrs.src.name}/renderer"; + + yarnOfflineCache = yarnCacheRenderer; + + buildPhase = '' + yarn make-index-files + runHook yarnBuildHook + ''; + + installPhase = '' + mkdir -p $out + cp -r dist $out; + ''; + + nativeBuildInputs = [ + yarnConfigHook + yarnBuildHook + nodejs + ]; + }); +in +stdenv.mkDerivation (finalAttrs: { + pname = "awakened-poe-trade"; + version = "${pkgVersion}"; + src = pkgSrc; + sourceRoot = "${finalAttrs.src.name}/main"; + + yarnOfflineCache = yarnCacheMain; + + patchPhase = '' + find . + substituteInPlace electron-builder.yml \ + --replace-fail "../renderer/dist" "${renderer}/dist" \ + --replace-fail "AppImage" "dir" + cat electron-builder.yml + find "${renderer}" + ''; + + env = { + ELECTRON_SKIP_BINARY_DOWNLOAD = 1; + ELECTRON_OVERRIDE_DIST_PATH = "${electron}"; + }; + + nativeBuildInputs = [ + yarnConfigHook + yarnBuildHook + yarn + nodejs + electron + makeWrapper + renderer + ]; + + # yarnBuildScript = "electron-builder"; + # yarnBuildFlags = [ + # "--dir" + # "-c.electronDist=${electron}/libexec/electron" + # "-c.electronVersion=${electron.version}" + # ]; + buildPhase = '' + runHook yarnBuildHook + yarn run electron-builder --dir -c.electronDist=${electron}/libexec/electron -c.electronVersion=${electron.version} + find dist + ''; + + installPhase = '' + runHook preInstall + mkdir -p "$out/share/lib/awakened-poe-trade" + cp -r ./dist/*-unpacked/{locales,resources{,.pak}} "$out/share/lib/awakened-poe-trade" + cp -r "${renderer}/dist/data" "$out/share/lib/awakened-poe-trade/resources/data" + echo "${renderer}" + + makeWrapper '${electron}/bin/electron' "$out/bin/awakened-poe-trade" \ + --set LD_LIBRARY_PATH "${ + lib.makeLibraryPath [ + libGL + xorg.libXtst + xorg.libXt + wayland + libglvnd + ] + }" \ + --add-flags "$out/share/lib/awakened-poe-trade/resources/app.asar" \ + --add-flags "\''${NIXOS_OZONE_WL:+\''${WAYLAND_DISPLAY:+--ozone-platform-hint=auto --enable-features=WaylandWindowDecorations}}" \ + --inherit-argv0 + runHook postInstall + ''; + + buildInputs = [ electron ]; + + meta = { + description = "Path of Exile trading app for price checking"; + homepage = "https://github.com/SnosMe/awakened-poe-trade"; + license = lib.licenses.mit; + mainProgram = "awakened-poe-trade"; + }; +}) diff --git a/pkgs/path-of-building-beta/default.nix b/pkgs/path-of-building-beta/default.nix new file mode 100644 index 0000000..c2b2f3a --- /dev/null +++ b/pkgs/path-of-building-beta/default.nix @@ -0,0 +1,94 @@ +{ + stdenv, + lib, + fetchFromGitHub, + unzip, + meson, + ninja, + pkg-config, + qtbase, + qttools, + wrapQtAppsHook, + luajit, +}: +let + data = stdenv.mkDerivation (finalAttrs: { + pname = "path-of-building-data"; + version = "2.43.0-beta"; + + src = fetchFromGitHub { + owner = "PathOfBuildingCommunity"; + repo = "PathOfBuilding"; + rev = "b536f24931c9315cccc9a08ce1d775f2cc1dc713"; + hash = "sha256-TNZcMVp7riBlFj2ELuf2jeh/L5dbocWCcsH6EmVY4xs="; + }; + + nativeBuildInputs = [ unzip ]; + + buildCommand = '' + # I have absolutely no idea how this file is generated + # and I don't think I want to know. The Flatpak also does this. + unzip -j -d $out $src/runtime-win32.zip lua/sha1.lua + + # Install the actual data + cp -r $src/src $src/runtime/lua/*.lua $src/manifest.xml $out + + # Pretend this is an official build so we don't get the ugly "dev mode" warning + substituteInPlace $out/manifest.xml --replace ' $out/src/UpdateCheck.lua + ''; + }); +in +stdenv.mkDerivation { + pname = "path-of-building"; + version = "${data.version}-unstable-2023-04-09"; + + src = fetchFromGitHub { + owner = "ernstp"; + repo = "pobfrontend"; + rev = "9faa19aa362f975737169824c1578d5011487c18"; + hash = "sha256-zhw2PZ6ZNMgZ2hG+a6AcYBkeg7kbBHNc2eSt4if17Wk="; + }; + + nativeBuildInputs = [ + meson + ninja + pkg-config + qttools + wrapQtAppsHook + ]; + buildInputs = [ + qtbase + luajit + luajit.pkgs.lua-curl + ]; + + installPhase = '' + runHook preInstall + install -Dm555 pobfrontend $out/bin/pobfrontend + runHook postInstall + ''; + + preFixup = '' + qtWrapperArgs+=( + --set LUA_PATH "$LUA_PATH" + --set LUA_CPATH "$LUA_CPATH" + --chdir "${data}" + ) + ''; + + passthru.data = data; + + meta = { + description = "Offline build planner for Path of Exile"; + homepage = "https://pathofbuilding.community/"; + license = lib.licenses.mit; + maintainers = [ lib.maintainers.k900 ]; + mainProgram = "pobfrontend"; + broken = stdenv.isDarwin; # doesn't find uic6 for some reason + }; +} diff --git a/scripts/update-pob.sh b/scripts/update-pob.sh new file mode 100755 index 0000000..6c69e50 --- /dev/null +++ b/scripts/update-pob.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env bash +set -eo pipefail +# set -x + +# TODO: Update pobfrontend as well? + +POB_NIX_FILE="pkgs/path-of-building-beta/default.nix" + +if [ -z "$1" ]; then + nurl_output=$(nurl -j https://github.com/PathOfBuildingCommunity/PathOfBuilding 2>/dev/null) + rev=$(jq '.args.rev' <<< "$nurl_output") +else + nurl_output=$(nurl -j https://github.com/PathOfBuildingCommunity/PathOfBuilding "$1" 2>/dev/null) +fi + +hash=$(jq '.args.hash' <<< "$nurl_output" | sed 's/\//\\\//g') +echo "Updating pob to $rev" + +# Find lines to replace +rev_line_numbers=$(grep -Fn "rev =" $POB_NIX_FILE| cut -d":" -f1) +rev_line_data=$(head -n1 <<< "$rev_line_numbers") +sed -i "${rev_line_data}s/.*/ rev = $rev;/" $POB_NIX_FILE + +hash_line_numbers=$(grep -Fn "hash =" $POB_NIX_FILE| cut -d":" -f1) +hash_line_data=$(head -n1 <<< "$hash_line_numbers") +sed -i "${hash_line_data}s/.*/ hash = $hash;/" $POB_NIX_FILE + +nixfmt $POB_NIX_FILE