|
454 | 454 | legacySonameShims |
455 | 455 | ]; |
456 | 456 |
|
| 457 | + # ── A standard set of development libraries ── |
| 458 | + # |
| 459 | + # The NixOS answer to what `apt install libssl-dev` and friends give Ubuntu |
| 460 | + # in /usr/include and /usr/lib. The list is not a guess: it is what the |
| 461 | + # Cargo.lock files under ~/dev actually link (openssl-sys, libz-sys, |
| 462 | + # libgit2-sys, libssh2-sys, zstd-sys, lzma-sys, libsqlite3-sys, bzip2-sys, |
| 463 | + # the webkit2gtk-sys stack for Tauri, clang-sys, libdbus-sys, alsa-sys and |
| 464 | + # the appindicator pair), plus the usual C set a Python or autotools build |
| 465 | + # reaches for. |
| 466 | + # |
| 467 | + # It reaches a build by two routes, and both are needed: |
| 468 | + # |
| 469 | + # - PKG_CONFIG_PATH (sessionVariables, further down), which is how every |
| 470 | + # -sys crate and most C build systems find a library at all. |
| 471 | + # - The system gcc and clang wrappers (`withDevLibraries` below), for |
| 472 | + # headers, -L, and -- the part that matters -- an rpath. |
| 473 | + # |
| 474 | + # The rpath is the non-obvious half. A binary linked here gets the store |
| 475 | + # glibc as its loader, so nix-ld never sees it, and it finds libraries only |
| 476 | + # through its RUNPATH. Nix's ld wrapper normally writes that for each -L in |
| 477 | + # the store, which is why `cc foo.c $(pkg-config --libs openssl)` has always |
| 478 | + # worked. But rustc (1.95 here) links with its bundled rust-lld, which never |
| 479 | + # goes through the ld wrapper -- `readelf -p .comment` on the output reads |
| 480 | + # "Linker: LLD 22.1.2". So cargo found openssl, linked it, and produced a |
| 481 | + # binary with no RUNPATH that dies on "libssl.so.3: cannot open shared |
| 482 | + # object file", with ldd agreeing. bosn's wheel backend runs ldd to bundle |
| 483 | + # OpenSSL and failed on exactly that. cc-ldflags reach whatever linker the |
| 484 | + # cc wrapper hands off to, rust-lld included. Verified: an openssl-sys + |
| 485 | + # libz-sys + libsqlite3-sys test crate runs with this and exits 127 without. |
| 486 | + # |
| 487 | + # Only the system compilers carry it. A `nix develop` / direnv shell puts |
| 488 | + # its own cc wrapper first on PATH and is untouched. Headers go in with |
| 489 | + # -idirafter, after glibc's and after any -I or -isystem a build passes, so |
| 490 | + # this set fills a gap and never shadows a project's own copy (checked: no |
| 491 | + # header here shares a path with glibc's or gcc's include-fixed). |
| 492 | + # |
| 493 | + # A binary built this way holds a RUNPATH into this environment's store path, |
| 494 | + # so once the list changes and the old generation is garbage-collected it |
| 495 | + # loses its libraries like any Nix-built binary would. Rebuild it. |
| 496 | + # |
| 497 | + # Deliberately NOT done: a global LD_LIBRARY_PATH. It outranks every Nix |
| 498 | + # program's own RUNPATH, so it would feed these exact library versions to |
| 499 | + # apps built from other nixpkgs revisions -- the hermes flake input, the user |
| 500 | + # nix profile -- and GTK is on this list. gcc_multi is not wrapped either; |
| 501 | + # these are 64-bit libraries with no business in a -m32 link. |
| 502 | + devLibraries = with pkgs; [ |
| 503 | + # Crypto, compression and the network stack. |
| 504 | + openssl zlib zstd xz bzip2 lz4 brotli libssh2 curl |
| 505 | + # Version control, databases, parsers. |
| 506 | + libgit2 sqlite libpq libxml2 libxslt libyaml expat pcre2 icu |
| 507 | + # What Python, Ruby and autotools builds want from the C side. |
| 508 | + libffi readline ncurses gmp libuv libevent libunwind elfutils |
| 509 | + # Linux system interfaces. |
| 510 | + util-linux systemdLibs dbus libseccomp libcap alsa-lib libusb1 hidapi |
| 511 | + # Graphics and the Tauri / WebKitGTK stack. The appindicator pair is two |
| 512 | + # entries because ayatana-appindicator3's .pc requires ayatana-indicator3, |
| 513 | + # and pkg-config fails the whole query when a Requires is missing. |
| 514 | + fontconfig freetype harfbuzz libGL libdrm libxkbcommon wayland |
| 515 | + glib gtk3 cairo pango atk gdk-pixbuf webkitgtk_4_1 libsoup_3 |
| 516 | + libayatana-appindicator libayatana-indicator |
| 517 | + # libclang for clang-sys / bindgen; LIBCLANG_PATH points into this. |
| 518 | + libclang |
| 519 | + ]; |
| 520 | + |
| 521 | + devLibraryEnv = pkgs.buildEnv { |
| 522 | + name = "dev-libraries"; |
| 523 | + # Headers and .pc files live in `dev`, the shared objects in `lib` or |
| 524 | + # `out` depending on the package; get* picks whichever exists. Listing |
| 525 | + # the packages bare would miss both -- openssl's default install outputs |
| 526 | + # are `bin` and `man`. |
| 527 | + paths = map lib.getDev devLibraries ++ map lib.getLib devLibraries; |
| 528 | + pathsToLink = [ "/include" "/lib" "/share/pkgconfig" ]; |
| 529 | + }; |
| 530 | + |
| 531 | + withDevLibraries = cc: cc.override (old: { |
| 532 | + extraBuildCommands = (old.extraBuildCommands or "") + '' |
| 533 | + echo "-idirafter ${devLibraryEnv}/include" >> $out/nix-support/cc-cflags |
| 534 | + echo "-L${devLibraryEnv}/lib -rpath ${devLibraryEnv}/lib" >> $out/nix-support/cc-ldflags |
| 535 | + ''; |
| 536 | + }); |
| 537 | + |
457 | 538 | in |
458 | 539 | { |
459 | 540 | # home-manager's NixOS module is added by flake.nix, alongside this file. |
|
773 | 854 | # lowPrio makes gcc the deterministic winner; `clang` and `clang++` are |
774 | 855 | # unique names and are unaffected. |
775 | 856 | # |
776 | | - # These compile self-contained code and nothing else. There is no |
777 | | - # /usr/include on NixOS, so anything that wants zlib, openssl or any other |
778 | | - # library's headers still needs a `shell.nix` / `nix develop` (direnv is |
779 | | - # enabled below) -- the nix-ld library list above puts shared objects on a |
780 | | - # *runtime* search path and deliberately does not reach the compiler. |
781 | | - # pkg-config is here for the same reason and with the same caveat: it |
782 | | - # finds nothing until a dev shell populates PKG_CONFIG_PATH. |
783 | | - gcc |
784 | | - (lib.lowPrio clang) |
| 857 | + # Both carry the development library set (`devLibraryEnv` in the let |
| 858 | + # block): its headers, its libraries and an rpath to them, so openssl, |
| 859 | + # zlib, sqlite and the rest compile, link and RUN without a dev shell, and |
| 860 | + # pkg-config finds them through the PKG_CONFIG_PATH set further down. A |
| 861 | + # `shell.nix` / `nix develop` (direnv is enabled below) still wins inside |
| 862 | + # a project, with its own compiler and its own versions. The nix-ld list |
| 863 | + # above is a different thing: it serves prebuilt foreign binaries at run |
| 864 | + # time and never reaches the compiler. |
| 865 | + (withDevLibraries gcc) |
| 866 | + (lib.lowPrio (withDevLibraries clang)) |
785 | 867 | clang-tools # clangd, clang-format, clang-tidy; not in `clang` |
786 | 868 | binutils # ld, as, ar, nm, objdump, readelf, strings |
787 | 869 | gnumake |
788 | 870 | cmake |
789 | 871 | ninja |
790 | 872 | pkg-config |
| 873 | + # protoc. prost-build -- in 57 Cargo.lock entries under ~/dev -- shells |
| 874 | + # out to it from its build script and fails the build without it. |
| 875 | + protobuf |
791 | 876 | autoconf |
792 | 877 | automake |
793 | 878 | libtool |
|
964 | 1049 | LADSPA_PATH = "${pkgs.ladspaPlugins}/lib/ladspa"; |
965 | 1050 | }; |
966 | 1051 |
|
| 1052 | + # The global half of the development library set; `devLibraryEnv` in the let |
| 1053 | + # block says why it exists and what else it takes. sessionVariables rather |
| 1054 | + # than environment.variables so an editor started from Plasma -- where |
| 1055 | + # rust-analyzer runs build scripts -- gets them too, not only a shell. |
| 1056 | + environment.sessionVariables = { |
| 1057 | + # A dev shell's own pkg-config still wins over this: nixpkgs' pkg-config |
| 1058 | + # wrapper puts the shell's paths first. Verified with openssl_3 in a |
| 1059 | + # nix-shell reporting 3.0.21 while this pointed at 3.6.3. |
| 1060 | + PKG_CONFIG_PATH = "${devLibraryEnv}/lib/pkgconfig:${devLibraryEnv}/share/pkgconfig"; |
| 1061 | + # clang-sys (bindgen's libclang loader) looks here first, then falls back |
| 1062 | + # to `llvm-config`, which is not on PATH -- it lives in llvm's dev output. |
| 1063 | + # Without this its build script fails before compiling anything; verified |
| 1064 | + # with clang-sys 1.9.1. |
| 1065 | + LIBCLANG_PATH = "${devLibraryEnv}/lib"; |
| 1066 | + }; |
| 1067 | + |
967 | 1068 | # fzf: the module installs pkgs.fzf and sources the bash integration, |
968 | 1069 | # giving ctrl+r fuzzy history, ctrl+t file picker and alt+c directory jump. |
969 | 1070 | programs.fzf = { |
|
0 commit comments