diff --git a/pkgs/default.nix b/pkgs/default.nix index 4496cc8..436f09d 100644 --- a/pkgs/default.nix +++ b/pkgs/default.nix @@ -12,4 +12,5 @@ in wm-helpers = callPackage ./wm-helpers { }; atool = callPackage ./atool-wrapped { }; nixfiles-assets = callPackage ./nixfiles-assets { }; + redlib = callPackage ./redlib { }; } diff --git a/pkgs/redlib/auth-fix.patch b/pkgs/redlib/auth-fix.patch new file mode 100644 index 0000000..016300a --- /dev/null +++ b/pkgs/redlib/auth-fix.patch @@ -0,0 +1,30 @@ +From bd47c206a1d94c8382570b69730d72562d777454 Mon Sep 17 00:00:00 2001 +From: Matthew Esposito +Date: Thu, 30 May 2024 18:08:45 -0400 +Subject: [PATCH] fix(oauth): Make Android user-agent patching unconditional + +--- + src/client.rs | 9 +++++---- + 1 file changed, 5 insertions(+), 4 deletions(-) + +diff --git a/src/client.rs b/src/client.rs +index 5b8fe8f..5ea9d1c 100644 +--- a/src/client.rs ++++ b/src/client.rs +@@ -181,11 +181,12 @@ fn request(method: &'static Method, path: String, redirect: bool, quarantine: bo + ) + }; + +- // Check if multi sub requested, or if submitted was requested. If so, replace "Android" with a tricky word. ++ // Replace "Android" with a tricky word. + // Issues: #78/#115, #116 +- if path.contains('+') || path.contains("/submitted") { +- user_agent = user_agent.replace("Android", "Andr\u{200B}oid"); +- } ++ // If you include the word "Android", you will get a number of different errors ++ // I guess they don't expect mobile traffic on the endpoints we use ++ // Scrawled on wall for next poor soul: Run the test suite. ++ user_agent = user_agent.replace("Android", "Andr\u{200B}oid"); + + // Build request to Reddit. When making a GET, request gzip compression. + // (Reddit doesn't do brotli yet.) diff --git a/pkgs/redlib/default.nix b/pkgs/redlib/default.nix new file mode 100644 index 0000000..393b781 --- /dev/null +++ b/pkgs/redlib/default.nix @@ -0,0 +1,65 @@ +{ lib +, stdenv +, cacert +, nixosTests +, rustPlatform +, fetchFromGitHub +, darwin +}: +rustPlatform.buildRustPackage rec { + pname = "redlib"; + version = "0.34.0"; + + src = fetchFromGitHub { + owner = "redlib-org"; + repo = "redlib"; + rev = "refs/tags/v${version}"; + hash = "sha256-JpuCX2ae9me+zHxQj5jqQlgDci2NV+TEVUAqnuTn3cA="; + }; + + patches = [ + ./auth-fix.patch + ]; + + cargoHash = "sha256-gkRblCHUFiprZeYtu43GIGBZqCq5l/HEGaQN91XbfSs="; + + buildInputs = lib.optionals stdenv.isDarwin [ + darwin.apple_sdk.frameworks.Security + ]; + + checkFlags = [ + # All these test try to connect to Reddit. + "--skip=test_fetching_subreddit_quarantined" + "--skip=test_fetching_nsfw_subreddit" + "--skip=test_fetching_ws" + + "--skip=test_obfuscated_share_link" + "--skip=test_share_link_strip_json" + + "--skip=test_localization_popular" + "--skip=test_fetching_subreddit" + "--skip=test_fetching_user" + + # These try to connect to the oauth client + "--skip=test_oauth_client" + "--skip=test_oauth_client_refresh" + "--skip=test_oauth_token_exists" + ]; + + env = { + SSL_CERT_FILE = "${cacert}/etc/ssl/certs/ca-bundle.crt"; + }; + + passthru.tests = { + inherit (nixosTests) redlib; + }; + + meta = { + changelog = "https://github.com/redlib-org/redlib/releases/tag/v${version}"; + description = "Private front-end for Reddit (Continued fork of Libreddit)"; + homepage = "https://github.com/redlib-org/redlib"; + license = lib.licenses.agpl3Only; + mainProgram = "redlib"; + maintainers = with lib.maintainers; [ soispha ]; + }; +}