Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Installing opam does not seem to install switch #4820

Closed
Zarickan opened this issue Aug 31, 2021 · 10 comments
Closed

Installing opam does not seem to install switch #4820

Zarickan opened this issue Aug 31, 2021 · 10 comments

Comments

@Zarickan
Copy link

Hi,

I am trying to install opam on Debian, to install I run:

sudo apt install opam
opam init
eval $(opam env)

All complete without errors or warnings, the output from opam init is:

$ opam init

<><> 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 bash configuration by adding the following line to ~/.profile:

    test -r /home/X/.opam/opam-init/init.sh && . /home/X/.opam/opam-init/init.sh > /dev/null 2> /dev/null || true

  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 ~/.profile? [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:
  ~/.profile is already up-to-date.
[NOTE] Make sure that ~/.profile is well sourced in your ~/.bashrc.

However, if I try to install something with opam install ... I get the following error:

$ opam install opam-depext
[ERROR] No switch is currently set. Please use 'opam switch' to set or install a switch

Is opam not supposed to create a switch on install?

I tried to create a switch, but it seems I have hundreds of different compilers to choose from, which one should I select for the switch?

Opam config report:

# opam config report
# opam-version      2.0.3
# self-upgrade      no
# system            arch=x86_64 os=linux os-distribution=debian os-version=10
[ERROR] No switch is currently set. Please use 'opam switch' to set or install a switch
# read-state        OpamStd.OpamSys.Exit(50)
@dra27
Copy link
Member

dra27 commented Aug 31, 2021

Assuming you haven't trimmed anything from that log, is OPAMBARE set in your environment? The log you've given above is exactly expect to see with opam init --bare or OPAMBARE=true opam init.

@dra27
Copy link
Member

dra27 commented Aug 31, 2021

Oh no, hang on - even with opam init --bare you should still see the initial repo sync. Have you used opam previously - it looks more like ~/.opam already existed. Assuming you're happy to start again, you can either rm -rf ~/.opam or rename it to something else and re-run opam init.

@Zarickan
Copy link
Author

After doing rm -rf ~/.opam I get this instead:

$ opam init
[NOTE] Will configure from built-in defaults.
Checking for available remotes: rsync and local, git, mercurial, darcs. Perfect!

<><> Fetching repository information ><><><><><><><><><><><><><><><><><><><><><>
[default] Initialised

<><> 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 bash configuration by adding the following line to ~/.profile:

    test -r /home/X/.opam/opam-init/init.sh && . /home/X/.opam/opam-init/init.sh > /dev/null 2> /dev/null || true

  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 ~/.profile? [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:
  ~/.profile is already up-to-date.
[NOTE] Make sure that ~/.profile is well sourced in your ~/.bashrc.


<><> Creating initial switch (ocaml-system>=4.02.3) <><><><><><><><><><><><><><>


<><> Gathering sources ><><><><><><><><><><><><><><><><><><><><><><><><><><><><>

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
∗ installed base-bigarray.base
∗ installed base-threads.base
∗ installed base-unix.base
[ERROR] The compilation of ocaml-system failed at "/home/X/.opam/opam-init/hooks/sandbox.sh build ocaml gen_ocaml_config.ml".

#=== ERROR while compiling ocaml-system.4.05.0 ================================#
# context     2.0.3 | linux/x86_64 |  | https://opam.ocaml.org#5c5a526e
# path        ~/.opam/default/.opam-switch/build/ocaml-system.4.05.0
# command     ~/.opam/opam-init/hooks/sandbox.sh build ocaml gen_ocaml_config.ml
# exit-code   1
# env-file    /tmp/opam-xxx-2354/ocaml-system-2354-6aa130.env
# output-file /tmp/opam-xxx-2354/ocaml-system-2354-6aa130.out
### output ###
# bwrap: Creating new namespace failed: Permission denied



<><> Error report <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
┌─ The following actions failed
│ λ build ocaml-system 4.05.0
└─
┌─ The following changes have been performed (the rest was aborted)
│ ∗ install base-bigarray base
│ ∗ install base-threads  base
│ ∗ install base-unix     base
└─
# Run eval $(opam env) to update the current shell environment
Switch initialisation failed: clean up? ('n' will leave the switch partially installed) [Y/n] y

@kit-ty-kate
Copy link
Member

Are you running this inside of a docker container or similar container/sandbox?

@Zarickan
Copy link
Author

This is in Debian on WSL2 on Windows 10 version 20H2

@dra27
Copy link
Member

dra27 commented Aug 31, 2021

Are you certain that's WSL2 and not WSL1? (wsl -l -v from a command prompt)

@Zarickan
Copy link
Author

You are right it was still running on version 1. After upgrading to version 2 it seems to work, is opam not compatible with WSL1?

@kit-ty-kate
Copy link
Member

is opam not compatible with WSL1?

opam itself should be. It's just its sandboxing mecanism (bubblewrap) that is not. See ocaml/opam-repository#12050 for more info.

I'm guessing this issue can now be closed. Please reopen if I'm mistaken. I've opened #4821 to make opam init less confusing per your setup in your original comment.

Using opam install ... to setup a switch would be a bit surprising in my opinion as opam would have to guess what the user wants (global switch vs. local switch, and with which OCaml version, OCaml system vs. ocaml-base-compiler, etc..)

Thanks for your time!

@Zarickan
Copy link
Author

Thank you for helping.

Perhaps this would be a candidate for something to include somewhere in the installation documentation (perhaps on the website). At least it wasn't clear to me that this error was because of WSL1 and I couldn't find any documentation anywhere stating that opam is not compatible with WSL1.

@kit-ty-kate
Copy link
Member

Mmh, that's fair. I've opened #4822 for that purpose. Thanks for the suggestion.

I believe more recent versions of opam (2.0.3 is 2 and a half years old) would have caught that in the opam init step as it tests if the sandbox works and shown a useful error message:

"Do you want to disable it? Note that this will result in \

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

No branches or pull requests

3 participants