ripasso-cursive: cosmetic changes (#361736)
[NixPkgs.git] / pkgs / by-name / ca / calibre / package.nix
blob09ca09b319cafe1b878649d53ce748e9b44b355d
2   lib,
3   stdenv,
4   fetchurl,
5   cmake,
6   fetchpatch,
7   ffmpeg,
8   fontconfig,
9   hunspell,
10   hyphen,
11   icu,
12   imagemagick,
13   libjpeg,
14   libmtp,
15   libpng,
16   libstemmer,
17   libuchardet,
18   libusb1,
19   piper-tts,
20   pkg-config,
21   podofo,
22   poppler_utils,
23   python3Packages,
24   qt6,
25   speechd-minimal,
26   sqlite,
27   xdg-utils,
28   wrapGAppsHook3,
29   popplerSupport ? true,
30   speechSupport ? true,
31   unrarSupport ? false,
34 stdenv.mkDerivation (finalAttrs: {
35   pname = "calibre";
36   version = "7.21.0";
38   src = fetchurl {
39     url = "https://download.calibre-ebook.com/${finalAttrs.version}/calibre-${finalAttrs.version}.tar.xz";
40     hash = "sha256-61Nbclkt59sh8VHh3uRw0GvlDjlyOz1jrsFMMIuzPLE=";
41   };
43   patches = [
44     #  allow for plugin update check, but no calibre version check
45     (fetchpatch {
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=";
49     })
50     (fetchpatch {
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=";
54     })
55   ] ++ lib.optional (!unrarSupport) ./dont_build_unrar_plugin.patch;
57   prePatch = ''
58     sed -i "s@\[tool.sip.project\]@[tool.sip.project]\nsip-include-dirs = [\"${python3Packages.pyqt6}/${python3Packages.python.sitePackages}/PyQt6/bindings\"]@g" \
59       setup/build.py
61     # Remove unneeded files and libs
62     rm -rf src/odf resources/calibre-portable.*
63   '';
65   dontUseQmakeConfigure = true;
66   dontUseCmakeConfigure = true;
68   nativeBuildInputs = [
69     cmake
70     pkg-config
71     qt6.qmake
72     qt6.wrapQtAppsHook
73     wrapGAppsHook3
74   ];
76   buildInputs = [
77     ffmpeg
78     fontconfig
79     hunspell
80     hyphen
81     icu
82     imagemagick
83     libjpeg
84     libmtp
85     libpng
86     libstemmer
87     libuchardet
88     libusb1
89     piper-tts
90     podofo
91     poppler_utils
92     qt6.qtbase
93     qt6.qtwayland
94     sqlite
95     (python3Packages.python.withPackages (
96       ps:
97       with ps;
98       [
99         (apsw.overrideAttrs (oldAttrs: {
100           setupPyBuildFlags = [ "--enable=load_extension" ];
101         }))
102         beautifulsoup4
103         css-parser
104         cssselect
105         python-dateutil
106         dnspython
107         faust-cchardet
108         feedparser
109         html2text
110         html5-parser
111         lxml
112         markdown
113         mechanize
114         msgpack
115         netifaces
116         pillow
117         pychm
118         pyqt-builder
119         pyqt6
120         python
121         regex
122         sip
123         setuptools
124         zeroconf
125         jeepney
126         pycryptodome
127         xxhash
128         # the following are distributed with calibre, but we use upstream instead
129         odfpy
130       ]
131       ++
132         lib.optionals (lib.lists.any (p: p == stdenv.hostPlatform.system) pyqt6-webengine.meta.platforms)
133           [
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.
137             pyqt6-webengine
138           ]
139       ++ lib.optional (unrarSupport) unrardll
140     ))
141     xdg-utils
142   ] ++ lib.optional (speechSupport) speechd-minimal;
144   installPhase = ''
145     runHook preInstall
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 \
161       --prefix=$out \
162       --libdir=$out/lib \
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
174     mkdir -p $out/share
175     cp -a man-pages $out/share/man
177     runHook postInstall
178   '';
180   # Wrap manually
181   dontWrapQtApps = true;
182   dontWrapGApps = true;
184   preFixup =
185     let
186       popplerArgs = "--prefix PATH : ${poppler_utils.out}/bin";
187     in
188     ''
189       for program in $out/bin/*; do
190         wrapProgram $program \
191           ''${qtWrapperArgs[@]} \
192           ''${gappsWrapperArgs[@]} \
193           ${if popplerSupport then popplerArgs else ""}
194       done
195     '';
197   doInstallCheck = true;
198   installCheckInputs = with python3Packages; [
199     fonttools
200     psutil
201   ];
202   installCheckPhase = ''
203     runHook preInstallCheck
205     ETN='--exclude-test-name'
206     EXCLUDED_FLAGS=(
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'"}
213     )
215     python setup.py test ''${EXCLUDED_FLAGS[@]}
217     runHook postInstallCheck
218   '';
220   meta = {
221     homepage = "https://calibre-ebook.com";
222     description = "Comprehensive e-book software";
223     longDescription = ''
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.
228     '';
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;
234   };