29 , popplerSupport ? true
30 , speechSupport ? true
31 , unrarSupport ? false
34 stdenv.mkDerivation (finalAttrs: {
39 url = "https://download.calibre-ebook.com/${finalAttrs.version}/calibre-${finalAttrs.version}.tar.xz";
40 hash = "sha256-EWQfaoTwO9BdZQgJQrxfj6b8tmtukvlW5hFo/USjNhU=";
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-a6yyG0RUsQJBBNxeJsTtQSBV2lxdzz1hnTob88O+SKg=";
56 ++ lib.optional (!unrarSupport) ./dont_build_unrar_plugin.patch;
59 sed -i "s@\[tool.sip.project\]@[tool.sip.project]\nsip-include-dirs = [\"${python3Packages.pyqt6}/${python3Packages.python.sitePackages}/PyQt6/bindings\"]@g" \
62 # Remove unneeded files and libs
63 rm -rf src/odf resources/calibre-portable.*
66 dontUseQmakeConfigure = true;
67 dontUseCmakeConfigure = true;
94 (python3Packages.python.withPackages
96 (apsw.overrideAttrs (oldAttrs: {
97 setupPyBuildFlags = [ "--enable=load_extension" ];
125 # the following are distributed with calibre, but we use upstream instead
127 ] ++ lib.optionals (lib.lists.any (p: p == stdenv.hostPlatform.system) pyqt6-webengine.meta.platforms) [
128 # much of calibre's functionality is usable without a web
129 # browser, so we enable building on platforms which qtwebengine
130 # does not support by simply omitting qtwebengine.
132 ] ++ lib.optional (unrarSupport) unrardll)
135 ] ++ lib.optional (speechSupport) speechd-minimal;
140 export HOME=$TMPDIR/fakehome
141 export POPPLER_INC_DIR=${poppler_utils.dev}/include/poppler
142 export POPPLER_LIB_DIR=${poppler_utils.out}/lib
143 export MAGICK_INC=${imagemagick.dev}/include/ImageMagick
144 export MAGICK_LIB=${imagemagick.out}/lib
145 export FC_INC_DIR=${fontconfig.dev}/include/fontconfig
146 export FC_LIB_DIR=${fontconfig.lib}/lib
147 export PODOFO_INC_DIR=${podofo.dev}/include/podofo
148 export PODOFO_LIB_DIR=${podofo.lib}/lib
149 export XDG_DATA_HOME=$out/share
150 export XDG_UTILS_INSTALL_MODE="user"
152 python setup.py install --root=$out \
155 --staging-root=$out \
156 --staging-libdir=$out/lib \
157 --staging-sharedir=$out/share
159 PYFILES="$out/bin/* $out/lib/calibre/calibre/web/feeds/*.py
160 $out/lib/calibre/calibre/ebooks/metadata/*.py
161 $out/lib/calibre/calibre/ebooks/rtf2xml/*.py"
163 sed -i "s/env python[0-9.]*/python/" $PYFILES
164 sed -i "2i import sys; sys.argv[0] = 'calibre'" $out/bin/calibre
167 cp -a man-pages $out/share/man
173 dontWrapQtApps = true;
174 dontWrapGApps = true;
178 popplerArgs = "--prefix PATH : ${poppler_utils.out}/bin";
181 for program in $out/bin/*; do
182 wrapProgram $program \
183 ''${qtWrapperArgs[@]} \
184 ''${gappsWrapperArgs[@]} \
185 ${if popplerSupport then popplerArgs else ""}
189 doInstallCheck = true;
190 installCheckInputs = with python3Packages; [
194 installCheckPhase = ''
195 runHook preInstallCheck
197 ETN='--exclude-test-name'
199 $ETN 'test_7z' # we don't include 7z support
200 $ETN 'test_zstd' # we don't include zstd support
201 $ETN 'test_qt' # we don't include svg or webp support
202 $ETN 'test_import_of_all_python_modules' # explores actual file paths, gets confused
203 $ETN 'test_websocket_basic' # flakey
204 ${lib.optionalString (!unrarSupport) "$ETN 'test_unrar'"}
207 python setup.py test ''${EXCLUDED_FLAGS[@]}
209 runHook postInstallCheck
213 homepage = "https://calibre-ebook.com";
214 description = "Comprehensive e-book software";
216 calibre is a powerful and easy to use e-book manager. Users say it’s
217 outstanding and a must-have. It’ll allow you to do nearly everything and
218 it takes things a step beyond normal e-book software. It’s also completely
219 free and open source and great for both casual users and computer experts.
221 changelog = "https://github.com/kovidgoyal/calibre/releases/tag/v${finalAttrs.version}";
222 license = if unrarSupport
223 then lib.licenses.unfreeRedistributable
224 else lib.licenses.gpl3Plus;
225 maintainers = with lib.maintainers; [ pSub ];
226 platforms = lib.platforms.unix;
227 broken = stdenv.hostPlatform.isDarwin;