fork/wezterm

git clone https://git.julia.blue/fork/wezterm

Chris PickUnset `$RUST_BACKTRACE` in nixShelldd6e5bd2f

main
7.9 KiB243 linesraw
1{
2  description = "A GPU-accelerated cross-platform terminal emulator and multiplexer written by @wez and implemented in Rust";
3
4  inputs = {
5    nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
6    flake-utils.url = "github:numtide/flake-utils";
7    rust-overlay = {
8      url = "github:oxalica/rust-overlay";
9      inputs.nixpkgs.follows = "nixpkgs";
10    };
11
12    # NOTE: @2024-05 Nix flakes does not support getting git submodules of 'self'.
13    # refs:
14    # - https://discourse.nixos.org/t/get-nix-flake-to-include-git-submodule/30324
15    # - https://github.com/NixOS/nix/pull/7862
16    #
17    # ... In the meantime we kinda duplicate the dependencies here then replace the submodules with
18    # links to each repo in package sources.
19    #
20    # Try to use tags when possible to increase readability
21    # (note: `git submodule status` in wezterm repo will show the `git describe` result for each
22    # submodule, can help finding a tag if any)
23    freetype2 = {
24      url = "github:freetype/freetype/VER-2-13-3";
25      flake = false;
26    };
27    harfbuzz = {
28      url = "github:harfbuzz/harfbuzz/11.2.1";
29      flake = false;
30    };
31    libpng = {
32      url = "github:pnggroup/libpng/v1.6.44";
33      flake = false;
34    };
35    zlib = {
36      url = "github:madler/zlib/v1.3.1";
37      flake = false;
38    };
39  };
40
41  outputs =
42    inputs@{ self, ... }:
43    inputs.flake-utils.lib.eachDefaultSystem (
44      system:
45      let
46        overlays = [ (import inputs.rust-overlay) ];
47        pkgs = import (inputs.nixpkgs) { inherit system overlays; };
48
49        inherit (inputs.nixpkgs) lib;
50        inherit (pkgs) stdenv;
51
52        nativeBuildInputs =
53          with pkgs;
54          [
55            installShellFiles
56            ncurses # tic for terminfo
57            pkg-config
58            python3
59          ]
60          ++ lib.optional stdenv.isDarwin perl;
61
62        buildInputs =
63          with pkgs;
64          [
65            fontconfig
66            openssl
67            zlib
68          ]
69          ++ lib.optionals stdenv.isLinux [
70            libxkbcommon
71            wayland
72
73            xorg.libX11
74            xorg.libxcb
75            xorg.xcbutil
76            xorg.xcbutilimage
77            xorg.xcbutilkeysyms
78            xorg.xcbutilwm # contains xcb-ewmh among others
79          ]
80          ++ lib.optionals stdenv.isDarwin ([
81            libiconv
82          ]);
83
84        libPath = lib.makeLibraryPath (
85          with pkgs;
86          [
87            xorg.xcbutilimage
88            libGL
89            vulkan-loader
90          ]
91        );
92
93        rustPlatform = pkgs.makeRustPlatform {
94          cargo = pkgs.rust-bin.stable.latest.minimal;
95          rustc = pkgs.rust-bin.stable.latest.minimal;
96        };
97      in
98      {
99        packages.default = rustPlatform.buildRustPackage rec {
100          inherit buildInputs nativeBuildInputs;
101
102          name = "wezterm";
103          src = ./..;
104          version = self.shortRev or "dev";
105
106          cargoLock = {
107            lockFile = ../Cargo.lock;
108            allowBuiltinFetchGit = true;
109          };
110
111          prePatch = ''
112            rm -rf deps/freetype/{freetype2,libpng,zlib} deps/harfbuzz/harfbuzz
113
114            ln -s ${inputs.freetype2} deps/freetype/freetype2
115            ln -s ${inputs.libpng} deps/freetype/libpng
116            ln -s ${inputs.zlib} deps/freetype/zlib
117            ln -s ${inputs.harfbuzz} deps/harfbuzz/harfbuzz
118          '';
119
120          postPatch = ''
121            echo ${version} > .tag
122
123            # tests are failing with: Unable to exchange encryption keys
124            rm -r wezterm-ssh/tests
125
126            # hash does not work well with NixOS
127            substituteInPlace assets/shell-integration/wezterm.sh \
128              --replace-fail 'hash wezterm 2>/dev/null' 'command type -P wezterm &>/dev/null' \
129              --replace-fail 'hash base64 2>/dev/null' 'command type -P base64 &>/dev/null' \
130              --replace-fail 'hash hostname 2>/dev/null' 'command type -P hostname &>/dev/null' \
131              --replace-fail 'hash hostnamectl 2>/dev/null' 'command type -P hostnamectl &>/dev/null'
132          '';
133
134          # Disable cargo-auditable until https://github.com/rust-secure-code/cargo-auditable/issues/124 is fixed
135          auditable = false;
136
137          preFixup =
138            lib.optionalString stdenv.isLinux /* bash */ ''
139              patchelf \
140                --add-needed "${pkgs.libGL}/lib/libEGL.so.1" \
141                --add-needed "${pkgs.vulkan-loader}/lib/libvulkan.so.1" \
142                $out/bin/wezterm-gui
143            ''
144            + lib.optionalString stdenv.isDarwin /* bash */ ''
145              mkdir -p "$out/Applications"
146              OUT_APP="$out/Applications/WezTerm.app"
147              cp -r assets/macos/WezTerm.app "$OUT_APP"
148              rm $OUT_APP/*.dylib
149              cp -r assets/shell-integration/* "$OUT_APP"
150              # macOS will only recognize our application bundle
151              # if the binaries are inside of it. Move them there
152              # and create symbolic links for them in bin/.
153              mv $out/bin/{wezterm,wezterm-mux-server,wezterm-gui,strip-ansi-escapes} "$OUT_APP"
154              ln -s "$OUT_APP"/{wezterm,wezterm-mux-server,wezterm-gui,strip-ansi-escapes} "$out/bin"
155            '';
156
157          postInstall = ''
158            mkdir -p $out/nix-support
159            echo "${passthru.terminfo}" >> $out/nix-support/propagated-user-env-packages
160
161            install -Dm644 assets/icon/terminal.png $out/share/icons/hicolor/128x128/apps/org.wezfurlong.wezterm.png
162            install -Dm644 assets/wezterm.desktop $out/share/applications/org.wezfurlong.wezterm.desktop
163            install -Dm644 assets/wezterm.appdata.xml $out/share/metainfo/org.wezfurlong.wezterm.appdata.xml
164
165            install -Dm644 assets/shell-integration/wezterm.sh -t $out/etc/profile.d
166            installShellCompletion --cmd wezterm \
167              --bash assets/shell-completion/bash \
168              --fish assets/shell-completion/fish \
169              --zsh assets/shell-completion/zsh
170
171            install -Dm644 assets/wezterm-nautilus.py -t $out/share/nautilus-python/extensions
172          '';
173
174          passthru = {
175            # the headless variant is useful when deploying wezterm's mux server on remote severs
176            headless = rustPlatform.buildRustPackage {
177              pname = "wezterm-headless";
178              inherit
179                version
180                src
181                postPatch
182                cargoLock
183                meta
184                ;
185
186              nativeBuildInputs = [ pkgs.pkg-config ];
187
188              buildInputs = [ pkgs.openssl ];
189
190              cargoBuildFlags = [
191                "--package"
192                "wezterm"
193                "--package"
194                "wezterm-mux-server"
195              ];
196
197              doCheck = false;
198
199              postInstall = ''
200                install -Dm644 assets/shell-integration/wezterm.sh -t $out/etc/profile.d
201                install -Dm644 ${passthru.terminfo}/share/terminfo/w/wezterm -t $out/share/terminfo/w
202              '';
203            };
204
205            terminfo =
206              pkgs.runCommand "wezterm-terminfo"
207                {
208                  nativeBuildInputs = [ pkgs.ncurses ];
209                }
210                ''
211                  mkdir -p $out/share/terminfo $out/nix-support
212                  tic -x -o $out/share/terminfo ${src}/termwiz/data/wezterm.terminfo
213                '';
214          };
215
216          meta.mainProgram = "wezterm";
217        };
218
219        devShell = pkgs.mkShell {
220          name = "wezterm-shell";
221          inherit nativeBuildInputs;
222
223          buildInputs =
224            buildInputs
225            ++ (with pkgs.rust-bin; [
226              (stable.latest.minimal.override {
227                extensions = [
228                  "clippy"
229                  "rust-src"
230                ];
231              })
232
233              nightly.latest.rustfmt
234              nightly.latest.rust-analyzer
235            ]);
236
237          LD_LIBRARY_PATH = libPath;
238        };
239
240        formatter = pkgs.nixfmt-rfc-style;
241      }
242    );
243}