OPAM-ADMIN-ADD-CONSTRAINT(1)
π OPAM-ADMIN-ADD-CONSTRAINT π
okay so bestie, this one lives in the Opam admin Manual, and its full government name is OPAM ADMIN-ADD-CONSTRAINT(1). It's a glow-up tool for your repo metadata. Let's get into it π
β¨ NAME β¨
opam admin-add-constraint β Adds version constraints on all dependencies towards a given package.
πΈ SYNOPSIS πΈ
opam admin add-constraint [--force] [--packages=PACKAGES] [OPTION]β¦ PACKAGE
π DESCRIPTION π
So the way this works is: it goes and searches to all dependencies that point towards a given package, and then it slaps a version constraint on them. Iconic behavior, honestly.
It's particularly useful when you wanna add upper bounds to dependencies you already have β like when a brand-new, incompatible major version of a library drops into a repository and you need everyone to chill π«Ά
The new version constraint gets merged with the existing one, and then simplified if possible. Example, because I know you love a concrete one: >=3 & >5 becomes >5. Math ate, periodt β¨
π¦ ARGUMENTS π¦
PACKAGE(required) β A package name with a version constraint, e.g.name>=version. And ngl, if you don't specify a version constraint, the command will just simplify the existing version constraints on dependencies to the named package. No constraint added, just tidying up π§Ή
π OPTIONS π
--forceβ Forces the updating of constraints even if the resulting constraint is unsatisfiable (e.g. when adding>3to the constraint<2). Without this, the default is to print a warning and keep the existing constraint unchanged. So yeah, this one is the "I know what I'm doing" button π-pPACKAGES,--packages=PACKAGESβ Only add constraints for the given packages.
π COMMON OPTIONS π
These options are common to all commands. Yes, all of them. They're basically the group chat everyone's in.
--best-effortβ Don't fail if all requested packages can't be installed: try to install as many as possible. Heads up though, not all external solvers may support this option (recent versions ofaspcudormccsshould). This is equivalent to setting$OPAMBESTEFFORTenvironment variable.--cli=MAJOR.MINOR(absent=2.6) β Use the command-line interface syntax and semantics ofMAJOR.MINOR. Intended for any persistent use of opam (scripts, blog posts, etc.), any version of opam in the sameMAJORseries will behave as for the specifiedMINORrelease. The flag was not available in opam 2.0, so to select the 2.0 CLI, set theOPAMCLIenvironment variable to2.0instead of using this parameter.--color=WHENβ Colorize the output.WHENmust be one ofalways,neverorauto. π--confirm-level=LEVELβ Confirmation level,LEVELmust be one ofask,no,yesorunsafe-yes. Can be specified more than once. If--yesor--noare also given, the value of the last--confirm-levelis taken into account. This is equivalent to setting `$OPAMCONFIRMLEVEL``.--criteria=CRITERIAβ Specify user preferences for dependency solving for this run. Overrides$OPAMCRITERIA,$OPAMFIXUPCRITERIAand$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 toFILENAME-<n>.cudfwhere<n>is the n-th call to the solver during the opam run.--debugβ Print debug message to stderr. This is equivalent to setting$OPAMDEBUGto"true".--debug-level=LEVELβ Like--debug, but allows specifying the debug level (--debugsets it to1). Equivalent to setting$OPAMDEBUGto 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 formatFMT. The valueFMTmust be one ofauto,pager,grofforplain. Withauto, the format ispagerorplainwhenever theTERMenv var isdumbor undefined.--ignore-pin-dependsβ Ignore extra pins required by packages that get pinned, either manually throughopam pinor throughopam install DIR. This is equivalent to settingIGNOREPINDEPENDS=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$OPAMJSONvariable.--noβ Answer no to all opam yes/no questions without prompting. See also--confirm-level. This is equivalent to setting$OPAMNOto"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 usingopam admin upgrade [--mirror URL]when possible.-q,--quietβ Disables--verbose.--root=ROOTβ UseROOTas the current root path. This is equivalent to setting$OPAMROOTtoROOT.--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$OPAMDEBUGvariable. 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 supportsbuiltin-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β UseSWITCHas the current compiler switch. This is equivalent to setting$OPAMSWITCHtoSWITCH.--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$OPAMNOASPCUDor$OPAMUSEINTERNALSOLVER.-v,--verboseβ Be more verbose. One-vshows all package commands, repeat to also display commands called internally (e.g.tar,curl,patchetc.) Repeating n times is equivalent to setting$OPAMVERBOSEto"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$OPAMYESto"true".
π ENVIRONMENT π
bestie. opam is deeply into env vars. it reads a whole little family of them and they shape how it behaves, so listen up.
for the boolean ones (the yes/no girlies): set them to "0", "no", "false" or the empty string to turn it OFF, and "1", "yes" or "true" to turn it ON. that's the whole rule, no cap.
OPAMALLPARENSβ surrounds all filters with parenthesis. all of them. every single one π«ΆOPAMASSUMEDEPEXTSβ go look at the--assume-depextsoption, that's the one.OPAMAUTOANSWERβ internal use only π like, genuinely do not mess with her.OPAMAUTOREMOVEβ see the remove option--auto-remove.OPAMBESTEFFORTβ see option--best-effort.OPAMBESTEFFORTPREFIXCRITERIAβ sets the string that must be prepended to the criteria when the--best-effortoption is set, and it's expected to maximise theopam-queryproperty in the solution.OPAMBUILDDOCβ Removed in 2.1. she's gone πOPAMBUILDTESTβ Removed in 2.1. also gone.OPAMCLIβ see option--cli.OPAMCOLORβ when set toalwaysornever, she sets a default value for the--coloroption.OPAMCONFIRMLEVELβ see option--confirm-level. β οΈOPAMCONFIRMLEVELhas priority overOPAMYESandOPAMNO.OPAMCRITERIAβ specifies your user preferences for dependency solving. the default value depends on the solver version, so runconfig reportto know the current setting. see also option--criteria.OPAMCUDFFILEβ save the cudf graph to file-actions-explicit.dot.OPAMCUDFTRIMβ controls the filtering of unrelated packages during CUDF preprocessing.OPAMCURLβ can be used to select a given 'curl' program. seeOPAMFETCHfor more options.OPAMDEBUGβ see options--debugand--debug-level.OPAMDEBUGSECTIONSβ if set, limits debug messages to the space-separated list of sections. sections can optionally have a specific debug level (for example,CLIENT:2orCLIENT CUDF:2), but otherwise use--debug-level.OPAMDIGDEPTHβ defines how aggressive the lookup for conflicts during CUDF preprocessing is. she will dig πOPAMDOWNLOADJOBSβ sets the maximum number of simultaneous downloads.OPAMDROPWORKINGDIRβ overrides packages previously updated with--working-diron update. without this variable set, opam would keep them unchanged unless explicitly named on the command-line.OPAMDRYRUNβ see option--dry-run.OPAMEDITORβ sets the editor to use for opam file editing, overrides$EDITORand$VISUAL.OPAMERRLOGLENβ sets the number of log lines printed when a sub-process fails.0to print all.OPAMEXTERNALSOLVERβ see option--solver.OPAMFAKEβ see option--fake.OPAMFETCHβ specifies how to download files: eitherwget,curlor a custom command where variables%{url}%,%{out}%,%{retry}%,%{compress}%and%{checksum}%will be replaced. overrides the 'download-command' value from the main config file.OPAMFIXUPCRITERIAβ same asOPAMUPGRADECRITERIA, but specific to fixup and reinstall.OPAMIGNOREAVAILABLEβ see install option--ignore-available-on.OPAMIGNORECONSTRAINTSβ see install option--ignore-constraints-on.OPAMIGNOREPINDEPENDSβ see option--ignore-pin-depends.OPAMINPLACEBUILDβ see option--inplace-build.OPAMJOBSβ sets the maximum number of parallel workers to run. she's multithreading, periodt π₯OPAMJSONβ log json output to the given file (use character%to index the files).OPAMKEEPBUILDDIRβ see 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.OPAMLOCKEDβ combination of--lockedand--lock-suffixoptions.OPAMLOGSβ logdir sets log directory, default is a temporary directory in/tmp.OPAMMAKECMDβ set the system make command to use.OPAMMERGEOUTβ merge process outputs, stderr on stdout.OPAMNOβ answer no to any question asked, see options--noand--confirm-level. β οΈOPAMNOis ignored if eitherOPAMCONFIRMLEVELorOPAMYESis set.OPAMNOAGGREGATEβ withopam admin check, don't aggregate packages.OPAMNOASPCUDβ Deprecated.OPAMNOAUTOUPGRADEβ disables automatic internal upgrade of repositories in an earlier format to the current one, on 'update' or 'init'.OPAMNOCHECKSUMSβ enables option--no-checksumswhen available.OPAMNODEPEXTSβ disables system dependencies handling, see option--no-depexts.OPAMNOENVNOTICEβ Internal.OPAMNOSELFUPGRADEβ see option--no-self-upgrade.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.OPAMPREPROβ set this to false to disable CUDF preprocessing. less efficient, but might help debugging 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 operation are done in-memory, no I/O for scanning the repository. iconic, honestly β¨OPAMREQUIRECHECKSUMSβ enables option--require-checksumswhen available (e.g. foropam install).OPAMRETRIESβ sets the number of tries before failing downloads.OPAMREUSEBUILDDIRβ see option--reuse-build-dir.OPAMROOTβ see option--root. this is automatically set byopam env --root=DIR --set-root.OPAMROOTISOKβ don't complain when running as root.OPAMSAFEβ see option--safe.OPAMSHOWβ see option--show.OPAMSKIPUPDATEβ see option--skip-updates.OPAMSKIPVERSIONCHECKSβ bypasses some version checks. Unsafe, for compatibility testing only.OPAMSOLVERALLOWSUBOPTIMALβ (defaulttrue) allows some solvers to still return a solution when they reach timeout; while the solution remains assured to be consistent, there is no guarantee in this case that it fits the expected optimisation criteria. iftrue, opam will continue with a warning; iffalse, a timeout is an error. currently only thebuiltin-z3backend handles this degraded case.OPAMSOLVERTIMEOUTβ change the time allowance of the solver. default is60.0, set to0for unlimited. note that all solvers may not support this option.OPAMSOLVERTOLERANCEβ changes the tolerance towards the solver choosing an unoptimized solution (i.e. might pull outdated packages). typical values range from0.0(best solution known to the solver) to1.0(unoptimized solution). default is0.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.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.).OPAMSWITCHβ see option--switch. automatically set byopam env --switch=SWITCH --set-switch.OPAMUNLOCKBASEβ see install option--unlock-base.OPAMUPGRADECRITERIAβ specifies user preferences for dependency solving when performing an upgrade. overridesOPAMCRITERIAin upgrades if both are set. see also option--criteria.OPAMUSEINTERNALSOLVERβ see option--use-internal-solver.OPAMUSEOPENSSLβ Removed in 2.2.OPAMUTF8β use UTF8 characters in output (one of always, never or auto). by defaultauto, which is determined from the locale.OPAMUTF8MSGSβ use extended UTF8 characters (camels) in opam messages πͺ impliesOPAMUTF8. this is set by default on macOS only.OPAMVALIDATIONHOOKβ if set, uses the%{hook}%command to validate an opam repository update.OPAMVERBOSEβ see option--verbose.OPAMVERBOSEONβ see option--verbose-on.OPAMVERSIONLAGPOWERβ do not use. π that's it. that's the whole description.OPAMWITHDEVSETUPβ see install option--with-dev-setup.OPAMWITHDOCβ see install option--with-doc.OPAMWITHTESTβ see install option--with-test.OPAMWORKINGDIRβ see option--working-dir.OPAMYESβ see options--yesand--confirm-level.OPAMYEShas priority overOPAMNOand is ignored ifOPAMCONFIRMLEVELis set.OPAMVAR_varβ overrides the contents of the variable var when substituting%{var}%strings inopamfiles.OPAMVAR_package_varβ overrides the contents of the variable package:var when substituting%{package:var}%strings inopamfiles.
π CLI VERSION π
okay this one is important so put your phone down for a sec.
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 for the nerds writing scripts β blog posts or other documentation can benefit too, because it prevents information from becoming stale. slay.
although opam only supports roots (~/.opam/) for the current version, it does provide backwards compatibility for its command-line interface.
since CLI version support was only added in opam 2.1, use OPAMCLI to select 2.0 support (as opam 2.0 will just ignore it), and --cli=2.1 for 2.1 (or later) versions, since an environment variable controlling the parsing of syntax is brittle. 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. π
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.
π EXIT STATUS π
ok so here's the tea on exit codes, bestie β every program hands back a lil number when it's done and opam is no exception, so let's decode the whole alphabet soup π«Ά
BIG exception first, don't skip this one!! unlike literally everything else below, the exec command is built different: it returns 127 if the command wasn't found or just couldn't be executed at all, and otherwise it returns the command's own exit value. that's the whole rule. iconic behavior honestly β¨
here's the full menu of exit codes:
0β Success π ortruewhen it's a boolean query. win is win.1β False. this one shows up when a boolean return value is what's expected, like when you're running with--check, or for queries likeopam lint.2β Bad command-line arguments π, or command-line arguments that point at an invalid context (think: a file that doesn't follow the expected format).5β Not found. you asked for something β a package, a version, a repository, whatever β and it Could Not Be Found. it's giving missing girl era π10β Aborted. the operation needed confirmation and you (or something) didn't give it.15β Could not acquire the locks required for the operation. locked out, not locked in π20β There's no solution to the user request. this can happen when you ask to install two incompatible packages, for example. the math said no, bestie.30β Error in package definition, or in other metadata files. heads up: using--strictraises this error more often π31β Package script error. some package operations were unsuccessful. this may be an error in the packages, or an incompatibility with your system. also: this can be a partial error.40β Sync error. couldn't fetch some remotes from the network. also can be a partial error π50β Configuration error. opam or system configuration doesn't allow the operation, and it needs fixing. bestie the config is the problem not you π60β Solver failure. the solver failed to return a sound answer. this can be because of a broken external solver, or an error in solver configuration.99β Internal error. something went wrong, and it's likely due to a bug in opam itself. not your fault babes, that's a them problem π130β User interrupt.SIGINTwas received, generally because the user pressed Ctrl+C. we've all been there π
and then there's this lil extra batch of status codes, keeping the same energy:
0on success.123on indiscriminate errors reported on standard error.124on command line parsing errors.125on unexpected internal errors (bugs).
π FURTHER DOCUMENTATION π
want more? the docs live at https://opam.ocaml.org/doc β go drink from the firehose, you got this π
π AUTHORS π
these are the icons who built this, show some respect to the whole squad:
- 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 admin(1) β the parent page, the main character, go read it next πΈ
π BUGS π
found something cursed? check the bug reports at https://github.com/ocaml/opam/issues β no cap, they actually want to hear about it π
and that's the whole page bestie!! π this was Opam admin 2.6.1, page OPAM ADMIN-ADD-CONSTRAINT(1) β literally the full manual page, start to finish, and you read all of it. ate. periodt. go forth and constrain some packages responsibly β¨π¦π
π¦ where this page comes from
- arch rolling: opam 2.6.1-1 Β· LGPL-2.1-only
- fedora 44: opam 2.6.1-1.fc44 Β· LGPL-2.1-only WITH OCaml-LGPL-linking-exception
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms