diff --git a/pkgs/network/proxy/clash-premium/default.nix b/pkgs/network/proxy/clash-premium/default.nix index 3258199..c9bbdcf 100644 --- a/pkgs/network/proxy/clash-premium/default.nix +++ b/pkgs/network/proxy/clash-premium/default.nix @@ -1,6 +1,5 @@ -{ pkgs, stdenv, fetchurl, version, ... }: with pkgs; - -let +{ + clash-premium = { pkgs, stdenv, fetchurl, version, ... }: with pkgs;let systemTriple = { "x86_64-darwin" = { system = "darwin-amd64"; @@ -20,65 +19,48 @@ let }; }; currentTriple = systemTriple."${stdenv.targetPlatform.system}"; -in -stdenv.mkDerivation { - name = "clash-premium"; - src = fetchurl { - url = "https://github.com/Dreamacro/clash/releases/download/premium/clash-${currentTriple.system}-${version}.gz"; - sha256 = currentTriple.sha256; - }; - dontConfigure = true; - dontBuild = true; - dontPatchELF = true; - doInstallCheck = true; - - unpackPhase = '' - FILENAME=$(${coreutils}/bin/basename $src) - ${coreutils}/bin/cp $src clash.gz - ${gzip}/bin/gzip -k -d clash.gz - ''; - installPhase = '' - runHook preInstall - ${coreutils}/bin/mkdir -p $out/bin - ${coreutils}/bin/install -m 0755 clash $out/bin/clash - - if [ "${system}" == "linux" ]; then - patchelf \ - --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \ - $out/bin/clash - fi - ''; - - makeUpdater = { subscription, name }: stdenv.mkDerivation { - name = "clash-updater-${name}"; - src = ./updater.sh; - buildInputs = [ - makeWrapper - ]; - + in + + stdenv.mkDerivation { + name = "clash-premium"; + src = fetchurl { + url = "https://github.com/Dreamacro/clash/releases/download/premium/clash-${currentTriple.system}-${version}.gz"; + sha256 = currentTriple.sha256; + }; dontConfigure = true; dontBuild = true; dontPatchELF = true; - dontUnpack = true; - - checkPhase = '' - patchShebangs bin + doInstallCheck = true; + + unpackPhase = '' + FILENAME=$(${coreutils}/bin/basename $src) + ${coreutils}/bin/cp $src clash.gz + ${gzip}/bin/gzip -k -d clash.gz ''; - installPhase = '' - makeWrapper $src $out/bin/clash-updater-${name} --set SUBSCRIPTION_URL "${subscription}" + runHook preInstall + ${coreutils}/bin/mkdir -p $out/bin + ${coreutils}/bin/install -m 0755 clash $out/bin/clash + + if [ "${system}" == "linux" ]; then + patchelf \ + --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \ + $out/bin/clash + fi ''; + + + meta = { + description = "close-sourced pre-built Clash binary with TUN support and more"; + homepage = "https://github.com/Dreamacro/clash/releases/premium"; + platforms = [ + "x86_64-darwin" + "aarch64-darwin" + "x86_64-linux" + "aarch64-linux" + ]; + }; }; - meta = { - description = "close-sourced pre-built Clash binary with TUN support and more"; - homepage = "https://github.com/Dreamacro/clash/releases/premium"; - platforms = [ - "x86_64-darwin" - "aarch64-darwin" - "x86_64-linux" - "aarch64-linux" - ]; - }; + clash-updater = import ./updater.nix; } - diff --git a/pkgs/network/proxy/clash-premium/updater.nix b/pkgs/network/proxy/clash-premium/updater.nix new file mode 100644 index 0000000..75ca1dd --- /dev/null +++ b/pkgs/network/proxy/clash-premium/updater.nix @@ -0,0 +1,20 @@ +{ subscription, name }: with import {}; stdenv.mkDerivation { + name = "clash-updater-${name}"; + src = ./updater.sh; + buildInputs = [ + makeWrapper + ]; + + dontConfigure = true; + dontBuild = true; + dontPatchELF = true; + dontUnpack = true; + + checkPhase = '' + patchShebangs bin + ''; + + installPhase = '' + makeWrapper $src $out/bin/clash-updater --set SUBSCRIPTION_URL "${subscription}" + ''; +} diff --git a/pkgs/network/proxy/clash-premium/updater.sh b/pkgs/network/proxy/clash-premium/updater.sh index 40f94a7..4598d4e 100755 --- a/pkgs/network/proxy/clash-premium/updater.sh +++ b/pkgs/network/proxy/clash-premium/updater.sh @@ -3,6 +3,24 @@ set -euo pipefail IFS=$'\n\t' -env +TEMP=${TEMP:-$(mktemp /tmp/clash-config-XXXXXX)} +OUTPUT=${OUTPUT:-$HOME/.config/clash/testoutput.yaml} +OUTDIR=$(dirname $OUTPUT) -sleep 10000 +LOG="/tmp/clash-updater.log" + + +exec > ${LOG} +set -x + +while true; do + curl -v --continue -o ${TEMP} ${SUBSCRIPTION_URL} + RET=$? + + if [[ $RET -eq 0 ]]; then + mkdir -pv $OUTDIR + cp -v $TEMP $OUTPUT + fi + + sleep $((3600*24)) +done diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index d4fc857..71866c8 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -1,5 +1,5 @@ with import {}; with pkgs; { - clash-premium = callPackage ../network/proxy/clash-premium { version = "2022.07.07"; }; -} \ No newline at end of file + clash-premium = callPackage (import ../network/proxy/clash-premium).clash-premium { version = "2022.07.07"; }; +}