From 9ba4afba1477b4c9d5be2c72bef447e99fdad346 Mon Sep 17 00:00:00 2001 From: PerchunPak Date: Wed, 25 Dec 2024 14:40:15 +0100 Subject: [PATCH] rquickshare: build from source --- pkgs/by-name/rq/rquickshare/package.nix | 114 +++++++++++++++++++----- pkgs/top-level/all-packages.nix | 2 + 2 files changed, 96 insertions(+), 20 deletions(-) diff --git a/pkgs/by-name/rq/rquickshare/package.nix b/pkgs/by-name/rq/rquickshare/package.nix index ae38de23828a4b..bda4a1e13cafe1 100644 --- a/pkgs/by-name/rq/rquickshare/package.nix +++ b/pkgs/by-name/rq/rquickshare/package.nix @@ -1,34 +1,108 @@ { - appimageTools, lib, - fetchurl, + cargo-tauri, + cargo-tauri_1, + fetchFromGitHub, + glib-networking, + libayatana-appindicator, + libsoup_2_4, + libsoup_3, + nodejs, + openssl, + perl, + pkg-config, + pnpm, + protobuf, + rustPlatform, + stdenv, + webkitgtk_4_0, + webkitgtk_4_1, + wrapGAppsHook4, + + # This package provides can be built using tauri v1 or v2. + # Try legacy (v1) version if main (v2) doesn't work. + app-type ? "main", # main or legacy }: let - pname = "rquickshare"; + app-type-either = + arg1: arg2: + if app-type == "main" then + arg1 + else if app-type == "legacy" then + arg2 + else + throw "Wrong argument for app-type in rquickshare package"; + + proper-cargo-tauri = app-type-either cargo-tauri cargo-tauri_1; +in +rustPlatform.buildRustPackage rec { + pname = "rquickshare" + (app-type-either "" "-legacy"); version = "0.11.2"; - src = fetchurl { - url = "https://github.com/Martichou/rquickshare/releases/download/v${version}/r-quick-share-main_v${version}_glibc-2.39_amd64.AppImage"; - hash = "sha256-7w1zybCPRg4RK5bKHoHLDUDXVDQL23ox/6wh8H9vTPg="; + + src = fetchFromGitHub { + owner = "Martichou"; + repo = "rquickshare"; + tag = "v${version}"; + hash = "sha256-MYhM6FB3zfvMFnLMecbn4Ismvk8AAykIvhPBnFcNjdI="; }; - appimageContents = appimageTools.extractType2 { inherit pname version src; }; -in -appimageTools.wrapType2 { - inherit pname version src; - extraInstallCommands = '' - install -Dm444 ${appimageContents}/rquickshare.desktop -t $out/share/applications - substituteInPlace $out/share/applications/rquickshare.desktop \ - --replace-fail 'Exec=rquickshare' 'Exec=rquickshare %u' - cp -r ${appimageContents}/usr/share/icons $out/share + + # from https://github.com/NixOS/nixpkgs/blob/04e40bca2a68d7ca85f1c47f00598abb062a8b12/pkgs/by-name/ca/cargo-tauri/test-app.nix#L23-L26 + postPatch = lib.optionalString stdenv.hostPlatform.isLinux '' + substituteInPlace $cargoDepsCopy/libappindicator-sys-*/src/lib.rs \ + --replace "libayatana-appindicator3.so.1" "${libayatana-appindicator}/lib/libayatana-appindicator3.so.1" ''; + pnpmRoot = "app/${app-type}"; + pnpmDeps = pnpm.fetchDeps { + inherit pname version src; + + sourceRoot = "${src.name}/app/${app-type}"; + hash = app-type-either "sha256-VPb2idEiBruVCwz5lDojFmD2C5CfXYSe5mPWBwCGeJs=" "sha256-sDHysaKMdNcbL1szww7/wg0bGHOnEKsKoySZJJCcPik="; + }; + + useFetchCargoVendor = true; + cargoRoot = "app/${app-type}/src-tauri"; + buildAndTestSubdir = cargoRoot; + cargoHash = app-type-either "sha256-5vGXMHar9E25jVseXR2uI82DtZXyPaHgDD8QkqoRhhY=" "sha256-kkbDEV4k+4EiUi4+EsZdmgm9/vMC0m5L5lpyCn7Zzb0="; + + nativeBuildInputs = [ + proper-cargo-tauri.hook + + # Setup pnpm + nodejs + pnpm.configHook + + # Make sure we can find our libraries + perl + pkg-config + protobuf + wrapGAppsHook4 + ]; + + buildInputs = + [ openssl ] + ++ lib.optionals stdenv.hostPlatform.isLinux [ + glib-networking # Most Tauri apps need networking + libayatana-appindicator + ] + ++ lib.optionals (app-type == "main") [ + webkitgtk_4_1 + libsoup_3 + ] + ++ lib.optionals (app-type == "legacy") [ + webkitgtk_4_0 + libsoup_2_4 + ]; + meta = { - description = "Rust implementation of NearbyShare/QuickShare from Android for Linux"; + description = "Rust implementation of NearbyShare/QuickShare from Android for Linux and macOS"; homepage = "https://github.com/Martichou/rquickshare"; changelog = "https://github.com/Martichou/rquickshare/blob/v${version}/CHANGELOG.md"; license = lib.licenses.gpl3Plus; - maintainers = [ lib.maintainers.luftmensch-luftmensch ]; - platforms = [ "x86_64-linux" ]; - sourceProvenance = with lib.sourceTypes; [ binaryNativeCode ]; - mainProgram = "rquickshare"; + mainProgram = app-type-either "rquickshare" "r-quick-share"; + maintainers = with lib.maintainers; [ + perchun + luftmensch-luftmensch + ]; }; } diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index a694f39b4b93f8..a64c933f1de1b4 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -16906,6 +16906,8 @@ with pkgs; buildShareware = true; }; + rquickshare-legacy = callPackage ../by-name/rq/rquickshare/package.nix { app-type = "legacy"; }; + starsector = callPackage ../games/starsector { openjdk = openjdk8; };