garnet/rust/flake.nix
yuri.meister d9921b3bcf Build Rust crate with Nix via crane sub-flake
Move Rust build into its own flake at rust/flake.nix using crane, and
reference it as an input from the top-level flake. The Haskell build
gets the Rust artifacts (header + static lib) via a haskell.nix
override that symlinks them into place before configure.

Use Cabal's Cgarnet_rs naming convention for extra-bundled-libraries
to satisfy the shared library install phase naming requirements.

Also extract inputs.nix, default.nix, and shell.nix for flake-compat
(nix-build / nix-shell) support.
2026-03-25 16:29:32 +09:00

38 lines
1.2 KiB
Nix

{
inputs = {
nix-haskell.url = "github:reflex-frp/nix-haskell";
nixpkgs.follows = "nix-haskell/nixpkgs";
flake-utils.url = "github:numtide/flake-utils";
crane.url = "github:ipetkov/crane";
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nix-haskell/nixpkgs";
};
};
outputs = inputs@{ self, nixpkgs, ... }:
inputs.flake-utils.lib.eachSystem [ "x86_64-linux" ] (system:
let pkgs = (import nixpkgs { inherit system; }).extend (import inputs.rust-overlay);
craneLib = (inputs.crane.mkLib pkgs).overrideToolchain (p: p.rust-bin.selectLatestNightlyWith (
toolchain: toolchain.default.override {
extensions = [ "rust-src" ];
targets = [ "x86_64-unknown-linux-gnu" ];
}
));
in {
packages.default = craneLib.buildPackage {
src = craneLib.cleanCargoSource ./.;
doCheck = false;
installPhaseCommand = ''
mkdir -p $out/lib $out/include
cp target/release/libgarnet_rs.a $out/lib/libCgarnet_rs.a
cp target/release/garnet_rs.h $out/include/
'';
};
devShells.default = craneLib.devShell { };
}
);
}