fork/wezterm
git clone https://git.julia.blue/fork/wezterm
dd6e5bd2f
main
1{ 2description = "A GPU-accelerated cross-platform terminal emulator and multiplexer written by @wez and implemented in Rust" ; 3 4inputs = { 5nixpkgs . url = "github:NixOS/nixpkgs/nixpkgs-unstable" ; 6flake-utils . url = "github:numtide/flake-utils" ; 7rust-overlay = { 8url = "github:oxalica/rust-overlay" ; 9inputs . 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) 23freetype2 = { 24url = "github:freetype/freetype/VER-2-13-3" ; 25flake = false ; 26}; 27harfbuzz = { 28url = "github:harfbuzz/harfbuzz/11.2.1" ; 29flake = false ; 30}; 31libpng = { 32url = "github:pnggroup/libpng/v1.6.44" ; 33flake = false ; 34}; 35zlib = { 36url = "github:madler/zlib/v1.3.1" ; 37flake = false ; 38}; 39}; 40 41outputs = 42inputs @{ self , ...} : 43inputs . flake-utils . lib . eachDefaultSystem ( 44system : 45let 46overlays = [ ( import inputs . rust-overlay ) ]; 47pkgs = import ( inputs . nixpkgs ) { inherit system overlays ; }; 48 49inherit ( inputs . nixpkgs ) lib ; 50inherit ( pkgs ) stdenv ; 51 52nativeBuildInputs = 53with pkgs ; 54[ 55installShellFiles 56ncurses # tic for terminfo 57pkg-config 58python3 59] 60++ lib . optional stdenv . isDarwin perl ; 61 62buildInputs = 63with pkgs ; 64[ 65fontconfig 66openssl 67zlib 68] 69++ lib . optionals stdenv . isLinux [ 70libxkbcommon 71wayland 72 73xorg . libX11 74xorg . libxcb 75xorg . xcbutil 76xorg . xcbutilimage 77xorg . xcbutilkeysyms 78xorg . xcbutilwm # contains xcb-ewmh among others 79] 80++ lib . optionals stdenv . isDarwin ([ 81libiconv 82]); 83 84libPath = lib . makeLibraryPath ( 85with pkgs ; 86[ 87xorg . xcbutilimage 88libGL 89vulkan-loader 90] 91); 92 93rustPlatform = pkgs . makeRustPlatform { 94cargo = pkgs . rust-bin . stable . latest . minimal ; 95rustc = pkgs . rust-bin . stable . latest . minimal ; 96}; 97in 98{ 99packages . default = rustPlatform . buildRustPackage rec { 100inherit buildInputs nativeBuildInputs ; 101 102name = "wezterm" ; 103src = ./.. ; 104version = self . shortRev or "dev" ; 105 106cargoLock = { 107lockFile = ../Cargo.lock ; 108allowBuiltinFetchGit = true ; 109}; 110 111prePatch = '' 112rm -rf deps/freetype/{freetype2,libpng,zlib} deps/harfbuzz/harfbuzz 113 114ln -s ${ inputs . freetype2 } deps/freetype/freetype2 115ln -s ${ inputs . libpng } deps/freetype/libpng 116ln -s ${ inputs . zlib } deps/freetype/zlib 117ln -s ${ inputs . harfbuzz } deps/harfbuzz/harfbuzz 118'' ; 119 120postPatch = '' 121echo ${ version } > .tag 122 123# tests are failing with: Unable to exchange encryption keys 124rm -r wezterm-ssh/tests 125 126# hash does not work well with NixOS 127substituteInPlace 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 135auditable = false ; 136 137preFixup = 138lib . optionalString stdenv . isLinux /* bash */ '' 139patchelf \ 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 */ '' 145mkdir -p "$out/Applications" 146OUT_APP="$out/Applications/WezTerm.app" 147cp -r assets/macos/WezTerm.app "$OUT_APP" 148rm $OUT_APP/*.dylib 149cp -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/. 153mv $out/bin/{wezterm,wezterm-mux-server,wezterm-gui,strip-ansi-escapes} "$OUT_APP" 154ln -s "$OUT_APP"/{wezterm,wezterm-mux-server,wezterm-gui,strip-ansi-escapes} "$out/bin" 155'' ; 156 157postInstall = '' 158mkdir -p $ out /nix-support 159echo " ${ passthru . terminfo } " >> $ out /nix-support/propagated-user-env-packages 160 161install -Dm644 assets/icon/terminal.png $ out /share/icons/hicolor/128x128/apps/org.wezfurlong.wezterm.png 162install -Dm644 assets/wezterm.desktop $ out /share/applications/org.wezfurlong.wezterm.desktop 163install -Dm644 assets/wezterm.appdata.xml $ out /share/metainfo/org.wezfurlong.wezterm.appdata.xml 164 165install -Dm644 assets/shell-integration/wezterm.sh -t $ out /etc/profile.d 166installShellCompletion --cmd wezterm \ 167--bash assets/shell-completion/bash \ 168--fish assets/shell-completion/fish \ 169--zsh assets/shell-completion/zsh 170 171install -Dm644 assets/wezterm-nautilus.py -t $ out /share/nautilus-python/extensions 172'' ; 173 174passthru = { 175# the headless variant is useful when deploying wezterm's mux server on remote severs 176headless = rustPlatform . buildRustPackage { 177pname = "wezterm-headless" ; 178inherit 179version 180src 181postPatch 182cargoLock 183meta 184; 185 186nativeBuildInputs = [ pkgs . pkg-config ]; 187 188buildInputs = [ pkgs . openssl ]; 189 190cargoBuildFlags = [ 191"--package" 192"wezterm" 193"--package" 194"wezterm-mux-server" 195]; 196 197doCheck = false ; 198 199postInstall = '' 200install -Dm644 assets/shell-integration/wezterm.sh -t $ out /etc/profile.d 201install -Dm644 ${ passthru . terminfo } /share/terminfo/w/wezterm -t $ out /share/terminfo/w 202'' ; 203}; 204 205terminfo = 206pkgs . runCommand "wezterm-terminfo" 207{ 208nativeBuildInputs = [ pkgs . ncurses ]; 209} 210'' 211mkdir -p $ out /share/terminfo $ out /nix-support 212tic -x -o $ out /share/terminfo ${ src } /termwiz/data/wezterm.terminfo 213'' ; 214}; 215 216meta . mainProgram = "wezterm" ; 217}; 218 219devShell = pkgs . mkShell { 220name = "wezterm-shell" ; 221inherit nativeBuildInputs ; 222 223buildInputs = 224buildInputs 225++ ( with pkgs . rust-bin ; [ 226( stable . latest . minimal . override { 227extensions = [ 228"clippy" 229"rust-src" 230]; 231}) 232 233nightly . latest . rustfmt 234nightly . latest . rust-analyzer 235]); 236 237LD_LIBRARY_PATH = libPath ; 238}; 239 240formatter = pkgs . nixfmt-rfc-style ; 241} 242); 243}