haskell-foreign-rust/flake.nix
2025-04-16 08:22:17 -05:00

112 lines
3.8 KiB
Nix

{
description = "foreign-rust: a Haskell library to create FFI to Rust";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
flake-parts.url = "github:hercules-ci/flake-parts";
haskell-flake.url = "github:srid/haskell-flake";
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
crane.url = "github:ipetkov/crane";
};
outputs = inputs @ {
self,
nixpkgs,
flake-parts,
...
}:
flake-parts.lib.mkFlake {inherit inputs;} {
systems = nixpkgs.lib.systems.flakeExposed;
imports = [inputs.haskell-flake.flakeModule];
perSystem = {
self',
pkgs,
config,
inputs',
system,
...
}: let
craneLib = (inputs.crane.mkLib pkgs).overrideToolchain (p: p.rust-bin.selectLatestNightlyWith (toolchain: toolchain.default));
rustbits = pkgs: let
cargoCbuild = {
cargoArtifacts,
cargoAwesomeExtraArgs ? "", # Arguments that are generally useful default
cargoExtraArgs ? "", # Other cargo-general flags (e.g. for features or targets)
} @ origArgs: let
# Clean the original arguments for good hygiene (i.e. so the flags specific
# to this helper don't pollute the environment variables of the derivation)
args = builtins.removeAttrs origArgs [
"cargoAwesomeExtraArgs"
"cargoExtraArgs"
];
in
craneLib.mkCargoDerivation (args
// {
inherit cargoArtifacts;
src = cargoArtifacts;
pname = "rustbits";
version = "0.1.0";
pnameSuffix = "-cbuild";
buildPhaseCargoCommand = "cargo cinstall --prefix=$out --libdir=$out/lib --includedir=$out/include --pkgconfigdir=$out/lib/pkgconfig ${cargoAwesomeExtraArgs}";
nativeBuildInputs = (args.nativeBuildInputs or []) ++ [pkgs.cargo-c];
});
in
cargoCbuild {
cargoArtifacts = craneLib.cleanCargoSource ./rustbits/.;
};
in {
_module.args.pkgs = import inputs.nixpkgs {
inherit system;
overlays = [(import inputs.rust-overlay)];
};
haskellProjects.default = {
# The base package set representing a specific GHC version.
# By default, this is pkgs.haskellPackages.
# You may also create your own. See https://community.flake.parts/haskell-flake/package-set
# basePackages = pkgs.haskellPackages;
# Extra package information. See https://community.flake.parts/haskell-flake/dependency
#
# Note that local packages are automatically included in `packages`
# (defined by `defaults.packages` option).
#
# packages = {
# aeson.source = "1.5.0.0"; # Hackage version override
# shower.source = inputs.shower;
# };
packages = {
};
settings = {
rustbits.custom = _: rustbits pkgs;
foreign-rust = {
#check = false;
};
borsh = {
broken = false;
};
};
devShell = {
# # Enabled by default
# enable = true;
#
# # Programs you want to make available in the shell.
# # Default programs can be disabled by setting to 'null'
# tools = hp: { fourmolu = hp.fourmolu; ghcid = null; };
#
# hlsCheck.enable = true;
};
};
# haskell-flake doesn't set the default package, but you can do it here.
packages.default = self'.packages.foreign-rust;
};
};
}