aboutsummaryrefslogtreecommitdiff
path: root/flake.nix
blob: 94ecf7b2d82024e4290d7937cb21e7afe4502bcb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs";
    opam-nix.url = "github:tweag/opam-nix";
    opam-repository = {
      url = "github:ocaml/opam-repository";
      flake = false;
    };
    opam-nix.inputs.opam-repository.follows = "opam-repository";
    opam-nix.inputs.nixpkgs.follows = "nixpkgs";
  };

  outputs = { self, nixpkgs, opam-nix, flake-utils, ... }:
    flake-utils.lib.eachDefaultSystem (system:
      let
        system = "x86_64-linux";
        pkgs = nixpkgs.legacyPackages.${system};
        inherit (opam-nix.lib.${system})
          buildOpamProject
          materializedDefsToScope
          materializeOpamProject';
        package = "wormhole";
        devPackagesQuery = {
          ocaml-lsp-server = "*";
          ocamlformat = "*";
          # 1.9.6 fails to build
          ocamlfind = "1.9.5";
          utop = "*";
        };
        query = {
          ocaml-base-compiler = "*";
        };
        overlay = final: prev: {
          "${package}" = prev.${package}.overrideAttrs (_: {
            # override derivation attributes, e.g. add additional dependacies
            buildInputs = [ 
              pkgs."gmp"
              pkgs."libev"
              pkgs."openssl"
            ];
          });
        };
        devBuildInputs = [ pkgs.ocamlPackages.ocamlformat ];
        resolved-scope =
          let scope = buildOpamProject { } package ./. query;
          in scope.overrideScope' overlay;
        materialized-scope =
          let scope = materializedDefsToScope
            { sourceMap.${package} = ./.; } ./package-defs.json;
          in scope.overrideScope' overlay;
      in rec {
        packages = {
          resolved = resolved-scope;
          materialized = materialized-scope;
          # to generate:
          #   cat $(nix eval .#package-defs --raw) > package-defs.json
          package-defs = materializeOpamProject' { } ./. query;
        };
        defaultPackage = packages.materialized.${package};
        devShells.default = pkgs.mkShell {
          inputsFrom = [ defaultPackage ];
          buildInputs = devBuildInputs;
        };
      }
    );
}