# 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); }; }