garnet/flake.nix
George Thomas d3cee99e92 stuff from Yuri
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 isn't very important but seems fine anyway
the rest is just re-inlining things and other refactors

final question:
it does seems a bit weird that `garnet-rs` arg to `project.nix` was always the same
might be a mistake, and we're supposed to be using local for local build?

"improve nix-haskell use"

there are a few things going on here but the main ones are ...
note that changes we keep are essentially:
- 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

should add co-author attribution
2026-04-14 01:45:35 +01:00

59 lines
2.1 KiB
Nix

{
inputs = {
nix-haskell.url = "github:reflex-frp/nix-haskell";
nixpkgs.follows = "nix-haskell/nixpkgs";
hls-src = { url = "github:haskell/haskell-language-server/2.13.0.0"; flake = false; };
hs-bindgen-src = { url = "github:well-typed/hs-bindgen/6ca94188abd756a1fb4dd8a4037de3fa7dca0765"; flake = false; };
libclang-src = { url = "github:well-typed/libclang/d6e482df49b88375cf3075928a78ee86c2a068d4"; flake = false; };
flake-utils.url = "github:numtide/flake-utils";
crane.url = "github:ipetkov/crane";
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs =
inputs@{ nix-haskell, ... }:
inputs.flake-utils.lib.eachSystem [ "x86_64-linux" ] (system:
let
pkgs = haskell.nixpkgs.extend (import inputs.rust-overlay);
nix-haskell = import inputs.nix-haskell { inherit system inputs; };
crane = (inputs.crane.mkLib pkgs).overrideToolchain (p: p.rust-bin.selectLatestNightlyWith (
toolchain: toolchain.default.override {
extensions = [ "rust-src" ];
targets = [ "x86_64-unknown-linux-gnu" ];
}
));
haskell =
nix-haskell (import ./project.nix { inherit (inputs) hls-src hs-bindgen-src libclang-src; inherit garnet-rs; });
garnet-rs = crane.buildPackage {
src = crane.cleanCargoSource ./rust;
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/
'';
};
in
rec {
defaultPackage = packages.garnet-exe;
packages = let garnet = haskell.project.haskell-nix.hsPkgs.garnet; in {
inherit garnet-rs;
garnet-exe = garnet.components.exes.garnet;
garnet-lib = garnet.components.library;
};
devShells.default = pkgs.mkShell {
inputsFrom = [
haskell.project.haskell-nix.shell
(crane.devShell { })
];
packages = with pkgs; [
bacon
ghcid
rust-analyzer
];
};
});
}