feat: Expose module for setting up the build and test environment.

This commit is contained in:
Robert Hensing 2025-10-27 01:37:18 +01:00
parent 62d4eb37a2
commit 26b7cb2116
4 changed files with 221 additions and 44 deletions

48
nci.nix
View file

@ -11,33 +11,12 @@
nci.projects.nix-bindings = {
path = ./.;
drvConfig = {
imports = [
# Downstream projects import this into depsDrvConfig instead
config.nix-bindings-rust.nciBuildConfig
];
# Extra settings for running the tests
mkDerivation = {
buildInputs = [
# stdbool.h
pkgs.stdenv.cc
]
++ (
if config.packages.nix ? libs then
let
l = config.packages.nix.libs;
in
[
l.nix-expr-c
l.nix-store-c
l.nix-util-c
l.nix-flake-c
]
else
[ config.packages.nix ]
);
nativeBuildInputs = [
pkgs.pkg-config
];
# bindgen uses clang to generate bindings, but it doesn't know where to
# find our stdenv cc's headers, so when it's gcc, we need to tell it.
postConfigure = lib.optionalString pkgs.stdenv.cc.isGNU ''
source ${./bindgen-gcc.sh}
'';
# Prepare the environment for Nix to work.
# Nix does not provide a suitable environment for running itself in
# the sandbox - not by default. We configure it to use a relocated store.
@ -61,26 +40,11 @@
echo "experimental-features = ca-derivations flakes" > "$NIX_CONF_DIR/nix.conf"
# Init ahead of time, because concurrent initialization is flaky
${
# Not using nativeBuildInputs because this should (hopefully) be
# the only place where we need a nix binary. Let's stay in control.
pkgs.buildPackages.nix
}/bin/nix-store --init
${config.nix-bindings-rust.nixPackage}/bin/nix-store --init
echo "Store initialized."
'';
};
# NOTE: duplicated in flake.nix devShell
env = {
LIBCLANG_PATH = lib.makeLibraryPath [ pkgs.buildPackages.llvmPackages.clang-unwrapped ];
BINDGEN_EXTRA_CLANG_ARGS =
# Work around missing [[deprecated]] in clang
"-x c++ -std=c++2a";
}
// lib.optionalAttrs pkgs.stdenv.cc.isGNU {
# Avoid cc wrapper, because we only need to add the compiler/"system" dirs
NIX_CC_UNWRAPPED = "${pkgs.stdenv.cc.cc}/bin/gcc";
};
};
};
};