Is opam using the dune cache when building packages?

I can’t seem to figure this out. I have enabled the dune cache in ~/.cache/dune. This directory grows in size when I do dune build, so it seems to be working. However, if I nuke the cache and install some package (which builds through dune), then the cache is not populated. Does this make sense? I couldn’t find a straight answer when searching on whether opam builds should profit from the dune cache or not. I’m using opam version 2.2.0, dune version 3.16.0.

At first I thought that maybe it doesn’t work because the dune cache is outside of the sandbox that opam uses for building but if I take a look at ~/.opam/opam-init/hooks/sandbox.sh there is specific support for the dune cache (in rw mode, so it should be able to populate it), and it is called when building so this seems all correct.

Maybe check whether this is the same for you as well?

I haven’t messed with the default settings when setting up the switch, and my sandbox script also mentions dune cache. Do you see the dune cache being used / populated when you do opam stuff? I’ll try to disable sandboxing altogether…

Hmm, if I do opam init --disable-sandboxing then the dune cache is populated when I install packages. So then it would seem that whatever exceptions are being made for the dune cache in sandbox.sh are not working on my machine. A bug in opam?

Could it be that you have enabled the cache in your dune config file but that file is not being mounted into the sandbox; thus the sandboxed dune doesn’t see that it should be enabled?

Maybe setting DUNE_CACHE=enabled would solve it? Or ro-mounting the config file into the sandbox.

1 Like