Skip to content

Conversation

@ElectreAAS
Copy link
Collaborator

@ElectreAAS ElectreAAS commented Jan 26, 2026

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

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

$ dune pkg enabled --ignore-lock-dir
^^^ This is a bug. It should be disabled.
We have a lock directory, but it is ignored.
It should behave the same as if there was no lockdir
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The bug is with the detection mechanism of the dune pkg enabled command, but not the actual detection mechanism used in the important parts of the engine

Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you create an issue about this?

Copy link
Collaborator Author

@ElectreAAS ElectreAAS Jan 27, 2026

Choose a reason for hiding this comment

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

Done -> #13469 and associated PR #13470

@shonfeder
Copy link
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
Copy link
Collaborator

Alizter commented Jan 26, 2026

@shonfeder The test checks this extensively.

@samoht
Copy link
Member

samoht commented Jan 27, 2026

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
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
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
Copy link
Collaborator

Leonidas-from-XIV commented Jan 27, 2026

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
Copy link
Collaborator

Alizter commented Jan 27, 2026

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
Collaborator

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.


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
Collaborator

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
Collaborator

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
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
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

Copy link
Collaborator

@art-w art-w left a comment

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
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
Copy link
Collaborator Author

ElectreAAS commented Jan 27, 2026

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
Collaborator Author

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

Copy link
Collaborator

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

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.

@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
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
Collaborator

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

Signed-off-by: Ambre Austen Suhamy <ambre@tarides.com>
@ElectreAAS
Copy link
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
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