summaryrefslogtreecommitdiff
path: root/flake.nix
blob: 1c549c06132754aa45c9f05be7be17e3e8943f53 (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
67
68
69
70
71
72
{
  inputs = {
    flake-utils.url = "github:numtide/flake-utils";
    nixpkgs.url = "github:nix-ocaml/nix-overlays";
  };

  outputs = { self, nixpkgs, flake-utils }:
    flake-utils.lib.eachDefaultSystem (system:
      let
        pkgs = nixpkgs.legacyPackages.${system}.appendOverlays [
          (self: super: {
            ocamlPackages = super.ocaml-ng.ocamlPackages_5_1.overrideScope'
              (oself: osuper: {
                pg_query = osuper.pg_query.overrideAttrs (prev: {
                  propagatedBuildInputs = prev.propagatedBuildInputs
                    ++ [ osuper.cmdliner ];
                });
              });
          })
        ];

        pkgs' = pkgs.pkgsCross.musl64;

        rinha = pkgs'.ocamlPackages.buildDunePackage {
          pname = "rinha";
          version = "0.0.1";
          src = ./.;
          buildInputs = with pkgs'.ocamlPackages; [
            ppx_rapper
            ppx_rapper_eio
            yojson
            eio_main
            piaf
            routes
            caqti-driver-postgresql
            ppx_expect

            logs
          ];
        };

      in {
        devShells.default = pkgs'.mkShell rec {
          nativeBuildInputs = with pkgs'.ocamlPackages; [
            dune_3
            findlib
            ocaml
            ocaml-lsp
            ocamlformat
            pkgs.openjdk17
          ];

          buildInputs = rinha.buildInputs
            ++ (with pkgs'.ocamlPackages; [ utop ]);
        };

        packages.default = rinha;

        packages.docker = pkgs.dockerTools.buildImage {
          name = "rinha";
          tag = "latest";
          copyToRoot = pkgs.buildEnv {
            name = "image-root";
            paths = [ pkgs.bashInteractive pkgs.coreutils pkgs.curl rinha ];
            pathsToLink = [ "/bin" ];
          };
          config = { Cmd = [ "rinha" ]; };
        };

        formatter = pkgs.nixfmt;
      });
}