From 719d7cccccc23a70d4386e226944518c674324b8 Mon Sep 17 00:00:00 2001 From: TomaSajt <62384384+TomaSajt@users.noreply.github.com> Date: Tue, 10 Sep 2024 15:47:43 +0200 Subject: [PATCH 1/2] modrinth-app-unwrapped: refactor and use pnpm hooks --- .../mo/modrinth-app-unwrapped/package.nix | 120 +++++------------- 1 file changed, 35 insertions(+), 85 deletions(-) diff --git a/pkgs/by-name/mo/modrinth-app-unwrapped/package.nix b/pkgs/by-name/mo/modrinth-app-unwrapped/package.nix index c9c5cbdc73f5c..68f444dbe3208 100644 --- a/pkgs/by-name/mo/modrinth-app-unwrapped/package.nix +++ b/pkgs/by-name/mo/modrinth-app-unwrapped/package.nix @@ -1,35 +1,31 @@ { lib, stdenv, - stdenvNoCC, fetchFromGitHub, rustPlatform, buildGoModule, nix-update-script, - modrinth-app-unwrapped, - cacert, cargo-tauri, desktop-file-utils, esbuild, darwin, - jq, libsoup, - moreutils, pnpm_8, nodejs, openssl, pkg-config, webkitgtk, }: -rustPlatform.buildRustPackage { + +rustPlatform.buildRustPackage rec { pname = "modrinth-app-unwrapped"; version = "0.7.1"; src = fetchFromGitHub { owner = "modrinth"; repo = "theseus"; - rev = "v${modrinth-app-unwrapped.version}"; - sha256 = "sha256-JWR0e2vOBvOLosr22Oo2mAlR0KAhL+261RRybhNctlM="; + rev = "refs/tags/v${version}"; + hash = "sha256-JWR0e2vOBvOLosr22Oo2mAlR0KAhL+261RRybhNctlM="; }; cargoLock = { @@ -39,50 +35,22 @@ rustPlatform.buildRustPackage { }; }; - pnpm-deps = stdenvNoCC.mkDerivation (finalAttrs: { - pname = "${modrinth-app-unwrapped.pname}-pnpm-deps"; - inherit (modrinth-app-unwrapped) version src; - sourceRoot = "${finalAttrs.src.name}/theseus_gui"; - - dontConfigure = true; - dontBuild = true; - doCheck = false; - - nativeBuildInputs = [ - cacert - jq - moreutils - pnpm_8 - ]; - - # https://github.com/NixOS/nixpkgs/blob/763e59ffedb5c25774387bf99bc725df5df82d10/pkgs/applications/misc/pot/default.nix#L56 - installPhase = '' - export HOME=$(mktemp -d) - - pnpm config set store-dir "$out" - pnpm install --frozen-lockfile --ignore-script --force - - # remove timestamp and sort json files - rm -rf "$out"/v3/tmp - for f in $(find "$out" -name "*.json"); do - sed -i -E -e 's/"checkedAt":[0-9]+,//g' $f - jq --sort-keys . "$f" | sponge "$f" - done - ''; - - dontFixup = true; - outputHashMode = "recursive"; - outputHash = "sha256-g/uUGfC9TQh0LE8ed51oFY17FySoeTvfaeEpzpNeMao="; - }); - nativeBuildInputs = [ cargo-tauri desktop-file-utils - pnpm_8 + pnpm_8.configHook nodejs pkg-config ]; + pnpmRoot = "theseus_gui"; + + pnpmDeps = pnpm_8.fetchDeps { + inherit pname src; + sourceRoot = "${src.name}/${pnpmRoot}"; + hash = "sha256-g/uUGfC9TQh0LE8ed51oFY17FySoeTvfaeEpzpNeMao="; + }; + buildInputs = [ openssl ] ++ lib.optionals stdenv.isLinux [ @@ -99,48 +67,30 @@ rustPlatform.buildRustPackage { ] ); - env = { - tauriBundle = - { - Linux = "deb"; - Darwin = "app"; - } - .${stdenv.hostPlatform.uname.system} - or (builtins.throw "No tauri bundle available for ${stdenv.hostPlatform.uname.system}!"); - - ESBUILD_BINARY_PATH = lib.getExe ( - esbuild.override { - buildGoModule = args: buildGoModule (args // rec { - version = "0.20.2"; - src = fetchFromGitHub { - owner = "evanw"; - repo = "esbuild"; - rev = "v${version}"; - hash = "sha256-h/Vqwax4B4nehRP9TaYbdixAZdb1hx373dNxNHvDrtY="; - }; - vendorHash = "sha256-+BfxCyg0KkDQpHt/wycy/8CTG6YBA/VJvJFhhzUnSiQ="; - }); - } - ); - }; - - postPatch = '' - export HOME=$(mktemp -d) - export STORE_PATH=$(mktemp -d) - - pushd theseus_gui - cp -rT ${modrinth-app-unwrapped.pnpm-deps} "$STORE_PATH" - chmod -R +w "$STORE_PATH" - - pnpm config set store-dir "$STORE_PATH" - pnpm install --offline --frozen-lockfile --ignore-script - popd - ''; + env.ESBUILD_BINARY_PATH = lib.getExe ( + esbuild.override { + buildGoModule = + args: + buildGoModule ( + args + // rec { + version = "0.20.2"; + src = fetchFromGitHub { + owner = "evanw"; + repo = "esbuild"; + rev = "v${version}"; + hash = "sha256-h/Vqwax4B4nehRP9TaYbdixAZdb1hx373dNxNHvDrtY="; + }; + vendorHash = "sha256-+BfxCyg0KkDQpHt/wycy/8CTG6YBA/VJvJFhhzUnSiQ="; + } + ); + } + ); buildPhase = '' runHook preBuild - cargo tauri build --bundles "$tauriBundle" + cargo tauri build --bundles ${if stdenv.isDarwin then "app" else "deb"} runHook postBuild ''; @@ -156,7 +106,7 @@ rustPlatform.buildRustPackage { ln -s "$out"/bin/modrinth-app "$out"/Applications/Modrinth\ App.app/Contents/MacOS/Modrinth\ App '' + lib.optionalString stdenv.isLinux '' - cp -r target/release/bundle/"$tauriBundle"/*/data/usr "$out" + cp -r target/release/bundle/deb/*/data/usr "$out" desktop-file-edit \ --set-comment "Modrinth's game launcher" \ --set-key="StartupNotify" --set-value="true" \ @@ -181,7 +131,7 @@ rustPlatform.buildRustPackage { ''; mainProgram = "modrinth-app"; homepage = "https://modrinth.com"; - changelog = "https://github.com/modrinth/theseus/releases/tag/v${modrinth-app-unwrapped.version}"; + changelog = "https://github.com/modrinth/theseus/releases/tag/v${version}"; license = with lib.licenses; [ gpl3Plus unfreeRedistributable From acb497f8a7573ca78a8d2e4d8625104924a218d0 Mon Sep 17 00:00:00 2001 From: TomaSajt <62384384+TomaSajt@users.noreply.github.com> Date: Tue, 10 Sep 2024 21:39:24 +0200 Subject: [PATCH 2/2] modrinth-app-unwrapped: migrate to mkDerivaion - TODO: combine --- .../mo/modrinth-app-unwrapped/package.nix | 35 +++++++++++-------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/pkgs/by-name/mo/modrinth-app-unwrapped/package.nix b/pkgs/by-name/mo/modrinth-app-unwrapped/package.nix index 68f444dbe3208..29a9d65d1a999 100644 --- a/pkgs/by-name/mo/modrinth-app-unwrapped/package.nix +++ b/pkgs/by-name/mo/modrinth-app-unwrapped/package.nix @@ -5,6 +5,7 @@ rustPlatform, buildGoModule, nix-update-script, + cargo, cargo-tauri, desktop-file-utils, esbuild, @@ -17,18 +18,26 @@ webkitgtk, }: -rustPlatform.buildRustPackage rec { +stdenv.mkDerivation (finalAttrs: { pname = "modrinth-app-unwrapped"; version = "0.7.1"; src = fetchFromGitHub { owner = "modrinth"; repo = "theseus"; - rev = "refs/tags/v${version}"; + rev = "refs/tags/v${finalAttrs.version}"; hash = "sha256-JWR0e2vOBvOLosr22Oo2mAlR0KAhL+261RRybhNctlM="; }; - cargoLock = { + pnpmRoot = "theseus_gui"; + + pnpmDeps = pnpm_8.fetchDeps { + inherit (finalAttrs) pname src; + sourceRoot = "${finalAttrs.src.name}/${finalAttrs.pnpmRoot}"; + hash = "sha256-g/uUGfC9TQh0LE8ed51oFY17FySoeTvfaeEpzpNeMao="; + }; + + cargoDeps = rustPlatform.importCargoLock { lockFile = ./Cargo.lock; outputHashes = { "tauri-plugin-single-instance-0.0.0" = "sha256-Mf2/cnKotd751ZcSHfiSLNe2nxBfo4dMBdoCwQhe7yI="; @@ -36,20 +45,16 @@ rustPlatform.buildRustPackage rec { }; nativeBuildInputs = [ - cargo-tauri - desktop-file-utils pnpm_8.configHook nodejs - pkg-config - ]; - pnpmRoot = "theseus_gui"; + rustPlatform.cargoSetupHook + cargo + cargo-tauri - pnpmDeps = pnpm_8.fetchDeps { - inherit pname src; - sourceRoot = "${src.name}/${pnpmRoot}"; - hash = "sha256-g/uUGfC9TQh0LE8ed51oFY17FySoeTvfaeEpzpNeMao="; - }; + desktop-file-utils + pkg-config + ]; buildInputs = [ openssl ] @@ -131,7 +136,7 @@ rustPlatform.buildRustPackage rec { ''; mainProgram = "modrinth-app"; homepage = "https://modrinth.com"; - changelog = "https://github.com/modrinth/theseus/releases/tag/v${version}"; + changelog = "https://github.com/modrinth/theseus/releases/tag/v${finalAttrs.version}"; license = with lib.licenses; [ gpl3Plus unfreeRedistributable @@ -141,4 +146,4 @@ rustPlatform.buildRustPackage rec { # this builds on architectures like aarch64, but the launcher itself does not support them yet broken = !stdenv.isx86_64; }; -} +})