ReScirpt PPX development with Devbox

I’m trying to replace Nix shell with Devbox, but with a custom flake for OCaml packages, dune picks up wrong ppxlib.

So, this is shell.nix that works fine:

with import <nixpkgs> {};
with pkgs.ocaml-ng.ocamlPackages_4_12;

let
  ppxlib-rescript = ppxlib.overrideAttrs (_: {
    version = "git";
    src = fetchFromGitHub {
      owner = "zth";
      repo = "ppxlib";
      rev = "32f83395fb89693a873541298b6367449f23bc4a";
      sha256 = "sha256-8bkmeFh5Unda8n3F2MQWi81QPt2NdkwFcy4wZTJ0STo=";
    };
    patches = [];
  });
in

mkShell {
  buildInputs = [
    ocaml
    dune_2
    findlib
    ppxlib-rescript
    merlin
    ocaml-lsp
    nodejs
    yarn
  ];
}

But this flake.nix + devbox.json combo doesn’t.

flake.nix:

{
    description = "OCaml 4.12 packages for ReScript PPX development";

    inputs = {
        nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
        flake-utils.url = "github:numtide/flake-utils";
    };

    outputs = { self, nixpkgs, flake-utils }:
        flake-utils.lib.eachDefaultSystem (system:
            let
                pkgs = nixpkgs.legacyPackages.${system};
                ocamlPackages = pkgs.ocaml-ng.ocamlPackages_4_12;

                ppxlib-rescript = ocamlPackages.ppxlib.overrideAttrs (_: {
                    version = "git";
                    src = pkgs.fetchFromGitHub {
                        owner = "zth";
                        repo = "ppxlib";
                        rev = "32f83395fb89693a873541298b6367449f23bc4a";
                        sha256 = "sha256-8bkmeFh5Unda8n3F2MQWi81QPt2NdkwFcy4wZTJ0STo=";
                    };
                    patches = [];
                });
            in
            {
                packages = {
                    ocaml = ocamlPackages.ocaml;
                    dune = ocamlPackages.dune_2;
                    findlib = ocamlPackages.findlib;
                    ppxlib = ppxlib-rescript;
                    merlin = ocamlPackages.merlin;
                    lsp = ocamlPackages.ocaml-lsp;
                };
            }
        );
}

devbox.json:

{
    "packages": [
        "path:./nix/ocaml#ocaml",
        "path:./nix/ocaml#dune",
        "path:./nix/ocaml#findlib",
        "path:./nix/ocaml#ppxlib",
        "path:./nix/ocaml#merlin",
        "path:./nix/ocaml#lsp",
        "nodejs",
        "yarn"
    ]
}
> ocamlfind query ppxlib

# nix shell
/nix/store/a87zc0bv3q4ai9jjkpgcgyimkqx9ys1f-ocaml4.12.1-ppxlib-0.28.0/lib/ocaml/4.12.1/site-lib/ppxlib

# devbox shell
/nix/store/0kbrgncs1486kc7g4q1zq3phsi8c2ij0-ocaml4.12.1-ppxlib-0.30.0/lib/ocaml/4.12.1/site-lib/ppxlib`

Using overlay doesn’t work either:

{
    description = "OCaml 4.12 packages for ReScript PPX development";

    inputs = {
        nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
        flake-utils.url = "github:numtide/flake-utils";
    };

    outputs = { self, nixpkgs, flake-utils }:
        flake-utils.lib.eachDefaultSystem (system:
            let
                overlay = (final: prev: {
                    ocaml-ng = prev.ocaml-ng // {
                        ocamlPackages_4_12 = prev.ocaml-ng.ocamlPackages_4_12 // {
                            ppxlib = prev.ocaml-ng.ocamlPackages_4_12.ppxlib.overrideAttrs (_: {
                                version = "git";
                                src = pkgs.fetchFromGitHub {
                                    owner = "zth";
                                    repo = "ppxlib";
                                    rev = "32f83395fb89693a873541298b6367449f23bc4a";
                                    sha256 = "sha256-8bkmeFh5Unda8n3F2MQWi81QPt2NdkwFcy4wZTJ0STo=";
                                };
                                patches = [];
                            });
                        };
                    };
                });

                pkgs = import nixpkgs {
                    inherit system;
                    overlays = [ overlay ];
                };

                ocamlPackages = pkgs.ocaml-ng.ocamlPackages_4_12;
            in
            {
                packages = {
                    ocaml = ocamlPackages.ocaml;
                    dune = ocamlPackages.dune_2;
                    findlib = ocamlPackages.findlib;
                    ppxlib = ocamlPackages.ppxlib;
                    merlin = ocamlPackages.merlin;
                    lsp = ocamlPackages.ocaml-lsp;
                };
            }
        );
}

I fixed it by simply switching to dune_3, but ocamlfind still picks up ppxlib-0.30, but everything builds. Tested on two PPXes. So probably I don’t care.

1 Like

Actually, it picks up correct ppxlib as without overlay it doesn’t build. I have no idea where this diff between nix shell and devbox shell comes from, but at this point I 100% don’t care.

1 Like