diff --git a/flake.lock b/flake.lock index fd80b32..049d278 100644 --- a/flake.lock +++ b/flake.lock @@ -41,6 +41,22 @@ } }, "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1673956053, + "narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-compat_2": { "flake": false, "locked": { "lastModified": 1696426674, @@ -115,6 +131,22 @@ "type": "github" } }, + "libgit2": { + "flake": false, + "locked": { + "lastModified": 1697646580, + "narHash": "sha256-oX4Z3S9WtJlwvj0uH9HlYcWv+x1hqp8mhXl7HsLu2f0=", + "owner": "libgit2", + "repo": "libgit2", + "rev": "45fd9ed7ae1a9b74b957ef4f337bc3c8b3df01b5", + "type": "github" + }, + "original": { + "owner": "libgit2", + "repo": "libgit2", + "type": "github" + } + }, "mk-naked-shell": { "flake": false, "locked": { @@ -131,6 +163,30 @@ "type": "github" } }, + "nix": { + "inputs": { + "flake-compat": "flake-compat", + "libgit2": "libgit2", + "nixpkgs": [ + "nixpkgs" + ], + "nixpkgs-regression": "nixpkgs-regression" + }, + "locked": { + "lastModified": 1705358697, + "narHash": "sha256-1SjVVJKIXfSoymtIBCx8mPkhw6LpyihrtzMXdFFOH2M=", + "owner": "tweag", + "repo": "nix", + "rev": "eb456d68bd22e1296c2eca30fa06281de0da289e", + "type": "github" + }, + "original": { + "owner": "tweag", + "ref": "nix-c-bindings", + "repo": "nix", + "type": "github" + } + }, "nix-cargo-integration": { "inputs": { "crane": "crane", @@ -173,6 +229,22 @@ "type": "github" } }, + "nixpkgs-regression": { + "locked": { + "lastModified": 1643052045, + "narHash": "sha256-uGJ0VXIhWKGXxkeNnq4TvV3CIOkUJ3PAoLZ3HMzNVMw=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "215d4d0fd80ca5163643b03a33fde804a29cc1e2", + "type": "github" + }, + "original": { + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "215d4d0fd80ca5163643b03a33fde804a29cc1e2", + "type": "github" + } + }, "nixpkgs-stable": { "locked": { "lastModified": 1704874635, @@ -212,7 +284,7 @@ }, "pre-commit-hooks-nix": { "inputs": { - "flake-compat": "flake-compat", + "flake-compat": "flake-compat_2", "flake-utils": "flake-utils", "gitignore": "gitignore", "nixpkgs": [ @@ -277,6 +349,7 @@ "root": { "inputs": { "flake-parts": "flake-parts", + "nix": "nix", "nix-cargo-integration": "nix-cargo-integration", "nixpkgs": "nixpkgs", "pre-commit-hooks-nix": "pre-commit-hooks-nix" diff --git a/flake.nix b/flake.nix index 6268571..b833505 100644 --- a/flake.nix +++ b/flake.nix @@ -4,6 +4,8 @@ inputs = { flake-parts.url = "github:hercules-ci/flake-parts"; flake-parts.inputs.nixpkgs-lib.follows = "nixpkgs"; + nix.url = "github:tweag/nix/nix-c-bindings"; + nix.inputs.nixpkgs.follows = "nixpkgs"; nix-cargo-integration.url = "github:yusdacra/nix-cargo-integration"; nix-cargo-integration.inputs.nixpkgs.follows = "nixpkgs"; nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; @@ -23,22 +25,42 @@ systems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ]; perSystem = { config, self', inputs', pkgs, ... }: { + + packages.nix = inputs'.nix.packages.nix.overrideAttrs { + # checkPhase does not seem to terminate. + # TODO: remove override + doCheck = false; + }; + pre-commit.settings.hooks.nixpkgs-fmt.enable = true; pre-commit.settings.hooks.rustfmt.enable = true; # Override to pass `--all` pre-commit.settings.hooks.rustfmt.entry = lib.mkForce "${pkgs.rustfmt}/bin/cargo-fmt fmt --all --manifest-path ./rust/Cargo.toml -- --color always"; devShells.default = pkgs.mkShell { + name = "nix-bindings-devshell"; + strictDeps = true; inputsFrom = [ config.nci.outputs.nix-bindings.devShell ]; + inherit (config.nci.outputs.nix-bindings.devShell.env) + LIBCLANG_PATH + BINDGEN_EXTRA_CLANG_ARGS + ; + buildInputs = [ + config.packages.nix + ]; nativeBuildInputs = [ pkgs.rust-analyzer pkgs.nixpkgs-fmt pkgs.rustfmt + pkgs.pkg-config + pkgs.clang-tools # clangd ]; shellHook = '' ${config.pre-commit.installationScript} echo 1>&2 "Welcome to the development shell!" ''; + # rust-analyzer needs a NIX_PATH for some reason + NIX_PATH = "nixpkgs=${inputs.nixpkgs}"; }; }; flake = { }; diff --git a/rust/nci.nix b/rust/nci.nix index 1fbaa3a..bbdd766 100644 --- a/rust/nci.nix +++ b/rust/nci.nix @@ -1,6 +1,33 @@ { - perSystem = { pkgs, config, ... }: { + perSystem = { lib, config, pkgs, ... }: { # https://flake.parts/options/nix-cargo-integration - nci.projects.nix-bindings.path = ./.; + nci.projects.nix-bindings = { + path = ./.; + drvConfig = { + mkDerivation = { + buildInputs = [ + config.packages.nix + # stdbool.h + pkgs.stdenv.cc + ]; + nativeBuildInputs = [ + pkgs.pkg-config + ]; + }; + # NOTE: duplicated in flake.nix devShell + env = { + LIBCLANG_PATH = + if pkgs.stdenv.cc.isClang then + null # don't set the variable + else + lib.makeLibraryPath [ pkgs.buildPackages.llvmPackages.clang-unwrapped ]; + BINDGEN_EXTRA_CLANG_ARGS = + if pkgs.stdenv.cc.isClang then + null # don't set the variable + else + "-I${lib.getDev pkgs.stdenv.cc.cc}/lib/gcc/${pkgs.stdenv.hostPlatform.config}/${pkgs.stdenv.cc.cc.version}/include"; + }; + }; + }; }; }