seperate clash-updater

This commit is contained in:
guochao 2022-07-18 15:12:35 +08:00
parent 7270a94cde
commit 1c484f8caa
4 changed files with 80 additions and 60 deletions

View File

@ -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;
doInstallCheck = true;
checkPhase = ''
patchShebangs bin
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;
}

View File

@ -0,0 +1,20 @@
{ subscription, name }: with import <nixpkgs> {}; 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}"
'';
}

View File

@ -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

View File

@ -1,5 +1,5 @@
with import <nixpkgs> {};
with pkgs;
{
clash-premium = callPackage ../network/proxy/clash-premium { version = "2022.07.07"; };
clash-premium = callPackage (import ../network/proxy/clash-premium).clash-premium { version = "2022.07.07"; };
}