From 6798a20e5482b574c8e02e5ff260d72ea6431a29 Mon Sep 17 00:00:00 2001 From: Akshay Date: Sat, 2 Mar 2024 11:47:30 +0000 Subject: init --- flake.lock | 59 +++++++++++++++++++++++++ flake.nix | 143 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 202 insertions(+) create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..0fc6590 --- /dev/null +++ b/flake.lock @@ -0,0 +1,59 @@ +{ + "nodes": { + "flaresolverr-src": { + "flake": false, + "locked": { + "lastModified": 1709156333, + "narHash": "sha256-pf5sibZ9Vjc98UOVTEUlKrBoXXKiykrt+szXLbNJB3k=", + "owner": "FlareSolverr", + "repo": "FlareSolverr", + "rev": "fd773e59097c1aca4e08edc07c1ed30164f88bd3", + "type": "github" + }, + "original": { + "owner": "FlareSolverr", + "ref": "v3.3.16", + "repo": "FlareSolverr", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1707205916, + "narHash": "sha256-fmRJilYGlB7VCt3XsdYxrA0u8e/K84O5xYucerUY0iM=", + "path": "/nix/store/6gjnggwf6024m5yj8gz04g8pv3ilfz98-source", + "rev": "8cc79aa39bbc6eaedaf286ae655b224c71e02907", + "type": "path" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "root": { + "inputs": { + "flaresolverr-src": "flaresolverr-src", + "nixpkgs": "nixpkgs", + "undetected-chromedriver-src": "undetected-chromedriver-src" + } + }, + "undetected-chromedriver-src": { + "flake": false, + "locked": { + "lastModified": 1708190030, + "narHash": "sha256-Qe+GrsUPnhjJMDgjdUCloapjj0ggFlm/Dr42WLcmb1o=", + "owner": "ultrafunkamsterdam", + "repo": "undetected-chromedriver", + "rev": "0aa5fbe252370b4cb2b95526add445392cad27ba", + "type": "github" + }, + "original": { + "owner": "ultrafunkamsterdam", + "repo": "undetected-chromedriver", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..742af2f --- /dev/null +++ b/flake.nix @@ -0,0 +1,143 @@ +# mostly lifted from https://github.com/xddxdd/nur-packages, converted into a standalone flake +{ + description = "Proxy server to bypass CloudFlare protection"; + + inputs = { + flaresolverr-src = { + url = github:FlareSolverr/FlareSolverr/v3.3.16; + flake = false; + }; + undetected-chromedriver-src = { + url = github:ultrafunkamsterdam/undetected-chromedriver; + flake = false; + }; + }; + + outputs = + { self + , nixpkgs + , flaresolverr-src + , undetected-chromedriver-src + }: + let + supportedSystems = [ "x86_64-linux" ]; + forAllSystems = nixpkgs.lib.genAttrs supportedSystems; + nixpkgsFor = forAllSystems (system: import nixpkgs { + inherit system; + overlays = [ self.overlays.default ]; + }); + in + { + overlays.default = final: prev: { + flaresolverr = + let + python = final.python3.withPackages (p: + with p; [ + bottle + waitress + selenium + func-timeout + prometheus-client + requests + websockets + xvfbwrapper + ]); + + path = final.lib.makeBinPath [ + final.chromium + final.undetected-chromedriver-bin + final.xorg.xorgserver + ]; + in + final.stdenv.mkDerivation { + pname = "flaresolverr"; + version = "v3.3.15"; + src = flaresolverr-src; + + nativeBuildInputs = [ final.makeWrapper ]; + + postPatch = '' + substituteInPlace src/utils.py \ + --replace 'PATCHED_DRIVER_PATH = None' 'PATCHED_DRIVER_PATH = "${final.undetected-chromedriver-bin}/bin/undetected_chromedriver"' + ''; + + installPhase = '' + mkdir -p $out/bin $out/opt + cp -r * $out/opt/ + + makeWrapper ${python}/bin/python $out/bin/flaresolverr \ + --add-flags "$out/opt/src/flaresolverr.py" \ + --set PATH "${path}" + ''; + + meta = with final.lib; { + description = "Proxy server to bypass Cloudflare protection"; + homepage = "https://github.com/FlareSolverr/FlareSolverr"; + license = licenses.mit; + }; + }; + + undetected_chromedriver = final.python3Packages.buildPythonPackage { + pname = "undetected-chromedriver"; + version = "0aa5fbe252370b4cb2b95526add445392cad27ba"; + src = undetected-chromedriver-src; + + buildInputs = with final.python3Packages; [ + selenium + requests + websockets + ]; + + preConfigure = '' + sed -i "s#selenium>=4.9.0#selenium#g" setup.py + ''; + + }; + + undetected-chromedriver-bin = + let + py = final.python3.withPackages (p: + with p; [ + requests + selenium + websockets + final.undetected_chromedriver + ]); + specSystem = "linux64"; + in + final.chromedriver.overrideAttrs (old: { + pname = "undetected-chromedriver-bin"; + postPatch = '' + export HOME=$(pwd) + export CHROMEDRIVER=$(pwd)/chromedriver-${specSystem}/chromedriver + + ls -alh + + ${py}/bin/python <> $out/bin/undetected_chromedriver + ''; + }); + }; + + packages = forAllSystems (system: { + inherit (nixpkgsFor."${system}") flaresolverr; + }); + + defaultPackage = forAllSystems (system: self.packages."${system}".flaresolverr); + + }; +} + -- cgit v1.2.3