ocaml / opam

opam is a source-based package manager. It supports multiple simultaneous compiler installations, flexible package constraints, and a Git-friendly development workflow.
https://opam.ocaml.org
Other
1.24k stars 357 forks source link

opam on M2 Mac returns permission denied error on wget when running opam init #5626

Closed sarahspak closed 1 year ago

sarahspak commented 1 year ago
# opam config report
# opam-version         2.1.5
# self-upgrade         no
# system               arch=arm64 os=macos os-distribution=homebrew os-version=13.4.1
[ERROR] No switch is currently set. Please use 'opam switch' to set or install a switch
# read-state           OpamStd.OpamSys.Exit(50)

Installed opam from Homebrew on my M2 Mac but I'm not able to run opam init.

> opam init -vvv --debug-level=3
00:00.033  CLI                    Parsing CLI version 2.1
No configuration file found, using built-in defaults.
00:00.037  CLIENT                 INIT
Checking for available remotes: rsync and local, git.
  - you won't be able to use mercurial repositories unless you install the hg command on your system.
  - you won't be able to use darcs repositories unless you install the darcs command on your system.

00:00.042  SYSTEM                 mkdir /Users/sp/.opam
00:00.042  SYSTEM                 mkdir /Users/sp/.opam/opam-init
00:00.042  SYSTEM                 mkdir /Users/sp/.opam/opam-init/hooks
00:00.042  SYSTEM                 mkdir /var/folders/8l/369lcxws2hz0q_cn2532qz080000gn/T/opam-63516-801562
00:00.042  SYSTEM                 mkdir /var/folders/8l/369lcxws2hz0q_cn2532qz080000gn/T/opam-sp-63516
+ /Users/sp/.opam/opam-init/hooks/sandbox.sh "build" "sh" "-c" "echo SUCCESS >$TMPDIR/opam-sandbox-check-out && cat $TMPDIR/opam-sandbox-check-out; rm -f $TMPDIR/opam-sandbox-check-out"
- SUCCESS
00:00.152  SYSTEM                 [log-63516-cc83e7] (in 0.110s) /Users/sp/.opam/opam-init/hooks/sandbox.sh build sh -c echo SUCCESS >$TMPDIR/opam-sandbox-check-out && cat $TMPDIR/opam-sandbox-check-out; rm -f $TMPDIR/opam-sandbox-check-out
00:00.152  SYSTEM                 rmdir /var/folders/8l/369lcxws2hz0q_cn2532qz080000gn/T/opam-63516-801562
00:00.156  FILE(config)           Wrote /Users/sp/.opam/config in 0.000s
00:00.156  SYSTEM                 mkdir /Users/sp/.opam/repo
00:00.157  FILE(repos-config)     Wrote /Users/sp/.opam/repo/repos-config in 0.000s
00:00.157  CLIENT                 updating repository state
00:00.157  GSTATE                 LOAD-GLOBAL-STATE @ /Users/sp/.opam
00:00.157  SYSTEM                 LOCK /Users/sp/.opam/lock (none => read)
00:00.157  SYSTEM                 LOCK /Users/sp/.opam/config.lock (none => write)
00:00.157  FILE(config)           Read ~/.opam/config in 0.000s
00:00.157  RSTATE                 LOAD-REPOSITORY-STATE @ /Users/sp/.opam
00:00.157  SYSTEM                 LOCK /Users/sp/.opam/repo/lock (none => write)
00:00.157  FILE(repos-config)     Read ~/.opam/repo/repos-config in 0.000s
00:00.157  RSTATE                 No cache found
00:00.157  FILE(repo)             Cannot find /Users/sp/.opam/repo/default/repo
00:00.157  RSTATE                 loaded opam files from repo default in 0.000s
00:00.158  SYSTEM                 LOCK /Users/sp/.opam/repo/state-28AC8B61.cache (none => write)
00:00.158  CACHE(repository)      Writing the repository cache to ~/.opam/repo/state-28AC8B61.cache ...
00:00.158  CACHE(repository)      ~/.opam/repo/state-28AC8B61.cache written in 0.000s
00:00.158  SYSTEM                 LOCK /Users/sp/.opam/repo/state-28AC8B61.cache (write => none)

<><> Fetching repository information ><><><><><><><><><><><><><><><><><><><>  🐫
00:00.158  PARALLEL               Iterate over 1 task(s) with 3 process(es)
00:00.158  PARALLEL               Starting job 0 (worker 1/3): 0
00:00.158  REPOSITORY             update default from https://opam.ocaml.org
00:00.158  CURL                   pull-repo-update
00:00.158  SYSTEM                 mkdir /Users/sp/.opam/repo/default.new
00:00.158  SYSTEM                 mkdir /var/folders/8l/369lcxws2hz0q_cn2532qz080000gn/T/opam-63516-f908a3
00:00.158  PARALLEL               Next task in job 0: /opt/homebrew/opt/wget --content-disposition -t 3 -O /private/var/folders/8l/369lcxws2hz0q_cn2532qz080000gn/T/opam-63516-f908a3/index.tar.gz.part -U opam/2.1.5 -- https://opam.ocaml.org/index.tar.gz
'opam init -vvv --debug-level=3' failed.
Fatal error:
/opt/homebrew/bin/opam: "create_process" failed on /opt/homebrew/opt/wget: Permission denied

Happy to provide any other information.

sarahspak commented 1 year ago

Oddly, running opam init -vvv --debug-level=3 a second time works, but running opam switch create doesn't work. See commands below

> opam init -vvv --debug-level=3
00:00.036  FILE(config)           Read ~/.opam/config in 0.000s
00:00.036  CLI                    Parsing CLI version 2.1

<><> Required setup - please read <><><><><><><><><><><><><><><><><><><><><>  🐫

  In normal operation, opam only alters files within ~/.opam.

  However, to best integrate with your system, some environment variables
  should be set. If you allow it to, this initialisation step will update
  your zsh configuration by adding the following line to ~/.zshrc:

    [[ ! -r /Users/sp/.opam/opam-init/init.zsh ]] || source /Users/sp/.opam/opam-init/init.zsh  > /dev/null 2> /dev/null

  Otherwise, every time you want to access your opam installation, you will
  need to run:

    eval $(opam env)

  You can always re-run this setup with 'opam init' later.

Do you want opam to modify ~/.zshrc? [N/y/f]
(default is 'no', use 'f' to choose a different file) y
A hook can be added to opam's init scripts to ensure that the shell remains in sync with the opam environment when they are loaded. Set that up? [y/N] y

User configuration:
  ~/.zshrc is already up-to-date.
> opam switch create 4.14.0

[ERROR] No compiler matching `4.14.0' found, use `opam switch list-available' to see what is available, or use `--packages' to select packages explicitly.
> opam switch list-available ocaml-base-compiler
# Listing available compilers from repositories: default
# No matches found

and trying to add a default repository fails with a permission denied error on wget

> opam repository add default https://opam.ocaml.org --set-default -vvv --debug-level=3

00:00.034  FILE(config)           Read ~/.opam/config in 0.000s
00:00.034  CLI                    Parsing CLI version 2.1
00:00.034  GSTATE                 LOAD-GLOBAL-STATE @ /Users/sp/.opam
00:00.034  SYSTEM                 LOCK /Users/sp/.opam/lock (none => read)
00:00.034  FILE(config)           Read ~/.opam/config in 0.000s
00:00.034  RSTATE                 LOAD-REPOSITORY-STATE @ /Users/sp/.opam
00:00.034  SYSTEM                 LOCK /Users/sp/.opam/repo/lock (none => write)
00:00.035  FILE(repos-config)     Read ~/.opam/repo/repos-config in 0.000s
00:00.035  SYSTEM                 LOCK /Users/sp/.opam/repo/state-28AC8B61.cache (none => read)
00:00.035  CACHE(repository)      Loaded /Users/sp/.opam/repo/state-28AC8B61.cache in 0.000s
00:00.035  SYSTEM                 LOCK /Users/sp/.opam/repo/state-28AC8B61.cache (read => none)
00:00.035  RSTATE                 Cache found
00:00.035  REPOSITORY             repository-add
00:00.035  PARALLEL               Iterate over 1 task(s) with 3 process(es)
00:00.035  PARALLEL               Starting job 0 (worker 1/3): 0
00:00.035  REPOSITORY             update default from https://opam.ocaml.org
00:00.035  CURL                   pull-repo-update
00:00.035  SYSTEM                 mkdir /var/folders/8l/369lcxws2hz0q_cn2532qz080000gn/T/opam-93251-700a03
00:00.035  PARALLEL               Next task in job 0: /opt/homebrew/opt/wget --content-disposition -t 3 -O /private/var/folders/8l/369lcxws2hz0q_cn2532qz080000gn/T/opam-93251-700a03/index.tar.gz.part -U opam/2.1.5 -- https://opam.ocaml.org/index.tar.gz
00:00.036  SYSTEM                 LOCK /Users/sp/.opam/repo/lock (write => none)
00:00.036  SYSTEM                 LOCK /Users/sp/.opam/config.lock (none => none)
'opam repository add default https://opam.ocaml.org --set-default -vvv --debug-level=3' failed.
Fatal error:
/opt/homebrew/bin/opam: "create_process" failed on /opt/homebrew/opt/wget: Permission denied
sarahspak commented 1 year ago

my fault - for some reason /opt/homebrew/opt/ was higher in my path than /opt/homebrew/bin and I suspect that's why opam was trying to use /opt/homebrew/opt/wget.

Once I adjusted my PATH the issues went away, so will close the issue.

kit-ty-kate commented 1 year ago

It looks like this will be fixed anyway by https://github.com/ocaml/opam/pull/5606 in the upcoming opam 2.2.0