2024-02-08 16:58:45 +01:00
|
|
|
{
|
2024-02-16 09:14:15 +01:00
|
|
|
perSystem = { lib, config, pkgs, ... }: {
|
2024-02-08 16:58:45 +01:00
|
|
|
# https://flake.parts/options/nix-cargo-integration
|
2024-02-16 09:14:15 +01:00
|
|
|
nci.projects.nix-bindings = {
|
|
|
|
|
path = ./.;
|
|
|
|
|
drvConfig = {
|
|
|
|
|
mkDerivation = {
|
|
|
|
|
buildInputs = [
|
|
|
|
|
# stdbool.h
|
|
|
|
|
pkgs.stdenv.cc
|
2024-12-16 12:51:03 +01:00
|
|
|
] ++
|
|
|
|
|
(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 ]);
|
2024-02-16 09:14:15 +01:00
|
|
|
nativeBuildInputs = [
|
|
|
|
|
pkgs.pkg-config
|
|
|
|
|
];
|
2025-01-08 11:14:09 +01:00
|
|
|
# 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}
|
|
|
|
|
'';
|
2024-03-19 18:01:05 +01:00
|
|
|
# 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.
|
|
|
|
|
preCheck = ''
|
|
|
|
|
# nix needs a home directory
|
|
|
|
|
export HOME="$(mktemp -d $TMPDIR/home.XXXXXX)"
|
|
|
|
|
|
|
|
|
|
# configure a relocated store
|
|
|
|
|
store_data=$(mktemp -d $TMPDIR/store-data.XXXXXX)
|
|
|
|
|
export NIX_REMOTE="$store_data"
|
|
|
|
|
export NIX_BUILD_HOOK=
|
|
|
|
|
export NIX_CONF_DIR=$store_data/etc
|
|
|
|
|
export NIX_LOCALSTATE_DIR=$store_data/nix/var
|
|
|
|
|
export NIX_LOG_DIR=$store_data/nix/var/log/nix
|
|
|
|
|
export NIX_STATE_DIR=$store_data/nix/var/nix
|
|
|
|
|
|
|
|
|
|
echo "Configuring relocated store at $NIX_REMOTE..."
|
|
|
|
|
|
|
|
|
|
# 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
|
|
|
|
|
|
|
|
|
|
echo "Store initialized."
|
|
|
|
|
'';
|
2024-02-16 09:14:15 +01:00
|
|
|
};
|
|
|
|
|
# NOTE: duplicated in flake.nix devShell
|
|
|
|
|
env = {
|
|
|
|
|
LIBCLANG_PATH =
|
2025-01-02 07:53:55 +01:00
|
|
|
lib.makeLibraryPath [ pkgs.buildPackages.llvmPackages.clang-unwrapped ];
|
|
|
|
|
BINDGEN_EXTRA_CLANG_ARGS =
|
|
|
|
|
# Work around missing [[deprecated]] in clang
|
|
|
|
|
"-x c++ -std=c++2a";
|
2025-01-08 11:14:09 +01:00
|
|
|
} // 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";
|
2024-02-16 09:14:15 +01:00
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
};
|
2024-02-08 16:58:45 +01:00
|
|
|
};
|
|
|
|
|
}
|