From bcf14f49a0e96b24903a939dd0ff79193d8deceb Mon Sep 17 00:00:00 2001 From: TomaSajt <62384384+TomaSajt@users.noreply.github.com> Date: Wed, 14 May 2025 16:28:16 +0200 Subject: [PATCH] clash-verge-rev: use cargo-tauri.hook, refactor --- pkgs/by-name/cl/clash-verge-rev/package.nix | 31 +------ pkgs/by-name/cl/clash-verge-rev/unwrapped.nix | 92 ++++++++++--------- pkgs/by-name/cl/clash-verge-rev/webui.nix | 45 --------- 3 files changed, 53 insertions(+), 115 deletions(-) delete mode 100644 pkgs/by-name/cl/clash-verge-rev/webui.nix diff --git a/pkgs/by-name/cl/clash-verge-rev/package.nix b/pkgs/by-name/cl/clash-verge-rev/package.nix index 7a4ea2533304..4dcbf111d4ff 100644 --- a/pkgs/by-name/cl/clash-verge-rev/package.nix +++ b/pkgs/by-name/cl/clash-verge-rev/package.nix @@ -8,8 +8,6 @@ wrapGAppsHook3, v2ray-geoip, v2ray-domain-list-community, - copyDesktopItems, - makeDesktopItem, libsoup, }: let @@ -31,7 +29,7 @@ let }; service-cargo-hash = "sha256-lMOQznPlkHIMSm5nOLuGP9qJXt3CXnd+q8nCu+Xbbt8="; - npm-hash = "sha256-v9+1NjXo/1ogmep+4IP+9qoUR1GJz87VGeOoMzQ1Rfw="; + pnpm-hash = "sha256-v9+1NjXo/1ogmep+4IP+9qoUR1GJz87VGeOoMzQ1Rfw="; vendor-hash = "sha256-y3XVHi00mnuVFxSd02YBgfWuXYRVIs+e0tITXNOFRsA="; service = callPackage ./service.nix { @@ -44,23 +42,13 @@ let ; }; - webui = callPackage ./webui.nix { - inherit - version - src - pname - meta - npm-hash - ; - }; - unwrapped = callPackage ./unwrapped.nix { inherit pname version src + pnpm-hash vendor-hash - webui meta libsoup ; @@ -92,20 +80,6 @@ stdenv.mkDerivation { nativeBuildInputs = [ wrapGAppsHook3 - copyDesktopItems - ]; - - desktopItems = [ - (makeDesktopItem { - name = "clash-verge"; - exec = "clash-verge"; - comment = "Clash Verge Rev"; - type = "Application"; - icon = "clash-verge"; - desktopName = "Clash Verge Rev"; - terminal = false; - categories = [ "Network" ]; - }) ]; installPhase = '' @@ -121,6 +95,7 @@ stdenv.mkDerivation { ln -s ${v2ray-geoip}/share/v2ray/geoip.dat $out/lib/Clash\ Verge/resources/geoip.dat ln -s ${v2ray-domain-list-community}/share/v2ray/geosite.dat $out/lib/Clash\ Verge/resources/geosite.dat ln -s ${dbip-country-lite.mmdb} $out/lib/Clash\ Verge/resources/Country.mmdb + runHook postInstall ''; } diff --git a/pkgs/by-name/cl/clash-verge-rev/unwrapped.nix b/pkgs/by-name/cl/clash-verge-rev/unwrapped.nix index f5bd48fb18cf..0c289203e0db 100644 --- a/pkgs/by-name/cl/clash-verge-rev/unwrapped.nix +++ b/pkgs/by-name/cl/clash-verge-rev/unwrapped.nix @@ -2,35 +2,53 @@ pname, version, src, - libayatana-appindicator, - vendor-hash, - glib, - webui, - pkg-config, - libsoup, - rustPlatform, - makeDesktopItem, - libsForQt5, - kdePackages, meta, - webkitgtk_4_1, - openssl, + + pnpm-hash, + vendor-hash, + + rustPlatform, + + cargo-tauri, jq, + moreutils, + nodejs, + pkg-config, + pnpm_9, + + glib, + kdePackages, + libayatana-appindicator, + libsForQt5, + libsoup, + openssl, + webkitgtk_4_1, }: rustPlatform.buildRustPackage { inherit version src meta; pname = "${pname}-unwrapped"; - sourceRoot = "${src.name}/src-tauri"; + + cargoRoot = "src-tauri"; + buildAndTestSubdir = "src-tauri"; useFetchCargoVendor = true; cargoHash = vendor-hash; + pnpmDeps = pnpm_9.fetchDeps { + inherit pname version src; + hash = pnpm-hash; + }; + env = { OPENSSL_NO_VENDOR = 1; }; postPatch = '' + # We disable the option to try to use the bleeding-edge version of mihomo + # If you need a newer version, you can override the mihomo input of the wrapped package + sed -i -e '/Mihomo Alpha/d' ./src/components/setting/mods/clash-core-viewer.tsx + substituteInPlace $cargoDepsCopy/libappindicator-sys-*/src/lib.rs \ --replace-fail "libayatana-appindicator3.so.1" "${libayatana-appindicator}/lib/libayatana-appindicator3.so.1" @@ -41,48 +59,38 @@ rustPlatform.buildRustPackage { --replace-fail '"kwriteconfig5"' '"${libsForQt5.kconfig}/bin/kwriteconfig5"' \ --replace-fail '"kwriteconfig6"' '"${kdePackages.kconfig}/bin/kwriteconfig6"' - cat tauri.conf.json | jq 'del(.bundle.resources) | del(.bundle.externalBin) | .build.frontendDist = "${webui}" | .build.beforeBuildCommand = ""' > tauri.conf.json.2 - mv tauri.conf.json.2 tauri.conf.json - cat tauri.linux.conf.json | jq 'del(.bundle.externalBin)' > tauri.linux.conf.json.2 - mv tauri.linux.conf.json.2 tauri.linux.conf.json - chmod 777 ../.cargo - rm ../.cargo/config.toml + # this file tries to override the linker used when compiling for certain platforms + rm .cargo/config.toml + + # disable updater and don't try to bundle helper binaries + jq ' + .bundle.createUpdaterArtifacts = false | + del(.bundle.resources) | + del(.bundle.externalBin) + ' src-tauri/tauri.conf.json | sponge src-tauri/tauri.conf.json + + jq 'del(.bundle.externalBin)' src-tauri/tauri.linux.conf.json | sponge src-tauri/tauri.linux.conf.json # As a side effect of patching the service to fix the arbitrary file overwrite issue, # we also need to update the timestamp format in the filename to the second level. # This ensures that the Clash kernel can still be restarted within one minute without problems. - substituteInPlace src/utils/dirs.rs \ + substituteInPlace src-tauri/src/utils/dirs.rs \ --replace-fail '%Y-%m-%d-%H%M' '%Y-%m-%d-%H%M%S' ''; nativeBuildInputs = [ - pkg-config - rustPlatform.cargoSetupHook + cargo-tauri.hook jq + moreutils + nodejs + pkg-config + pnpm_9.configHook ]; buildInputs = [ - openssl + libayatana-appindicator libsoup + openssl webkitgtk_4_1 ]; - - postInstall = '' - install -DT icons/128x128@2x.png $out/share/icons/hicolor/128x128@2/apps/clash-verge.png - install -DT icons/128x128.png $out/share/icons/hicolor/128x128/apps/clash-verge.png - install -DT icons/32x32.png $out/share/icons/hicolor/32x32/apps/clash-verge.png - ''; - - desktopItems = [ - (makeDesktopItem { - name = "clash-verge-rev"; - exec = "clash-verge %u"; - icon = "clash-verge-rev"; - desktopName = "Clash Verge Rev"; - genericName = meta.description; - mimeTypes = [ "x-scheme-handler/clash" ]; - type = "Application"; - terminal = false; - }) - ]; } diff --git a/pkgs/by-name/cl/clash-verge-rev/webui.nix b/pkgs/by-name/cl/clash-verge-rev/webui.nix deleted file mode 100644 index d8cdc4f80b1b..000000000000 --- a/pkgs/by-name/cl/clash-verge-rev/webui.nix +++ /dev/null @@ -1,45 +0,0 @@ -{ - version, - src, - pname, - pnpm_9, - nodejs, - stdenv, - meta, - npm-hash, -}: -stdenv.mkDerivation { - inherit version src meta; - pname = "${pname}-webui"; - pnpmDeps = pnpm_9.fetchDeps { - inherit pname version src; - hash = npm-hash; - }; - - nativeBuildInputs = [ - nodejs - pnpm_9.configHook - ]; - - postPatch = '' - chmod -R +644 -- ./src/components/setting/mods/clash-core-viewer.tsx - chmod -R +644 -- ./src/components/setting/mods - sed -i -e '/Mihomo Alpha/d' ./src/components/setting/mods/clash-core-viewer.tsx - ''; - - buildPhase = '' - runHook preBuild - - node --max_old_space_size=1024000 ./node_modules/vite/bin/vite.js build - - runHook postBuild - ''; - - installPhase = '' - runHook preInstall - - cp -r dist $out - - runHook postInstall - ''; -}