29 popplerSupport ? true,
34 stdenv.mkDerivation (finalAttrs: {
39 url = "https://download.calibre-ebook.com/${finalAttrs.version}/calibre-${finalAttrs.version}.tar.xz";
40 hash = "sha256-61Nbclkt59sh8VHh3uRw0GvlDjlyOz1jrsFMMIuzPLE=";
44 # allow for plugin update check, but no calibre version check
46 name = "0001-only-plugin-update.patch";
47 url = "https://raw.githubusercontent.com/debian-calibre/calibre/debian/${finalAttrs.version}+ds-1/debian/patches/0001-only-plugin-update.patch";
48 hash = "sha256-mHZkUoVcoVi9XBOSvM5jyvpOTCcM91g9+Pa/lY6L5p8=";
51 name = "0007-Hardening-Qt-code.patch";
52 url = "https://raw.githubusercontent.com/debian-calibre/calibre/debian/${finalAttrs.version}+ds-1/debian/patches/hardening/0007-Hardening-Qt-code.patch";
53 hash = "sha256-9hi4T9LB7aklWASMR8hIuKBgZm2arDvORfmk9S8wgCA=";
55 ] ++ lib.optional (!unrarSupport) ./dont_build_unrar_plugin.patch;
58 sed -i "s@\[tool.sip.project\]@[tool.sip.project]\nsip-include-dirs = [\"${python3Packages.pyqt6}/${python3Packages.python.sitePackages}/PyQt6/bindings\"]@g" \
61 # Remove unneeded files and libs
62 rm -rf src/odf resources/calibre-portable.*
65 dontUseQmakeConfigure = true;
66 dontUseCmakeConfigure = true;
95 (python3Packages.python.withPackages (
99 (apsw.overrideAttrs (oldAttrs: {
100 setupPyBuildFlags = [ "--enable=load_extension" ];
128 # the following are distributed with calibre, but we use upstream instead
132 lib.optionals (lib.lists.any (p: p == stdenv.hostPlatform.system) pyqt6-webengine.meta.platforms)
134 # much of calibre's functionality is usable without a web
135 # browser, so we enable building on platforms which qtwebengine
136 # does not support by simply omitting qtwebengine.
139 ++ lib.optional (unrarSupport) unrardll
142 ] ++ lib.optional (speechSupport) speechd-minimal;
147 export HOME=$TMPDIR/fakehome
148 export POPPLER_INC_DIR=${poppler_utils.dev}/include/poppler
149 export POPPLER_LIB_DIR=${poppler_utils.out}/lib
150 export MAGICK_INC=${imagemagick.dev}/include/ImageMagick
151 export MAGICK_LIB=${imagemagick.out}/lib
152 export FC_INC_DIR=${fontconfig.dev}/include/fontconfig
153 export FC_LIB_DIR=${fontconfig.lib}/lib
154 export PODOFO_INC_DIR=${podofo.dev}/include/podofo
155 export PODOFO_LIB_DIR=${podofo.lib}/lib
156 export XDG_DATA_HOME=$out/share
157 export XDG_UTILS_INSTALL_MODE="user"
158 export PIPER_TTS_DIR=${piper-tts}/bin
160 python setup.py install --root=$out \
163 --staging-root=$out \
164 --staging-libdir=$out/lib \
165 --staging-sharedir=$out/share
167 PYFILES="$out/bin/* $out/lib/calibre/calibre/web/feeds/*.py
168 $out/lib/calibre/calibre/ebooks/metadata/*.py
169 $out/lib/calibre/calibre/ebooks/rtf2xml/*.py"
171 sed -i "s/env python[0-9.]*/python/" $PYFILES
172 sed -i "2i import sys; sys.argv[0] = 'calibre'" $out/bin/calibre
175 cp -a man-pages $out/share/man
181 dontWrapQtApps = true;
182 dontWrapGApps = true;
186 popplerArgs = "--prefix PATH : ${poppler_utils.out}/bin";
189 for program in $out/bin/*; do
190 wrapProgram $program \
191 ''${qtWrapperArgs[@]} \
192 ''${gappsWrapperArgs[@]} \
193 ${if popplerSupport then popplerArgs else ""}
197 doInstallCheck = true;
198 installCheckInputs = with python3Packages; [
202 installCheckPhase = ''
203 runHook preInstallCheck
205 ETN='--exclude-test-name'
207 $ETN 'test_7z' # we don't include 7z support
208 $ETN 'test_zstd' # we don't include zstd support
209 $ETN 'test_qt' # we don't include svg or webp support
210 $ETN 'test_import_of_all_python_modules' # explores actual file paths, gets confused
211 $ETN 'test_websocket_basic' # flakey
212 ${lib.optionalString (!unrarSupport) "$ETN 'test_unrar'"}
215 python setup.py test ''${EXCLUDED_FLAGS[@]}
217 runHook postInstallCheck
221 homepage = "https://calibre-ebook.com";
222 description = "Comprehensive e-book software";
224 calibre is a powerful and easy to use e-book manager. Users say it’s
225 outstanding and a must-have. It’ll allow you to do nearly everything and
226 it takes things a step beyond normal e-book software. It’s also completely
227 free and open source and great for both casual users and computer experts.
229 changelog = "https://github.com/kovidgoyal/calibre/releases/tag/v${finalAttrs.version}";
230 license = if unrarSupport then lib.licenses.unfreeRedistributable else lib.licenses.gpl3Plus;
231 maintainers = with lib.maintainers; [ pSub ];
232 platforms = lib.platforms.unix;
233 broken = stdenv.hostPlatform.isDarwin;