feat(nix): build and bundle terminal.so in the flake#2207
Merged
theangelperalta merged 4 commits intoJun 3, 2026
Conversation
The Nix flake never built the lem-terminal native helper: it has no libvterm input and no terminal.c build step, so on Nix the terminal extension silently disabled itself (ffi.lisp's use-foreign-library is wrapped in ignore-errors). Removing the committed binaries in lem-project#2204 did not regress this -- the prebuilt .so was dynamically linked against a libvterm that was never present in the Nix sandbox -- but it also left Nix without a working terminal. Add a terminal-so derivation that compiles extensions/terminal/terminal.c against pkgs.libvterm, mirroring the existing ts-wrapper / c-webview C derivations, and add it to the nativeLibs of lem-ncurses, lem-sdl2 and lem-webview. Dynamic linking is the idiomatic choice on Nix (unlike the AppImage/macOS bundles, which static-link in lem-project#2205): the stdenv records an RPATH to the pinned libvterm store path, so terminal.so resolves libvterm at runtime with no bundling or relinking, and nativeLibs puts terminal.so itself on the library path that ffi.lisp's "terminal.so" lookup uses at build and run time.
nixpkgs' libvterm (0.99.7) has meta.platforms = Linux only, so referencing pkgs.libvterm unconditionally made `nix flake check --all-systems` fail at evaluation on the aarch64-darwin / x86_64-darwin systems, breaking every build job. Add terminal-so to nativeLibs only when stdenv.isLinux (via lib.optionals, which doesn't force its list when the condition is false). Terminal works on Linux Nix builds; Darwin Nix is unchanged (no terminal, as before, since nixpkgs doesn't package libvterm for Darwin).
…ovim fork) nixpkgs' libvterm (0.99.7) is the Neovim fork, whose vterm.h #includes <glib.h>. terminal.c includes vterm.h, so the build failed with "fatal error: glib.h: No such file or directory". Add pkg-config + glib and pull GLib's compile/link flags via `pkg-config --cflags --libs glib-2.0`.
The compile failed on glib.h then curses.h from libvterm-0.99.7's vterm.h because pkgs.libvterm is the old, abandoned glib/curses-based "libvterm" with an API incompatible with terminal.c. Leonerd's modern libvterm -- the one terminal.c targets -- is packaged as pkgs.libvterm-neovim. Switch to pkgs.libvterm-neovim and drop the glib/pkg-config workaround.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
Makes the terminal extension work in Nix builds by compiling and bundling
terminal.soin the flake. Until now the flake had no libvterm input and no terminal build step, so on Nix the terminal extension silently disabled itself.Why
ffi.lisploadsterminal.sobest-effort (ignore-errors), and the flake builds Lem vialisp.buildASDFSystemwith native deps declared innativeLibs(ncurses, tree-sitter,ts-wrapper, webview) — but never libvterm/terminal.so. So:terminal.sowas dynamically linked against a libvterm that isn't in the Nix sandbox.Change
terminal-soderivation that compilesextensions/terminal/terminal.cagainstpkgs.libvterm, mirroring the existingts-wrapper/c-webviewC derivations.nativeLibsoflem-ncurses,lem-sdl2, andlem-webview(both branches).Why dynamic (not static like #2205)
On Nix, dynamic linking is the idiomatic and more reliable choice:
libvtermstore path, soterminal.soresolves libvterm at runtime with no bundling or relinking — exactly howts-wrapperresolves tree-sitter today.nativeLibsputsterminal.soitself on the library path thatffi.lisp's"terminal.so"lookup uses, at both build time (so CFFI registers it for image-restore reload) and run time (baked into thewrapProgramLD_LIBRARY_PATH).libvterm.athat nixpkgs doesn't ship by default.The output keeps the
.sosuffix on both platforms (not.dylib), becauseffi.lisploads it by the literal nameterminal.soeven on macOS.Test plan
.github/workflows/ci.yml) runsnix flake check+nix build .#lem-ncurses/.#lem-webview/.#lem-sdl2on Linux and macOS — this builds theterminal-soderivation and is the authoritative check. (Could not runnixlocally — no nix on this machine.)pkgs.libvtermis the correct attr and its version compilesterminal.c(theconceal/strikecell-attr fields need libvterm ≥ 0.3; if nixpkgs'libvtermis too old or misnamed, fall back topkgs.libvterm-neovim).lem, open a*terminal*buffer, confirm a shell runs.Refs #1964, #2060, #2204, #2205.