microfetch: 0.4.4 -> 0.4.6 (#377799)
[NixPkgs.git] / pkgs / applications / networking / browsers / qutebrowser / default.nix
blob1de7936f7d7f8c594368da8006f23f808ac9d9db
2   stdenv,
3   lib,
4   fetchurl,
5   fetchzip,
6   python3,
7   wrapQtAppsHook,
8   glib-networking,
9   asciidoc,
10   docbook_xml_dtd_45,
11   docbook_xsl,
12   libxml2,
13   libxslt,
14   withPdfReader ? true,
15   pipewireSupport ? stdenv.hostPlatform.isLinux,
16   pipewire,
17   qtwayland,
18   qtbase,
19   qtwebengine,
20   enableWideVine ? false,
21   widevine-cdm,
22   # can cause issues on some graphics chips
23   enableVulkan ? false,
24   vulkan-loader,
27 let
28   isQt6 = lib.versions.major qtbase.version == "6";
29   pdfjs =
30     let
31       version = "4.2.67";
32     in
33     fetchzip {
34       url = "https://github.com/mozilla/pdf.js/releases/download/v${version}/pdfjs-${version}-dist.zip";
35       hash = "sha256-7kfT3+ZwoGqZ5OwkO9h3DIuBFd0v8fRlcufxoBdcy8c=";
36       stripRoot = false;
37     };
39   version = "3.4.0";
42 python3.pkgs.buildPythonApplication {
43   pname = "qutebrowser" + lib.optionalString (!isQt6) "-qt5";
44   inherit version;
45   pyproject = true;
47   src = fetchurl {
48     url = "https://github.com/qutebrowser/qutebrowser/releases/download/v${version}/qutebrowser-${version}.tar.gz";
49     hash = "sha256-gUEkwO0zdDDmE6HaNm1eOJBMsgSa+xUFlxRWylymIj4=";
50   };
52   # Needs tox
53   doCheck = false;
55   buildInputs =
56     [
57       qtbase
58       glib-networking
59     ]
60     ++ lib.optionals stdenv.hostPlatform.isLinux [
61       qtwayland
62     ];
64   build-system = with python3.pkgs; [
65     setuptools
66   ];
68   nativeBuildInputs = [
69     wrapQtAppsHook
70     asciidoc
71     docbook_xml_dtd_45
72     docbook_xsl
73     libxml2
74     libxslt
75   ];
77   dependencies = with python3.pkgs; [
78     colorama
79     pyyaml
80     (if isQt6 then pyqt6-webengine else pyqtwebengine)
81     jinja2
82     pygments
83     # scripts and userscripts libs
84     tldextract
85     beautifulsoup4
86     readability-lxml
87     pykeepass
88     stem
89     pynacl
90     # extensive ad blocking
91     adblock
92     # for the qute-bitwarden user script to be able to copy the TOTP token to clipboard
93     pyperclip
94   ];
96   patches = [
97     ./fix-restart.patch
98   ];
100   dontWrapQtApps = true;
102   postPatch =
103     ''
104       substituteInPlace qutebrowser/misc/quitter.py --subst-var-by qutebrowser "$out/bin/qutebrowser"
106       sed -i "s,/usr,$out,g" qutebrowser/utils/standarddir.py
107     ''
108     + lib.optionalString withPdfReader ''
109       sed -i "s,/usr/share/pdf.js,${pdfjs},g" qutebrowser/browser/pdfjs.py
110     '';
112   installPhase = ''
113     runHook preInstall
115     make -f misc/Makefile \
116       PYTHON=${(python3.pythonOnBuildForHost.withPackages (ps: with ps; [ setuptools ])).interpreter} \
117       PREFIX=. \
118       DESTDIR="$out" \
119       DATAROOTDIR=/share \
120       install
122     runHook postInstall
123   '';
125   postInstall = ''
126     # Patch python scripts
127     buildPythonPath "$out $propagatedBuildInputs"
128     scripts=$(grep -rl python "$out"/share/qutebrowser/{user,}scripts/)
129     for i in $scripts; do
130       patchPythonScript "$i"
131     done
132   '';
134   preFixup =
135     let
136       libPath = lib.makeLibraryPath [ pipewire ];
137     in
138     ''
139       makeWrapperArgs+=(
140         # Force the app to use QT_PLUGIN_PATH values from wrapper
141         --unset QT_PLUGIN_PATH
142         "''${qtWrapperArgs[@]}"
143         # avoid persistant warning on starup
144         --set QT_STYLE_OVERRIDE Fusion
145         ${lib.optionalString pipewireSupport ''--prefix LD_LIBRARY_PATH : ${libPath}''}
146         ${lib.optionalString (enableVulkan) ''
147           --prefix LD_LIBRARY_PATH : ${lib.makeLibraryPath [ vulkan-loader ]}
148           --set-default QSG_RHI_BACKEND vulkan
149         ''}
150         ${lib.optionalString enableWideVine ''--add-flags "--qt-flag widevine-path=${widevine-cdm}/share/google/chrome/WidevineCdm/_platform_specific/linux_x64/libwidevinecdm.so"''}
151         --set QTWEBENGINE_RESOURCES_PATH "${qtwebengine}/resources"
152       )
153     '';
155   meta = with lib; {
156     homepage = "https://github.com/qutebrowser/qutebrowser";
157     changelog = "https://github.com/qutebrowser/qutebrowser/blob/v${version}/doc/changelog.asciidoc";
158     description = "Keyboard-focused browser with a minimal GUI";
159     license = licenses.gpl3Plus;
160     mainProgram = "qutebrowser";
161     platforms = if enableWideVine then [ "x86_64-linux" ] else qtwebengine.meta.platforms;
162     maintainers = with maintainers; [
163       jagajaga
164       rnhmjoj
165       ebzzry
166       dotlambda
167       nrdxp
168     ];
169   };