dune icon indicating copy to clipboard operation
dune copied to clipboard

pkg: Add CLI command to update the config to enable package management

Open shonfeder opened this issue 1 month ago • 3 comments

Motivation

We have had feedback from multiple users who found it confusing to enable dune package management for unlocked use. Most users (even experienced ones) are not used to configuring dune-workspace files, and despite clear instructions such as

To tell Dune to manage packages, you only need to configure a dune-workspace file with (pkg enabled). Then, in that workspace, Dune will manage the dependencies declared in dune-project.

# Alternatively update an existing `dune-workspace` file
$ cat > dune-workspace <<EOF
(lang dune 3.21)
(pkg enabled)
EOF
$ dune build

people are still putting the stanza in their dune-project files, and ending up confused when it doesn't work.

Since it seems likely that we will end up requiring updates to the dune-workspace anytime someone wants to lock on a new system (as per https://github.com/ocaml/dune/issues/11868) finding ways to reduce the cognitive load on users seems desirable.

Proposal

Adding a CLI that takes care of the configuration detals could reduce the cognitive load. This kind of command is not used in dune currently (afaik), but it is quite common in other package manages. E.g.,

One possible interface for this is

dune pkg (--enable|--disable)

meaning

enable (resp. disable) dune package management in the default context, by making the needed updates to persistent configuration files.

Looking forward to alleviating the load from adding supported systems for locks, we could expect a CLI like

dune pkg lock --add-system

meaning

add the host systems to the list of systems supported by the lock directory by making the needed updates to persistent configuration files, and and relock

Considerations

IMO, it would be ideal to not need this kind of added complexity in the CLI. However, without revisions to offer a simpler configuration API for common cases, I think providing users with simple commands to manage the overhead of dune's configuration demands may be the best way to help users.

I would be interested to consider alternative approaches that can meet the stated need.

Related

This is related to #12819 in that both are aimed at proving users with simpler interface for managing package management functionality. However, #12819 only applies to running the invocation of single commands, whereas this feature is for managing persistent configuration.

shonfeder avatar Nov 30 '25 03:11 shonfeder

We had a similar situation for dune cache for a while. There we encouraged people to put it in their config with the ability to opt out in the cli.

For pkg something similar would work. Enabling pkg in the config would use package management for all contexts by default, only when explicitly specified to use an opam switch or disabled via a new --pkg enabled/disabled would we have the current default behaviour with pkg in the config.

Alizter avatar Nov 30 '25 07:11 Alizter

However pkg still requires some deliberate configuration, such as opam repos.

Alizter avatar Nov 30 '25 07:11 Alizter

I think this is a great idea to have our cake and eat it to. Users can use commands to set things up (and we can make sure the commands set up the configuration in the right way), while the configuration ends in the config files from which it is both easy for users to see what was done as well as easy for Dune to pick up the configuration.

I don't think enabling package management requires deliberate configuration in the common case (just as OPAM has comes with its default Dune does too) and that's the case I would expect a lot of people to have, where they're ok just using opam-repository and getting the newest packages.

The main issue I see is that we currently lack a good programmatic way of editing dune configurations. As far as I know we don't have a way to read a dune-workspace file, edit it and write it out without it being mangled (stripped comments, different formatting). Maybe it's ok to reformat in such cases, but we need to make sure to preserve comments.

Leonidas-from-XIV avatar Dec 03 '25 15:12 Leonidas-from-XIV