View Single Post
Old 11-04-2026, 04:27 AM   #7
cranetoad
Junior Member
cranetoad began at the beginning.
 
Posts: 7
Karma: 10
Join Date: Jul 2025
Device: kindle
Quote:
Originally Posted by JSWolf View Post
Why is it some run such obscure odd versions of Linux and then wonder why things break?
Nixos isn't exactly obscure, but more in use with developers. My intent was to ask whether someone had already patched Calibre so I wouldn't do the same work someone has already done. Kovidgoyal was kind enough to point me in the right direction, and just in case someone else comes looking, here is what I did:

A system installation of camoufox and injecting browserforge to Calibre PYTHON_PATH does the trick, and is easily achievable by using an overlay. For Camoufox, I used the flake from here and installed system-wide: https://github.com/maximoffua/camoufox-nix. Just pick and choose what you need from there.

Then I created the overlay:

Code:
(final: prev: {
      calibre = prev.calibre.overrideAttrs (old:
      {
        buildInputs = old.buildInputs ++ [final.camoufox final.python314Packages.browserforge];

        postPatch =
          (old.postPatch or "")
          + ''
            unwrapped=$(grep -o '/nix/store/[^/"]*camoufox-unwrapped[^/"]*' ${final.camoufox}/bin/camoufox | head -n1)
            test -n "$unwrapped" || { echo "could not find unwrapped camoufox"; exit 1; }

            substituteInPlace setup/resources.py \
              --replace-fail "if not opts.system_camoufox:" "if False:" \
              --replace-fail "parts = opts.system_camoufox.split(os.pathsep)" "parts = '$unwrapped/bin/camoufox:$unwrapped/lib/camoufox'.split(os.pathsep)"
          '';
        preFixup =
          ''
            qtWrapperArgs+=(
              --set-default FONTCONFIG_FILE ${final.camoufox}/bin/fonts.conf
              --prefix PYTHONPATH : ${final.python314Packages.makePythonPath [final.python314Packages.browserforge]}
              --prefix LD_LIBRARY_PATH : ${final.lib.makeLibraryPath [
              final.gtk3
              final.glib
              final.dbus-glib
              final.libGL
              final.libxkbcommon
              final.alsa-lib
              final.libpulseaudio
              final.pciutils
              final.xorg.libX11
              final.xorg.libXtst
              final.xorg.libXrandr
              final.xorg.libXcomposite
              final.xorg.libXdamage
              final.xorg.libXfixes
              final.xorg.libXcursor
              final.xorg.libXi
              final.xorg.libxcb
              final.wayland
            ]}
            )
          ''
          + old.preFixup;
      });
    })
I'm not entirely sure if Calibre needs camoufox and browserforge as buildInputs, but I started by adding them, and never got to testing without, they are harmless if not used.

The hacky grep-based substitution is because I had problems with python whitespace inside nix and my formatter destroying the whitespace, so instead of elegant, you get hacky. It works 😅.

qtWrapper adds the run-time dependencies to calibre. e.g. browserforge and camoufox fonts, and also the libraries that camoufox might need. The libraries probably could be whittled down, if you are inclined to test.

If someone has done something prettier, feel free to share!
cranetoad is offline   Reply With Quote