Skip to content

Add cli option to turn on/off package management - #13458

Merged
ElectreAAS merged 1 commit into
ocaml:mainfrom
ElectreAAS:push-xksznwmmqnkm
Jan 30, 2026
Merged

ElectreAAS merged 1 commit into
ocaml:mainfrom
ElectreAAS:push-xksznwmmqnkm

Conversation

@ElectreAAS

@ElectreAAS ElectreAAS commented Jan 26, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #12819, see the motivation section of the issue.

Added

I added a --pkg option in the common section, taking either enabled or disabled as arguments. It does what it says, the behaviour is shared with the pkg field in workspace files (note that the docs don't mention that field yet).

The CLI option has priority over the workspace configuration. See added test for details.

Implementation notes

Interaction with --ignore-lock-dir

It is rather simple:

  • pkg = enabled means autolocking is activated.
  • pkg = disabled means no lock directory is ever considered anyway.

I still think these two options are too related to be separated, and should be merged eventually, but that isn't included in this PR.

Overlap with the existing pkg option

The dune init command option has a pkg option which relates to either opam or esy, nothing related to what I'm doing here. However the name can't be used for two different options (thanks Cmdliner), so I added a boolean allow_pkg_flag to sort that out. Not the cleanest option, advice appreciated.

Priority calculation

I found this comment in workspace.mli which clearly states priority order, worth a quick look

Documentation changes

I added an entry for the pkg field in workspace files which was missing, alluding to the CLI option. Rendered output visible here.

  • changes entry no changes entry for pkg related stuff

cc @Alizter @art-w as they helped me with this <3

@shonfeder

Copy link
Copy Markdown
Member

Glad to see this coming into shape! Where can I find the analysis and design justification/explanation of how the different options interact or override each other?

@Alizter

Alizter commented Jan 26, 2026

Copy link
Copy Markdown
Collaborator

@shonfeder The test checks this extensively.

@samoht

samoht commented Jan 27, 2026 •

Copy link
Copy Markdown
Member

Could we have a richer state instead of enabled/disabled? for instance:

  • disable
  • portable (to generate a portable lock file)
  • enabled (to generate a non-portable lock file -- faster in the dev mode use-case)
  • always (to always relock and ignore any existing lockdir -> implies non-portable)

@shonfeder

Copy link
Copy Markdown
Member

@shonfeder The test checks this extensively.

Yes I saw the test. I am asking after the rationale and specification of the behavior. What is the general rule we are applying that should be applied in all similar cases? How will it interact with environment variables for the same functionality (which is also called for in the issue)?

Tests of a single use case aren't sufficient to specify the rule and explain the rationale (tho a spec that is also tested is cool when that works out).

@shonfeder

Copy link
Copy Markdown
Member

Could we have a richer state instead of enabled/disabled? for instance:

  • disable

  • portable (to generate a portable lock file)

  • enabled (to generate a non-portable lock file -- faster in the dev mode use-case)

  • always (to always relock and ignore any existing lockdir -> implies non-portable)

I think we can safely add extensions to the value accepted here in follow-ups, without expanding the scope of this PR, so long as we are not committing to anything that limits those extensions. We are aware of your RFC drafts that touch on this flag, btw, and not ignoring them :)

@Leonidas-from-XIV

Leonidas-from-XIV commented Jan 27, 2026 •

Copy link
Copy Markdown
Member

Personally I think the solution to #12819 should be a tool that edits dune-workspace (sets (pkg enabled) or similar). That way we don't introduce yet another configuration dimension and everything in the build is declarative, instead of depending on the user setting a plethora of random CLI flags to make their build work.

This would also allow for extension on what can be configured (akin to git config) in the future, thus making it potentially easier for people to configure e.g. multiple contexts with multiple lock dirs because while the dune-workspace config file can be somewhat complicated, the CLI can provide an easy interface to do common tasks.

--ignore-lock-dir is essentially only meant to be used via -p (thus, mostly when installing via OPAM) and not for users to enable or disable package management or configure it.

@Alizter

Alizter commented Jan 27, 2026

Copy link
Copy Markdown
Collaborator

We already do this for enabling/disabling the cache. This PR is reusing the logic introduced there. This is not editing dune-workspace but rather overriding it in a precedented way.

The title of this PR is perhaps inaccurate since the goal is not to enable/disable package management, but rather to provide a CLI analogue to the existing (pkg enabled) stanza in dune-workspace.

--ignore-lock-dir is an orthogonal behaviour to what is essentially being provided. Currently as it stands there is no way to enable "autolocking" (which should rather be named "creating-a-build-plan-without-locking") from the CLI.

This PR is filling this gap and nothing more.


Regarding some other comments:

  • disable

This is possible with (pkg disabled) and now --pkg disabled which will also ignore lock directories.

  • portable (to generate a portable lock file)

This is the default behaviour.

  • enabled (to generate a non-portable lock file -- faster in the dev mode use-case)

This can be configured by setting the platforms you want to solve for to one. Not the most ergonomic, but we would need to think a bit harder on a nice way to do this otherwise. If we don't have an issue open about this we should open one.

  • always (to always relock and ignore any existing lockdir -> implies non-portable)

This is --pkg enabled --ignore-lock-dir.


Regarding the precedence of the CLI vs workspace vs env vars vs config. I think this is something that should be thought about, but I would argue that it doesn't belong in this PR. This PR is following the precedent set by options such as (cache enabled). As it stands:

CLI > env vars > dune-workspace > config

The first precedent pair is inherited from cmdliner. We can of course change this, but it can be argued that it is the most expected. If you disagree, great, but let's instead discuss that in the relevant issue.

@Alizter
Alizter self-requested a review January 27, 2026 09:41
@Leonidas-from-XIV

Copy link
Copy Markdown
Member

This PR is filling this gap and nothing more.

Ok, then maybe I should ask: why? What is the use case that this is solving? --ignore-lock-dir is solving the usecase of "OPAM is installing a tarball that has a lockfile". Admittedly, with autolocking the flag should be renamed to be more descriptive.

I think adding more configuration flags just because it is possible makes the UX worse as it

  • Adds another configuration dimension
  • Confuses users whether they should or should not be using this flag
  • Makes it easier for users to accidentally do the wrong thing (e.g. write Makefiles to call dune ... --pkg=enabled instead of editing the dune-workspace)

I am worried about adding an option to Dune that we will have to discourage people from using.

Comment thread bin/common.ml

let dash_p =
let dash_p_implies = [ "--release"; "--ignore-lock-dir"; "--only-packages" ] in
let dash_p_implies = [ "--release"; "--pkg=disabled"; "--only-packages" ] in

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this change is answering @Leonidas-from-XIV 's question regarding the need: --ignore-lock-dir is incorrect for the purpose of an Opam installation, since it shouldn't disable pkg if you have it enabled in your workspace.

On the other end, the explicit --pkg=enabled is very useful for CI! (for progressive adoption)

As mentioned by @ElectreAAS , it should be possible to refactor the flag --ignore-lock-dir to mean --pkg=always i.e. "enabled-but-ignore-existing-lock-dir", but it'll be easier to review this in a follow-up PR, separate from the introduction of the new --pkg flag feature. I think this will make the semantics clearer and open the way for more options for that flag (e.g. non portable lockfiles).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well fair enough. In such case I would actually suggest removing --ignore-lock-dir since its only purpose was to not accidentally trigger package management when a package that comes with a lock dir is distributed via OPAM. With --pkg=disabled supplanting that, I think it is completely obsolete (one could configure --pkg=enabled --ignore-lock-dir but it seems like a weird roundabout way to require autolocking and not a reasonable configuration option - if we wanted that then something like a hypothetical --pkg=autolock would be a much better way to express such a configuration).

@shonfeder

Copy link
Copy Markdown
Member

@Leonidas-from-XIV

Personally I think the solution to #12819 should be a tool that edits dune-workspace (sets (pkg enabled) or similar).

This defeats the purpose of the issue, which is to make it possible to bypass (or enable) package management functionality without having to edit the files on disk (and so make the repo dirty, etc.)

This is still declarative, but the declaration happens on the CLI.

@shonfeder

Copy link
Copy Markdown
Member

Regarding the precedence of the CLI vs workspace vs env vars vs config. I think this is something that should be thought about, but I would argue that it doesn't belong in this PR.

To be clear, I was not asking for it to be added in this PR, I was asking where it is documented/specified. :D

@art-w art-w left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this PR is good and should be merged! It introduces a useful feature which both addresses the CI needs and provides a cleaner setting to disable pkg for opam installations.

However there's some follow-up refactoring work to do to clean up the interaction with --ignore-lock-dir described in the issue #13468, which would then enable the other improvements requested by everyone :)

@ElectreAAS

Copy link
Copy Markdown
Collaborator Author

I added in the PR description a link to a comment specifying the priority order.
I still agree with you @shonfeder that it's not the most visible thing ever

@ElectreAAS

ElectreAAS commented Jan 27, 2026 •

Copy link
Copy Markdown
Collaborator Author

As this is a user-visible change, this needs a changelog entry (and probably an update in the docs too)
I put off making one until reviews have stabilized

@ElectreAAS

Copy link
Copy Markdown
Collaborator Author

I opened the follow-up #13472 that may better answer your concerns @Leonidas-from-XIV @samoht

@Leonidas-from-XIV Leonidas-from-XIV left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the code is fine overall, my main concern would be to straight up remove --ignore-lock-dirs directly but that's in #13468.

Comment thread bin/pkg/pkg_enabled.ml Resolved
@ElectreAAS
ElectreAAS force-pushed the push-xksznwmmqnkm branch 2 times, most recently from caba848 to 883291d Compare January 28, 2026 15:51
@ElectreAAS

Copy link
Copy Markdown
Collaborator Author

I added a doc entry for the pkg field in workspace files, which also mentions the CLI option.

@Leonidas-from-XIV you added the field in the first place, but there was no doc entry. Was this an oversight or a deliberate choice?

@Leonidas-from-XIV

Copy link
Copy Markdown
Member

@ElectreAAS We don't write package management stuff in the changelog, so it was a deliberate choice to let it out.

@ElectreAAS

Copy link
Copy Markdown
Collaborator Author

We don't write package management stuff in the changelog

right, I somehow forgot about that. I removed it, but the doc entry is still there
I'll merge if CI is green, unless someone objects in the mean time

@Alizter
Alizter removed their request for review January 29, 2026 15:00
@ElectreAAS
ElectreAAS merged commit d145919 into ocaml:main Jan 30, 2026
26 checks passed
@ElectreAAS
ElectreAAS deleted the push-xksznwmmqnkm branch January 30, 2026 12:43
@ElectreAAS

Copy link
Copy Markdown
Collaborator Author

The only red in the CI was the ocaml benchmarks one, suffering from lack of space. Unrelated, and other commits on main also have the same problem 🤷

Leonidas-from-XIV added a commit that referenced this pull request Feb 2, 2026
…d` (#13498)

The purpose of `--ignore-lock-dir` was to disable package management in
case a package was installed via OPAM as the presence of a lock dir was
the only thing required to trigger package management. Thus it was an
option that was implied in `-p`. But with #13458 merged, `-p` reasonably
switched to `--pkg=disabled`.

This leaves `--ignore-lock-dir` as a more or less worse version of
`--pkg=disabled`, with unclear semantics if these two options are
combined. This PR removes the option altogether.

As to why it was called `--ignore-lock-dir` and not
`--disable-package-management`: For the longest time an explicitly
created lock dir was the only way to use package management, thus these
two terms are equivalent. Notably, ``-ignore-lock-dir` should never
imply autolocking, because that directly contradicts the "disable in the
OPAM context" usecase.

Closes #13468
Closes #13469
Closes #13470
Closes #13472

Signed-off-by: Marek Kubica <[email protected]>
@Alizter Alizter added this to the 3.22.0 milestone Jul 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pkg: Add CLI interface for enabling and disabling package management during single command executions

6 participants