Shells in OCaml
1# Mostly copied from RyanGibb/eon
2{
3 inputs = {
4 nixpkgs.url = "github:nixos/nixpkgs";
5 opam-nix.url = "github:tweag/opam-nix";
6 flake-utils.url = "github:numtide/flake-utils";
7 opam-nix.inputs.nixpkgs.follows = "nixpkgs";
8 opam-nix.inputs.flake-utils.follows = "flake-utils";
9 # maintain a different opam-repository to those pinned upstream
10 opam-repository = {
11 url = "github:ocaml/opam-repository/340ee6fd1ff10d0fce25e21ba1caca9ed1cfec68";
12 flake = false;
13 };
14 opam-nix.inputs.opam-repository.follows = "opam-repository";
15 };
16 outputs = { self, nixpkgs, flake-utils, opam-nix, ... }@inputs:
17 # create outputs for each default system
18 flake-utils.lib.eachDefaultSystem (system:
19 let
20 package = "merry";
21 pkgs = nixpkgs.legacyPackages.${system};
22 opam-nix-lib = opam-nix.lib.${system};
23 devPackagesQuery = {
24 ocaml-lsp-server = "*";
25 ocamlformat = "*";
26 utop = "*";
27 };
28 query = {
29 ocaml-base-compiler = "*";
30 };
31 overlay = final: prev: {
32 "${package}" = prev.${package}.overrideAttrs (o: {
33 passthru = o.passthru // {
34 shellPath = "/bin/msh";
35 };
36 });
37 };
38 scope =
39 # recursive finds vendored dependancies in duniverse
40 (opam-nix-lib.buildOpamProject' { recursive = true; } ./. (query // devPackagesQuery)).overrideScope
41 overlay;
42 in {
43 packages.default = scope.${package};
44 defaultPackage = scope.${package};
45
46 devShells.default = let
47 devPackages = builtins.attrValues
48 (pkgs.lib.getAttrs (builtins.attrNames devPackagesQuery) scope);
49 in pkgs.mkShell {
50 inputsFrom = [ scope.${package} ];
51 buildInputs = devPackages;
52 };
53 }) // {
54 nixosModules = {
55 default.imports = [ (import ./module.nix self.packages) ];
56 };
57
58 formatter = nixpkgs.lib.genAttrs nixpkgs.lib.systems.flakeExposed
59 (system: nixpkgs.legacyPackages.${system}.nixfmt);
60 };
61}