garnet/project.nix
George Thomas b5fd53b5ec stuff from Yuri (maybe squash?)...
things I've changed from the PR:
- dropped legacy (i.e. non-flake) compat stuff, which turns out to account for most of the diff
- dropped `packages.garnet` since it doesn't work with `nix build .#garnet`
- back to using Rust-extended packages everywhere, which _seems_ fine
the rest is just re-inlining things and other refactors

note that changes we keep are essentially:
- not using Crane's extended packages everywhere
- bumping `nix-haskell` to avoid shell hook workaround
- various changes in how we call `nix-haskell`
- using `libCgarnet_rs` name, which Cabal expects
- adding proper non-dev-shell targets, so that e.g. `nix run` works

stuff we should still take a look at:
- seems a bit weird that `garnet-rs` arg to `project.nix` was always same (and therefore now we always pass the ) - might be a mistake, and we're supposed to be using local for local build?
- similar `libCgarnet_rs.a` logic appears in three places - see if we can deduplicate to some extent somehow
- I haven't even checked all steps are necessary
2026-03-30 12:08:05 +01:00

55 lines
1.7 KiB
Nix

{ hls-src
, hs-bindgen-src
, libclang-src
, garnet-rs
}:
{
name = "garnet";
src = ./.;
compiler-nix-name = "ghc914";
source-repository-packages = {
# not on Hackage yet: https://well-typed.com/blog/2026/02/hs-bindgen-alpha
# we're using more recent versions than in that post, because we want record-dot support:
# https://github.com/well-typed/hs-bindgen/issues/1829#issuecomment-4081875451
c-expr-dsl = hs-bindgen-src + "/c-expr-dsl";
c-expr-runtime = hs-bindgen-src + "/c-expr-runtime";
hs-bindgen = hs-bindgen-src + "/hs-bindgen";
hs-bindgen-runtime = hs-bindgen-src + "/hs-bindgen-runtime";
libclang-bindings = libclang-src;
};
overrides = [
({ pkgs, ... }: {
packages.libclang-bindings.components.library = {
build-tools = [ pkgs.llvmPackages.llvm ];
libs = [ pkgs.llvmPackages.libclang ];
};
})
(_: {
packages.garnet.components.library = {
preConfigure = ''
mkdir -p rust/target/debug
ln -s ${garnet-rs}/include/garnet_rs.h rust/target/debug/garnet_rs.h
ln -s ${garnet-rs}/lib/libCgarnet_rs.a rust/target/debug/libCgarnet_rs.a
'';
preInstall = ''
cp ${garnet-rs}/lib/libCgarnet_rs.a dist/build/libCgarnet_rs.a
'';
configureFlags = [ "--extra-lib-dirs=${garnet-rs}/lib" ];
};
})
];
shell = {
tools = {
cabal = "latest";
haskell-language-server = {
src = hls-src;
sha256map = {
"https://github.com/snowleopard/alga"."d4e43fb42db05413459fb2df493361d5a666588a" = "0s1mlnl64wj7pkg3iipv5bb4syy3bhxwqzqv93zqlvkyfn64015i";
};
};
};
withHoogle = false;
withHaddock = true;
};
}