From 09e97e00caf77f3035bf9d1df2f276a7e5729e4d Mon Sep 17 00:00:00 2001 From: lyranico Date: Tue, 11 Feb 2025 02:58:46 +0800 Subject: [PATCH] mihomo-party: refactor --- pkgs/by-name/mi/mihomo-party/package.nix | 35 ++++++++++++------------ pkgs/by-name/mi/mihomo-party/update.sh | 2 +- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/pkgs/by-name/mi/mihomo-party/package.nix b/pkgs/by-name/mi/mihomo-party/package.nix index b4e8203ed352..02467ca6ebd1 100644 --- a/pkgs/by-name/mi/mihomo-party/package.nix +++ b/pkgs/by-name/mi/mihomo-party/package.nix @@ -13,32 +13,28 @@ libayatana-appindicator, libGL, }: -let + +stdenv.mkDerivation rec { + pname = "mihomo-party"; version = "1.7.1"; + src = let - inherit (stdenv.hostPlatform) system; - selectSystem = attrs: attrs.${system}; - suffix = selectSystem { + selectSystem = + attrs: + attrs.${stdenv.hostPlatform.system} or (throw "Unsupported system: ${stdenv.hostPlatform.system}"); + arch = selectSystem { x86_64-linux = "amd64"; aarch64-linux = "arm64"; }; + in + fetchurl { + url = "https://github.com/mihomo-party-org/mihomo-party/releases/download/v${version}/mihomo-party-linux-${version}-${arch}.deb"; hash = selectSystem { x86_64-linux = "sha256-fVPW4lk+1uY+zTPk0wNeHz7ILKB+7p9hunHrqnuPI6w="; aarch64-linux = "sha256-wEOOP5ha7R0z0DCTCsmn5lfwJdzEWtNGdWNjVB5cI6k="; }; - in - fetchurl { - url = "https://github.com/mihomo-party-org/mihomo-party/releases/download/v${version}/mihomo-party-linux-${version}-${suffix}.deb"; - inherit hash; }; -in -stdenv.mkDerivation { - inherit version src; - - pname = "mihomo-party"; - - passthru.updateScript = ./update.sh; nativeBuildInputs = [ dpkg @@ -58,10 +54,11 @@ stdenv.mkDerivation { runHook preInstall mkdir -p $out/bin - cp -r opt/mihomo-party usr/share $out + cp -r opt $out/opt + cp -r usr/share $out/share substituteInPlace $out/share/applications/mihomo-party.desktop \ --replace-fail "/opt/mihomo-party/mihomo-party" "mihomo-party" - ln -s $out/mihomo-party/mihomo-party $out/bin/mihomo-party + ln -s $out/opt/mihomo-party/mihomo-party $out/bin/mihomo-party runHook postInstall ''; @@ -74,9 +71,11 @@ stdenv.mkDerivation { udev libayatana-appindicator ] - } $out/mihomo-party/mihomo-party + } $out/opt/mihomo-party/mihomo-party ''; + passthru.updateScript = ./update.sh; + meta = { description = "Another Mihomo GUI"; homepage = "https://github.com/mihomo-party-org/mihomo-party"; diff --git a/pkgs/by-name/mi/mihomo-party/update.sh b/pkgs/by-name/mi/mihomo-party/update.sh index 380b997c2512..406680fd0208 100755 --- a/pkgs/by-name/mi/mihomo-party/update.sh +++ b/pkgs/by-name/mi/mihomo-party/update.sh @@ -1,5 +1,5 @@ #!/usr/bin/env nix-shell -#!nix-shell -i bash -p bash nixVersions.latest curl coreutils jq common-updater-scripts +#!nix-shell -i bash -p bash nix curl coreutils jq common-updater-scripts latestTag=$(curl ${GITHUB_TOKEN:+-u ":$GITHUB_TOKEN"} -sL https://api.github.com/repos/mihomo-party-org/mihomo-party/releases/latest | jq -r ".tag_name") latestVersion="$(expr "$latestTag" : 'v\(.*\)')"