|
3 | 3 |
|
4 | 4 | inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05"; |
5 | 5 |
|
6 | | - outputs = { self, nixpkgs }: |
7 | | - let |
8 | | - systems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ]; |
9 | | - forEachSystem = nixpkgs.lib.genAttrs systems; |
| 6 | + outputs = { |
| 7 | + self, |
| 8 | + nixpkgs, |
| 9 | + }: let |
| 10 | + systems = ["x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin"]; |
| 11 | + forEachSystem = nixpkgs.lib.genAttrs systems; |
| 12 | + in { |
| 13 | + devShells = forEachSystem (system: let |
| 14 | + pkgs = import nixpkgs {inherit system;}; |
10 | 15 | in { |
11 | | - devShells = forEachSystem (system: |
12 | | - let pkgs = import nixpkgs { inherit system; }; |
13 | | - in { |
14 | | - default = pkgs.mkShell { |
15 | | - packages = with pkgs; [ |
16 | | - ruby |
17 | | - |
18 | | - # The native extension is implemented in Rust |
19 | | - rustc |
20 | | - cargo |
21 | | - libiconv # required as a dependency when building the rb-sys Rust crate |
22 | | - |
23 | | - # For build automation |
24 | | - just |
25 | | - git-lfs |
26 | | - ]; |
27 | | - }; |
28 | | - }); |
29 | | - }; |
| 16 | + default = pkgs.mkShell { |
| 17 | + packages = with pkgs; [ |
| 18 | + ruby |
| 19 | + |
| 20 | + # The native extension is implemented in Rust |
| 21 | + rustc |
| 22 | + cargo |
| 23 | + libiconv # Required dependency when building the rb-sys Rust crate on macOS and some Linux systems |
| 24 | + |
| 25 | + # Required for bindgen (used by rb-sys crate for generating Ruby C API bindings) |
| 26 | + # Without these, build fails with "Unable to find libclang" error |
| 27 | + libclang # Provides libclang library that bindgen requires |
| 28 | + llvmPackages.clang # Clang compiler used by bindgen for parsing C headers |
| 29 | + pkg-config # Used by build scripts to find library paths |
| 30 | + |
| 31 | + # C standard library headers required for Ruby C extension compilation |
| 32 | + # Without this, build fails with "stdarg.h file not found" error |
| 33 | + glibc.dev |
| 34 | + |
| 35 | + # For build automation |
| 36 | + just |
| 37 | + git-lfs |
| 38 | + ]; |
| 39 | + |
| 40 | + # Environment variables required to fix NixOS-specific build issues with rb-sys/bindgen |
| 41 | + |
| 42 | + # LIBCLANG_PATH: Required by bindgen to locate libclang shared library |
| 43 | + # Without this, bindgen fails with "couldn't find any valid shared libraries" error |
| 44 | + LIBCLANG_PATH = "${pkgs.libclang.lib}/lib"; |
| 45 | + |
| 46 | + # BINDGEN_EXTRA_CLANG_ARGS: Additional clang arguments for bindgen when parsing Ruby headers |
| 47 | + # Includes system header paths that are not automatically discovered in NixOS |
| 48 | + # --sysroot ensures clang can find standard C library headers like stdarg.h |
| 49 | + BINDGEN_EXTRA_CLANG_ARGS = with pkgs; |
| 50 | + builtins.concatStringsSep " " [ |
| 51 | + "-I${libclang.lib}/lib/clang/${libclang.version}/include" # Clang builtin headers |
| 52 | + "-I${glibc.dev}/include" # System C headers |
| 53 | + "--sysroot=${glibc.dev}" # System root for header resolution |
| 54 | + ]; |
| 55 | + |
| 56 | + # Compiler environment variables to ensure consistent toolchain usage |
| 57 | + # These help rb-sys and other build scripts use the correct clang installation |
| 58 | + CLANG_PATH = "${pkgs.llvmPackages.clang}/bin/clang"; |
| 59 | + CC = "${pkgs.llvmPackages.clang}/bin/clang"; |
| 60 | + CXX = "${pkgs.llvmPackages.clang}/bin/clang++"; |
| 61 | + }; |
| 62 | + }); |
| 63 | + }; |
30 | 64 | } |
0 commit comments