fork/wezterm

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

Francesco Zaniniflake.nix: fix build on darwina5abd6991

termwiz-0.23.2
7.4 KiB237 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/9.0.0";
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          preFixup =
135            lib.optionalString stdenv.isLinux ''
136              patchelf \
137                --add-needed "${pkgs.libGL}/lib/libEGL.so.1" \
138                --add-needed "${pkgs.vulkan-loader}/lib/libvulkan.so.1" \
139                $out/bin/wezterm-gui
140            ''
141            + lib.optionalString stdenv.isDarwin ''
142              mkdir -p "$out/Applications"
143              OUT_APP="$out/Applications/WezTerm.app"
144              cp -r assets/macos/WezTerm.app "$OUT_APP"
145              rm $OUT_APP/*.dylib
146              cp -r assets/shell-integration/* "$OUT_APP"
147              ln -s $out/bin/{wezterm,wezterm-mux-server,wezterm-gui,strip-ansi-escapes} "$OUT_APP"
148            '';
149
150          postInstall = ''
151            mkdir -p $out/nix-support
152            echo "${passthru.terminfo}" >> $out/nix-support/propagated-user-env-packages
153
154            install -Dm644 assets/icon/terminal.png $out/share/icons/hicolor/128x128/apps/org.wezfurlong.wezterm.png
155            install -Dm644 assets/wezterm.desktop $out/share/applications/org.wezfurlong.wezterm.desktop
156            install -Dm644 assets/wezterm.appdata.xml $out/share/metainfo/org.wezfurlong.wezterm.appdata.xml
157
158            install -Dm644 assets/shell-integration/wezterm.sh -t $out/etc/profile.d
159            installShellCompletion --cmd wezterm \
160              --bash assets/shell-completion/bash \
161              --fish assets/shell-completion/fish \
162              --zsh assets/shell-completion/zsh
163
164            install -Dm644 assets/wezterm-nautilus.py -t $out/share/nautilus-python/extensions
165          '';
166
167          passthru = {
168            # the headless variant is useful when deploying wezterm's mux server on remote severs
169            headless = rustPlatform.buildRustPackage {
170              pname = "wezterm-headless";
171              inherit
172                version
173                src
174                postPatch
175                cargoLock
176                meta
177                ;
178
179              nativeBuildInputs = [ pkgs.pkg-config ];
180
181              buildInputs = [ pkgs.openssl ];
182
183              cargoBuildFlags = [
184                "--package"
185                "wezterm"
186                "--package"
187                "wezterm-mux-server"
188              ];
189
190              doCheck = false;
191
192              postInstall = ''
193                install -Dm644 assets/shell-integration/wezterm.sh -t $out/etc/profile.d
194                install -Dm644 ${passthru.terminfo}/share/terminfo/w/wezterm -t $out/share/terminfo/w
195              '';
196            };
197
198            terminfo =
199              pkgs.runCommand "wezterm-terminfo"
200                {
201                  nativeBuildInputs = [ pkgs.ncurses ];
202                }
203                ''
204                  mkdir -p $out/share/terminfo $out/nix-support
205                  tic -x -o $out/share/terminfo ${src}/termwiz/data/wezterm.terminfo
206                '';
207          };
208
209          meta.mainProgram = "wezterm";
210        };
211
212        devShell = pkgs.mkShell {
213          name = "wezterm-shell";
214          inherit nativeBuildInputs;
215
216          buildInputs =
217            buildInputs
218            ++ (with pkgs.rust-bin; [
219              (stable.latest.minimal.override {
220                extensions = [
221                  "clippy"
222                  "rust-src"
223                ];
224              })
225
226              nightly.latest.rustfmt
227              nightly.latest.rust-analyzer
228            ]);
229
230          LD_LIBRARY_PATH = libPath;
231          RUST_BACKTRACE = 1;
232        };
233
234        formatter = pkgs.nixfmt-rfc-style;
235      }
236    );
237}