culr/flake.nix
2025-02-08 11:01:09 +11:00

141 lines
3.4 KiB
Nix

{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
flake-utils.url = "github:numtide/flake-utils";
};
nixConfig = {
extra-substituters = "https://anmonteiro.nix-cache.workers.dev";
extra-trusted-public-keys = "ocaml.nix-cache.com-1:/xI2h2+56rwFfKyyFVbkJSeGqSIYMC/Je+7XXqGKDIY=";
};
outputs =
{
self,
nixpkgs,
flake-utils,
}:
let
version = builtins.toString self.lastModified;
in
flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = import nixpkgs {
inherit system;
};
inherit (pkgs) mkShell ocamlPackages;
inherit (ocamlPackages)
dune_3
ocaml
utop
ocaml-lsp
ocamlformat
ocamlformat-rpc-lib
angstrom
angstrom-unix
ppx_inline_test
;
minimal = [
dune_3
ocaml
angstrom
angstrom-unix
ppx_inline_test
];
dev = [
utop
ocaml-lsp
ocamlformat
ocamlformat-rpc-lib
pkgs.just
];
in
{
devShells.default = mkShell {
buildInputs = minimal ++ dev;
shellHook =
let
justFile = ''
default:
@just --list
@build:
nix build .#debug --offline
@release:
nix build --offline
@test:
printf "\\n\\n\\t************ running nix+dune tests ************\\n\\n\\n"
nix flake check --offline
nix build .#tests --offline
printf "\\n\\n\\t************ running visual test ************\\n\\n\\n"
echo one two three four | CULRS="(255,0,0);(0,0,255);#00FF00" CULR_ORDER="1;0;2" result/bin/culr
@push:
git commit -a
git push
'';
in
''
printf '${justFile}' > justfile
'';
};
checks.default = pkgs.callPackage ./nix/test.nix {
culr = self.packages.${system}.tests;
inherit version;
};
packages.default = pkgs.callPackage ./nix/default.nix {
ocaml-deps = minimal;
inherit version;
};
packages.debug = pkgs.callPackage ./nix/default.nix {
debug = true;
ocaml-deps = minimal;
inherit version;
};
packages.tests = pkgs.callPackage ./nix/default.nix {
debug = true;
ocaml-deps = minimal;
doCheck = true;
inherit version;
};
}
)
// {
nixosModules.culr = import ./nix/module.nix { overlays = [ self.overlays.culr ]; };
overlays.culr =
final: prev:
let
ocaml-deps =
let
inherit (prev.ocamlPackages)
dune_3
ocaml
angstrom
angstrom-unix
ppx_inline_test
;
in
[
dune_3
ocaml
angstrom
angstrom-unix
ppx_inline_test
];
in
{
culr = final.callPackage ./nix/default.nix {
inherit ocaml-deps version;
};
};
};
}