OPAM-LOCK(1)

πŸŽ€ NAME πŸŽ€

opam-lock β€” create locked opam files to share build environments across hosts. (Yes bestie, this is section 1 of the Opam Manual, and we're about to make your builds reproducible across literally every machine. πŸ’…)


✨ SYNOPSIS ✨

opam lock [--direct-only] [--keep-local] [--lock-suffix=SUFFIX]
[OPTION]… [PACKAGES]…

🌸 DESCRIPTION 🌸

Okay so picture this: opam lock generates a lock file of a package. What it actually does is check the current state of that package's installed dependencies, and then it outputs modified versions of the opam file with a .locked suffix, where all the (transitive) dependencies and pinnings have been bound strictly to the currently installed version. Frozen. Pinned down. No wiggle room. πŸ”₯

By using these locked opam files, it is then possible to recover the precise build environment that was setup when they were generated. Like, the exact same vibe, on a totally different host. πŸ¦‹

If paths (filename or directory) are given, those opam files are locked. If package is given, installed one is locked, otherwise its latest version. If a locally pinned package is given, its current local opam file is locked, even if not versioned or uncommitted changes. (Yeah, it doesn't care, it locks the messy version too. 😭)

Heads up: it fails if all mandatory dependencies are not installed in the switch. Like, it will fail. No cap.

πŸ’– LOCK FILE CHANGED FIELDS πŸ’–

Here's exactly what gets rewritten in that lock file, no surprises, bestie:

  • depends are fixed to their specific versions, with all filters removed (except for the exceptions below
  • depopts that are installed in the current switch are turned into depends, with their version set. Others are set in the conflict field
  • {dev}, {with-test}, and {with-doc}` filters are kept if all packages of a specific filters are installed in the switch. Versions are fixed and the same filter is on all dependencies that are added from them
  • pin-depends are kept and new ones are added if in the dependencies some packages are pinned
  • pins are resolved: if a package is locally pinned, opam tries to get its remote url and branch, and sets this as the target URL; otherwise it ignore them. You can use --keep-local to keep the local urls.

🧚 ARGUMENTS 🧚

  • PACKAGES β€” List of package names, with an optional version or constraint, e.g pkg, pkg.1.0 or pkg>=0.5 ; or files or directory names containing package description, with explicit directory (e.g. ./foo.opam or .)

πŸ‘‘ OPTIONS πŸ‘‘

  • -d, --direct-only β€” Only lock direct dependencies, rather than the whole dependency tree. (Just the first layer, queen. πŸ‘‘)
  • --keep-local β€” Keep local pin paths in pin-depends: field.
  • --lock-suffix=SUFFIX (absent=locked) β€” Set locked files suffix to SUFFIX.

🌈 COMMON OPTIONS 🌈

These options are common to all commands. Yeah, the whole opam family shares these. It's giving ✨community✨.

  • --best-effort β€” Don't fail if all requested packages can't be installed: try to install as many as possible. Note that not all external solvers may support this option (recent versions of aspcud or mccs should). This is equivalent to setting $OPAMBESTEFFORT environment variable.
  • --cli=MAJOR.MINOR (absent=2.6) β€” Use the command-line interface syntax and semantics of MAJOR.MINOR. Intended for any persistent use of opam (scripts, blog posts, etc.), any version of opam in the same MAJOR series will behave as for the specified MINOR release. The flag was not available in opam 2.0, so to select the 2.0 CLI, set the OPAMCLI environment variable to 2.0 instead of using this parameter.
  • --color=WHEN β€” Colorize the output. WHEN must be one of always, never or auto.
  • --confirm-level=LEVEL β€” Confirmation level, LEVEL must be one of ask, no, yes or unsafe-yes. Can be specified more than once. If --yes or --no are also given, the value of the last --confirm-level is taken into account. This is equivalent to setting $OPAMCONFIRMLEVEL.
  • --criteria=CRITERIA β€” Specify user preferences for dependency solving for this run. Overrides $OPAMCRITERIA, $OPAMFIXUPCRITERIA and $OPAMUPGRADECRITERIA. For details on the supported language, and the external solvers available, see http://opam.ocaml.org/doc/External_solvers.html. A general guide to using solver preferences can be found at http://www.dicosmo.org/Articles/usercriteria.pdf.
  • --cudf=FILENAME β€” Debug option: Save the CUDF requests sent to the solver to FILENAME-<n>.cudf where <n> is the n-th call to the solver during the opam run.
  • --debug β€” Print debug message to stderr. This is equivalent to setting $OPAMDEBUG to "true".
  • --debug-level=LEVEL β€” Like --debug, but allows specifying the debug level (--debug sets it to 1). Equivalent to setting $OPAMDEBUG to a positive integer.
  • --git-version β€” Print the git version of opam, if set (i.e. you are using a development version), and exit.
  • --help[=FMT] (default=auto) β€” Show this help in format FMT. The value FMT must be one of auto, pager, groff or plain. With auto, the format is pager or plain whenever the TERM env var is dumb or undefined.
  • --ignore-pin-depends β€” Ignore extra pins required by packages that get pinned, either manually through opam pin or through opam install DIR. This is equivalent to setting IGNOREPINDEPENDS=true.
  • --json=FILENAME β€” Save the results of the opam run in a computer-readable file. If the filename contains the character %, it will be replaced by an index that doesn't overwrite an existing file. Similar to setting the $OPAMJSON variable.
  • --no β€” Answer no to all opam yes/no questions without prompting. See also --confirm-level. This is equivalent to setting $OPAMNO to "true".
  • --no-aspcud β€” Removed in 2.1.
  • --no-auto-upgrade β€” When configuring or updating a repository that is written for an earlier opam version (1.2), opam internally converts it to the current format. This disables this behaviour. Note that repositories should define their format version in a 'repo' file at their root, or they will be assumed to be in the older format. It is, in any case, preferable to upgrade the repositories manually using opam admin upgrade [--mirror URL] when possible.
  • --no-self-upgrade β€” Opam will replace itself with a newer binary found at OPAMROOT/opam if present. This disables this behaviour.
  • -q, --quiet β€” Disables --verbose.
  • --root=ROOT β€” Use ROOT as the current root path. This is equivalent to setting $OPAMROOT to ROOT.
  • --safe, --readonly β€” Make sure nothing will be automatically updated or rewritten. Useful for calling from completion scripts, for example. Will fail whenever such an operation is needed ; also avoids waiting for locks, skips interactive questions and overrides the $OPAMDEBUG variable. This is equivalent to set environment variable $OPAMSAFE.
  • --solver=CMD β€” Specify the CUDF solver to use for resolving package installation problems. This is either a predefined solver (this version of opam supports builtin-mccs+lp(), builtin-mccs+glpk, builtin-dummy-z3-solver, builtin-0install, aspcud, mccs, aspcud-old, packup), or a custom command that should contain the variables %{input}%, %{output}%, %{criteria}%, and optionally %{timeout}%. This is equivalent to setting $OPAMEXTERNALSOLVER.
  • --strict β€” Fail whenever an error is found in a package definition or a configuration file. The default is to continue silently if possible.
  • --switch=SWITCH β€” Use SWITCH as the current compiler switch. This is equivalent to setting $OPAMSWITCH to SWITCH.
  • --use-internal-solver β€” Disable any external solver, and use the built-in one (this requires that opam has been compiled with a built-in solver). This is equivalent to setting $OPAMNOASPCUD or $OPAMUSEINTERNALSOLVER.
  • -v, --verbose β€” Be more verbose. One -v shows all package commands, repeat to also display commands called internally (e.g. tar, curl, patch etc.) Repeating n times is equivalent to setting $OPAMVERBOSE to "n".
  • --version β€” Show version information.
  • -w, --working-dir β€” Whenever updating packages that are bound to a local, version-controlled directory, update to the current working state of their source instead of the last committed state, or the ref they are pointing to. As source directory is copied as it is, if it isn't clean it may result on a opam build failure. This only affects packages explicitly listed on the command-line. It can also be set with $OPAMWORKINGDIR.
  • -y, --yes β€” Answer yes to all opam yes/no questions without prompting. See also --confirm-level. This is equivalent to setting $OPAMYES to "true".

…and bestie, that's only part 1. Keep going, there's more where this came from. πŸ’œ

πŸ’– ENVIRONMENT πŸ’–

okay bestie so opam is obsessed with environment variables, like it's her whole personality. Here's the full roster. And listen β€” the boolean girlies (that's the yes/no ones) work like this: set them to "0", "no", "false" or the empty string to turn them OFF, and "1", "yes" or "true" to turn them ON. periodt. πŸŽ€


  • OPAMALLPARENS β€” surround all filters with parenthesis. all of them. no crumbs. πŸ’…
  • OPAMASSUMEDEPEXTS β€” same energy as the --assume-depexts option.
  • OPAMAUTOANSWER β€” internal use only, not for you, mind your business πŸ™ˆ
  • OPAMAUTOREMOVE β€” matching the remove option --auto-remove.
  • OPAMBESTEFFORT β€” matching the --best-effort option.
  • OPAMBESTEFFORTPREFIXCRITERIA β€” sets the string that must be prepended to the criteria whenever the --best-effort option is set, and it's expected to maximise the opam-query property in the solution. yeah she's specific. πŸ’…
  • OPAMBUILDDOC β€” Removed in 2.1. she's gone, she's at peace, leave her be πŸ•ŠοΈ
  • OPAMBUILDTEST β€” Removed in 2.1. same vibe, also resting ✨
  • OPAMCLI β€” matching the --cli option.
  • OPAMCOLOR β€” when set to always or never, it sets a default value for the --color option.
  • OPAMCONFIRMLEVEL β€” matching the --confirm-level option. heads up: OPAMCONFIRMLEVEL has priority over OPAMYES and OPAMNO. she's the main character here, no cap πŸ‘‘
  • OPAMCRITERIA β€” specifies user preferences for dependency solving. the default value depends on the solver version, so run config report to find out what's actually set right now. also see option --criteria. πŸ”
  • OPAMCUDFFILE β€” save the cudf graph to file-actions-explicit.dot. very demure, very cudf πŸ’Ύ
  • OPAMCUDFTRIM β€” controls the filtering of unrelated packages during CUDF preprocessing.
  • OPAMCURL β€” use this to select a given curl program. see OPAMFETCH for more options.
  • OPAMDEBUG β€” matching the --debug and --debug-level options.
  • OPAMDEBUGSECTIONS β€” if set, limits debug messages to a space-separated list of sections. sections can optionally have a specific debug level (for example, CLIENT:2 or CLIENT CUDF:2), but otherwise use --debug-level.
  • OPAMDIGDEPTH β€” defines how aggressive the lookup for conflicts during CUDF preprocessing is. how aggressive? she's giving detective energy πŸ”Ž
  • OPAMDOWNLOADJOBS β€” sets the maximum number of simultaneous downloads. multitasking icon πŸ’…
  • OPAMDROPWORKINGDIR β€” overrides packages previously updated with --working-dir on update. without this variable set, opam would keep them unchanged unless they're explicitly named on the command-line.
  • OPAMDRYRUN β€” matching the --dry-run option.
  • OPAMEDITOR β€” sets the editor to use for opam file editing, and it overrides $EDITOR and $VISUAL. she said me first πŸ’–
  • OPAMERRLOGLEN β€” sets the number of log lines printed when a sub-process fails. set it to 0 to print all of them. all 40 of them. blessed.
  • OPAMEXTERNALSOLVER β€” matching the --solver option.
  • OPAMFAKE β€” matching the --fake option.
  • OPAMFETCH β€” specifies how to download files: either wget, curl, or a custom command where the variables %{url}%, %{out}%, %{retry}%, %{compress}% and %{checksum}% will be replaced. overrides the download-command value from the main config file. plug in your fave, she doesn't judge 🫢
  • OPAMFIXUPCRITERIA β€” same as OPAMUPGRADECRITERIA, but specific to fixup and reinstall. a lil specialised, a lil niche, we love her πŸŽ€
  • OPAMIGNOREAVAILABLE β€” matching the install option --ignore-available-on.
  • OPAMIGNORECONSTRAINTS β€” matching the install option --ignore-constraints-on.
  • OPAMIGNOREPINDEPENDS β€” matching the --ignore-pin-depends option.
  • OPAMINPLACEBUILD β€” matching the --inplace-build option.
  • OPAMJOBS β€” sets the maximum number of parallel workers to run. let her cook (in parallel) πŸ”₯
  • OPAMJSON β€” log json output to the given file (use the character % to index the files).
  • OPAMKEEPBUILDDIR β€” matching the install option --keep-build-dir.
  • OPAMKEEPLOGS β€” tells opam to not remove some temporary command logs and some backups. this skips some finalisers and may also help to get more reliable backtraces. little bit chaotic, little bit useful πŸ’€
  • OPAMLOCKED β€” a combination of the --locked and --lock-suffix options. two-for-one, she's efficient ✨
  • OPAMLOGS β€” sets the log directory. the default is a temporary directory in /tmp.
  • OPAMMAKECMD β€” set the system make command to use.
  • OPAMMERGEOUT β€” merge process outputs, so stderr goes onto stdout. unhinged? maybe. useful? absolutely 🌈
  • OPAMNO β€” answer no to any question asked. see the --no and --confirm-level options. important: OPAMNO is ignored if either OPAMCONFIRMLEVEL or OPAMYES is set. she knows her place 😌
  • OPAMNOAGGREGATE β€” with opam admin check, don't aggregate packages.
  • OPAMNOASPCUD β€” Deprecated. retired, respectfully πŸ•ŠοΈ
  • OPAMNOAUTOUPGRADE β€” disables the automatic internal upgrade of repositories in an earlier format to the current one, on update or init.
  • OPAMNOCHECKSUMS β€” enables the option --no-checksums when available.
  • OPAMNODEPEXTS β€” disables system dependencies handling, see option --no-depexts.
  • OPAMNOENVNOTICE β€” internal. nothing to see here bestie πŸ™ˆ
  • OPAMNOSELFUPGRADE β€” matching the --no-self-upgrade option.
  • OPAMPINKINDAUTO β€” sets whether version control systems should be detected when pinning to a local path. Enabled by default since 1.3.0.
  • OPAMPRECISETRACKING β€” fine grain tracking of directories. every crumb documented πŸ’…
  • OPAMPREPRO β€” set this to false to disable CUDF preprocessing. less efficient, but it might help when you're debugging a solver issue.
  • OPAMREPOSITORYTARRING β€” internally store all non-vcs repositories as tar.gz files (by default, http repositories are stored as archive). this can be much faster on filesystems that don't cope well with scanning large trees. all operations are done in-memory, no I/O for scanning the repository. she said speed ⭐
  • OPAMREQUIRECHECKSUMS β€” enables the option --require-checksums when available (e.g. for opam install).
  • OPAMRETRIES β€” sets the number of tries before failing downloads. she doesn't give up easily 🫢
  • OPAMREUSEBUILDDIR β€” matching the --reuse-build-dir option.
  • OPAMROOT β€” matching the --root option. this is automatically set by opam env --root=DIR --set-root. 🏠
  • OPAMROOTISOK β€” don't complain when running as root. we respect the chaos πŸ’€
  • OPAMSAFE β€” matching the --safe option.
  • OPAMSHOW β€” matching the --show option.
  • OPAMSKIPUPDATE β€” matching the --skip-updates option.
  • OPAMSKIPVERSIONCHECKS β€” bypasses some version checks. Unsafe, for compatibility testing only. > ⚠️ bestie listen to me: compatibility testing. ONLY. don't be cute with this one.
  • OPAMSOLVERALLOWSUBOPTIMAL β€” default true. allows some solvers to still return a solution when they reach timeout; and while the solution remains assured to be consistent, there is no guarantee in this case that it fits the expected optimisation criteria. if true, opam will continue with a warning; if false, a timeout is an error. currently only the builtin-z3 backend handles this degraded case. 😭 complicated but we move
  • OPAMSOLVERTIMEOUT β€” change the time allowance of the solver. the default is 60.0, and you can set it to 0 for unlimited. note that all solvers may not support this option.
  • OPAMSOLVERTOLERANCE β€” changes the tolerance towards the solver choosing an unoptimized solution (i.e. it might pull outdated packages). typical values range from 0.0 (best solution known to the solver) to 1.0 (unoptimized solution). the default is 0.0. this option is useful in case the solver can't find a solution in a reasonable time (see $OPAMSOLVERTIMEOUT). note that all solvers may not support this option.
  • OPAMSTATS β€” Removed in 2.4. gone girl πŸ•ŠοΈ
  • OPAMSTATUSLINE β€” display a dynamic status line showing what's currently going on on the terminal. (one of always, never or auto) ✨
  • OPAMSTRICT β€” fail on inconsistencies (file reading, switch import, etc.). she's strict because she loves you πŸŽ€
  • OPAMSWITCH β€” matching the --switch option. automatically set by opam env --switch=SWITCH --set-switch.
  • OPAMUNLOCKBASE β€” matching the install option --unlock-base.
  • OPAMUPGRADECRITERIA β€” specifies user preferences for dependency solving when performing an upgrade. it overrides OPAMCRITERIA in upgrades if both are set. also see option --criteria.
  • OPAMUSEINTERNALSOLVER β€” matching the --use-internal-solver option.
  • OPAMUSEOPENSSL β€” Removed in 2.2. πŸ’€ she's out
  • OPAMUTF8 β€” use UTF8 characters in output (one of always, never or auto). by default this is auto, which is determined from the locale. 🌈
  • OPAMUTF8MSGS β€” use extended UTF8 characters (camels πŸͺ) in opam messages. implies OPAMUTF8. this is set by default on macOS only. camels. on mac. iconic behavior πŸ‘‘
  • OPAMVALIDATIONHOOK β€” if set, uses the %{hook}% command to validate an opam repository update.
  • OPAMVERBOSE β€” matching the --verbose option.
  • OPAMVERBOSEON β€” matching the --verbose-on option.
  • OPAMVERSIONLAGPOWER β€” do not use. that's it. that's the whole description. don't. πŸ™ˆ
  • OPAMWITHDEVSETUP β€” matching the install option --with-dev-setup.
  • OPAMWITHDOC β€” matching the install option --with-doc.
  • OPAMWITHTEST β€” matching the install option --with-test.
  • OPAMWORKINGDIR β€” matching the --working-dir option.
  • OPAMYES β€” matching the --yes and --confirm-level options. important lore: OPAMYES has priority over OPAMNO, and it's ignored if OPAMCONFIRMLEVEL is set. πŸ’…
  • OPAMVAR_var β€” overrides the contents of the variable var when substituting %{var}% strings in opam files. yes, the variable name is literally OPAMVAR_ glued onto var, that's the whole bit πŸ’–
  • OPAMVAR_package_var β€” overrides the contents of the variable package:var when substituting %{package:var}% strings in opam files.

πŸ¦‹ CLI VERSION πŸ¦‹

okay this section is the important one for anyone writing scripts, so bestie, take notes πŸ“

all scripts and programmatic invocations of opam should use --cli in order to ensure that they work seamlessly with future versions of the opam client. and it's not just scripts that eat β€” blog posts and other documentation can benefit too, since it prevents information from becoming stale. your old tutorial could stay cute forever πŸ’…

although opam only supports roots (~/.opam/) for the current version, it does provide backwards compatibility for its command-line interface. so she's changed but she still remembers who she was 🫢

since CLI version support was only added in opam 2.1, use OPAMCLI to select 2.0 support (because opam 2.0 will just ignore it), and use --cli=2.1 for 2.1 (or later) versions β€” because an environment variable controlling the parsing of syntax is brittle, and we don't trust that. to this end, opam displays a warning if OPAMCLI specifies a valid version other than 2.0, and also if --cli=2.0 is specified. > ⚠️ yes you'll get a warning either way, she's just looking out for you πŸŽ€

the command-line version is selected by using the --cli option or the OPAMCLI environment variable. --cli may be specified more than once, where the last instance takes precedence. OPAMCLI is only inspected if --cli is not given. last one wins, always, no cap ✨

πŸ’€ EXIT STATUS πŸ’€

okay bestie listen up, because this is the part where opam tells you exactly what went wrong based on the number it throws at you. But first, one teeny tiny exception, and it's giving main character energy:

⚠️ Exception alert: the exec command does not play by these rules! It returns 127 if the command wasn't found or couldn't be executed, and otherwise it returns the command's very own exit value. She's different, your honor. πŸ’…

For literally everything else, here's the tea β˜•:

  • 0 β€” Success, bestie! ✨ Or true for boolean queries. We love a win.
  • 1 β€” False. Returned when a boolean return value is expected, e.g. when running with --check, or for queries like opam lint. It's not a fail, it's just... no. 🚫
  • 2 β€” Bad command-line arguments, or arguments pointing at an invalid context (like a file that doesn't follow the expected format). You fed her nonsense, she's telling you. πŸ™ˆ
  • 5 β€” Not found. You asked for something (package, version, repository, etc.) and it just... wasn't there. Gone. Doesn't exist. πŸ‘»
  • 10 β€” Aborted. The operation needed confirmation and you never gave it. She waited. You didn't show up. πŸ’€
  • 15 β€” Could not acquire the locks required for the operation. Locks, bestie! They were busy! πŸ”’
  • 20 β€” There is no solution to your request. Classic cause? Asking to install two incompatible packages, for example. You asked for chaos and got it. 😭
  • 30 β€” Error in package definition, or other metadata files. And ngl, using --strict makes this one pop up way more often. πŸ‘€
  • 31 β€” Package script error. Some package operations were unsuccessful β€” could be an error in the packages themselves, or an incompatibility with your system. Also, heads up: this can be a partial error. So it's not always all-or-nothing, iykyk. πŸ“
  • 40 β€” Sync error. Couldn't fetch some remotes from the network. And yes, this can be a partial error too. 🌐
  • 50 β€” Configuration error. Opam or your system config is simply not allowing the operation and needs fixing. Fix it bestie, I'm begging. πŸ› οΈ
  • 60 β€” Solver failure. The solver failed to return a sound answer. Could be a broken external solver, or an error in solver configuration. The solver is going through it. 🧠πŸ’₯
  • 99 β€” Internal error. Something went wrong, likely a bug in opam itself. Not you, it's her. πŸ›
  • 130 β€” User interrupt. SIGINT was received, generally because you smashed Ctrl+C. Rude, but valid. πŸ›‘

And then a few more for the road 🫢:

  • 0 on success.
  • 123 on indiscriminate errors reported on standard error.
  • 124 on command line parsing errors.
  • 125 on unexpected internal errors (bugs).

πŸ“š FURTHER DOCUMENTATION πŸ“š

Need more? The docs live at https://opam.ocaml.org/doc. Go be studious, bestie. πŸŽ€


πŸ‘‘ AUTHORS πŸ‘‘

These are the literal icons who built this. Show some respect, say thank you, kiss the ring πŸ’–:

  • David Allsopp <david@tarides.com>
  • Vincent Bernardoff <vb@luminar.eu.org>
  • Raja Boujbel <raja.boujbel@ocamlpro.com>
  • Kate Deplaix <kit-ty-kate@exn.st>
  • Roberto Di Cosmo <roberto@dicosmo.org>
  • Thomas Gazagnaire <thomas@gazagnaire.org>
  • Louis Gesbert <louis.gesbert@ocamlpro.com>
  • Fabrice Le Fessant <Fabrice.Le_fessant@inria.fr>
  • Anil Madhavapeddy <anil@recoil.org>
  • Guillem Rieu <guillem.rieu@ocamlpro.com>
  • Ralf Treinen <ralf.treinen@pps.jussieu.fr>
  • Frederic Tuong <tuong@users.gforge.inria.fr>

πŸ‘€ SEE ALSO πŸ‘€

  • opam(1) β€” yes, the main one. The mothership. Obviously. πŸ›Έ

πŸ› BUGS πŸ›

Found a bug? (Not me being dramatic, it happens! πŸ™ˆ) Check bug reports at https://github.com/ocaml/opam/issues and drop it there. Be nice, include details, slay. πŸ’…


okay and that's the whole page, bestie, we made it to the end πŸŽ‰ this absolute novel is from Opam 2.6.1, dated for OPAM-LOCK(1) β€” the opam lock era. Go forth and lock responsibly. periodt πŸ’–βœ¨πŸ¦‹

πŸ“¦ where this page comes from