python3Packages.orjson: Disable failing tests on 32 bit
[NixPkgs.git] / pkgs / applications / terminal-emulators / kitty / default.nix
blobb6a6ca7780fb61b0eae8020f18698912bbc88711
1 { lib, stdenv, fetchFromGitHub, python3Packages, libunistring
2 , harfbuzz, fontconfig, pkg-config, ncurses, imagemagick
3 , libstartup_notification, libGL, libX11, libXrandr, libXinerama, libXcursor
4 , libxkbcommon, libXi, libXext, wayland-protocols, wayland
5 , lcms2
6 , librsync
7 , openssl
8 , installShellFiles
9 , dbus
10 , darwin
11 , Cocoa
12 , CoreGraphics
13 , Foundation
14 , IOKit
15 , Kernel
16 , OpenGL
17 , libcanberra
18 , libicns
19 , libpng
20 , python3
21 , zlib
22 , bashInteractive
23 , zsh
24 , fish
25 , nixosTests
28 with python3Packages;
29 buildPythonApplication rec {
30   pname = "kitty";
31   version = "0.26.2";
32   format = "other";
34   src = fetchFromGitHub {
35     owner = "kovidgoyal";
36     repo = "kitty";
37     rev = "v${version}";
38     sha256 = "sha256-IqXRkKzOfqWolH/534nmM2R/69olhFOk6wbbF4ifRd0=";
39   };
41   buildInputs = [
42     harfbuzz
43     ncurses
44     lcms2
45     librsync
46     openssl.dev
47   ] ++ lib.optionals stdenv.isDarwin [
48     Cocoa
49     CoreGraphics
50     Foundation
51     IOKit
52     Kernel
53     OpenGL
54     libpng
55     python3
56     zlib
57   ] ++ lib.optionals (stdenv.isDarwin && (builtins.hasAttr "UserNotifications" darwin.apple_sdk.frameworks)) [
58     darwin.apple_sdk.frameworks.UserNotifications
59   ] ++ lib.optionals stdenv.isLinux [
60     fontconfig libunistring libcanberra libX11
61     libXrandr libXinerama libXcursor libxkbcommon libXi libXext
62     wayland-protocols wayland dbus libGL
63   ];
65   nativeBuildInputs = [
66     installShellFiles
67     ncurses
68     pkg-config
69     sphinx
70     furo
71     sphinx-copybutton
72     sphinxext-opengraph
73     sphinx-inline-tabs
74   ] ++ lib.optionals stdenv.isDarwin [
75     imagemagick
76     libicns  # For the png2icns tool.
77   ];
79   outputs = [ "out" "terminfo" "shell_integration" ];
81   patches = [
82     # Gets `test_ssh_env_vars` to pass when `bzip2` is in the output of `env`.
83     ./fix-test_ssh_env_vars.patch
85     # Needed on darwin
87     # Gets `test_ssh_shell_integration` to pass for `zsh` when `compinit` complains about
88     # permissions.
89     ./zsh-compinit.patch
91     # Skip `test_ssh_bootstrap_with_different_launchers` when launcher is `zsh` since it causes:
92     # OSError: master_fd is in error condition
93     ./disable-test_ssh_bootstrap_with_different_launchers.patch
94   ];
96   # Causes build failure due to warning
97   hardeningDisable = lib.optional stdenv.cc.isClang "strictoverflow";
99   dontConfigure = true;
101   buildPhase = let
102     commonOptions = ''
103       --update-check-interval=0 \
104       --shell-integration=enabled\ no-rc
105     '';
106     darwinOptions = ''
107       --disable-link-time-optimization \
108       ${commonOptions}
109     '';
110   in ''
111     runHook preBuild
112     ${if stdenv.isDarwin then ''
113       ${python.interpreter} setup.py build ${darwinOptions}
114       make docs
115       ${python.interpreter} setup.py kitty.app ${darwinOptions}
116     '' else ''
117       ${python.interpreter} setup.py build-launcher
118       ${python.interpreter} setup.py linux-package \
119       --egl-library='${lib.getLib libGL}/lib/libEGL.so.1' \
120       --startup-notification-library='${libstartup_notification}/lib/libstartup-notification-1.so' \
121       --canberra-library='${libcanberra}/lib/libcanberra.so' \
122       --fontconfig-library='${fontconfig.lib}/lib/libfontconfig.so' \
123       ${commonOptions}
124     ''}
125     runHook postBuild
126   '';
128   checkInputs = [
129     pillow
131     # Shells needed for shell integration tests
132     bashInteractive
133     zsh
134     fish
135   ];
137   # skip failing tests due to darwin sandbox
138   preCheck = lib.optionalString stdenv.isDarwin ''
139     substituteInPlace kitty_tests/file_transmission.py \
140       --replace test_file_get dont_test_file_get \
141       --replace test_path_mapping_receive dont_test_path_mapping_receive
142     substituteInPlace kitty_tests/shell_integration.py \
143       --replace test_fish_integration dont_test_fish_integration
144     substituteInPlace kitty_tests/open_actions.py \
145       --replace test_parsing_of_open_actions dont_test_parsing_of_open_actions
146     substituteInPlace kitty_tests/ssh.py \
147       --replace test_ssh_connection_data dont_test_ssh_connection_data
148     substituteInPlace kitty_tests/fonts.py \
149       --replace 'class Rendering(BaseTest)' 'class Rendering'
150   '';
152   checkPhase = ''
153       runHook preCheck
155       # Fontconfig error: Cannot load default config file: No such file: (null)
156       export FONTCONFIG_FILE=${fontconfig.out}/etc/fonts/fonts.conf
158       # Required for `test_ssh_shell_integration` to pass.
159       export TERM=kitty
161       make test
162       runHook postCheck
163     '';
165   installPhase = ''
166     runHook preInstall
167     mkdir -p $out
168     ${if stdenv.isDarwin then ''
169     mkdir "$out/bin"
170     ln -s ../Applications/kitty.app/Contents/MacOS/kitty "$out/bin/kitty"
171     mkdir "$out/Applications"
172     cp -r kitty.app "$out/Applications/kitty.app"
174     installManPage 'docs/_build/man/kitty.1'
175     '' else ''
176     cp -r linux-package/{bin,share,lib} $out
177     ''}
178     wrapProgram "$out/bin/kitty" --prefix PATH : "$out/bin:${lib.makeBinPath [ imagemagick ncurses.dev ]}"
180     installShellCompletion --cmd kitty \
181       --bash <("$out/bin/kitty" +complete setup bash) \
182       --fish <("$out/bin/kitty" +complete setup fish2) \
183       --zsh  <("$out/bin/kitty" +complete setup zsh)
185     terminfo_src=${if stdenv.isDarwin then
186       ''"$out/Applications/kitty.app/Contents/Resources/terminfo"''
187       else
188       "$out/share/terminfo"}
190     mkdir -p $terminfo/share
191     mv "$terminfo_src" $terminfo/share/terminfo
193     mkdir -p $out/nix-support
194     echo "$terminfo" >> $out/nix-support/propagated-user-env-packages
196     cp -r 'shell-integration' "$shell_integration"
198     runHook postInstall
199   '';
201   # Patch shebangs that Nix can't automatically patch
202   preFixup =
203     let
204       pathComponent = if stdenv.isDarwin then "Applications/kitty.app/Contents/Resources" else "lib";
205     in
206     ''
207       substituteInPlace $out/${pathComponent}/kitty/shell-integration/ssh/askpass.py \
208         --replace '/usr/bin/env -S ' $out/bin/
209       substituteInPlace $shell_integration/ssh/askpass.py \
210         --replace '/usr/bin/env -S ' $out/bin/
211     '';
213   passthru.tests.test = nixosTests.terminal-emulators.kitty;
215   meta = with lib; {
216     homepage = "https://github.com/kovidgoyal/kitty";
217     description = "A modern, hackable, featureful, OpenGL based terminal emulator";
218     license = licenses.gpl3Only;
219     changelog = "https://sw.kovidgoyal.net/kitty/changelog/";
220     platforms = platforms.darwin ++ platforms.linux;
221     maintainers = with maintainers; [ tex rvolosatovs Luflosi ];
222   };