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

Upgrades from opam 2.1.0~beta4 to 2.1.0~rc2 remove the opam config file #4748

Closed
kit-ty-kate opened this issue Jul 9, 2021 · 0 comments · Fixed by #4750
Closed

Upgrades from opam 2.1.0~beta4 to 2.1.0~rc2 remove the opam config file #4748

kit-ty-kate opened this issue Jul 9, 2021 · 0 comments · Fixed by #4750
Milestone

Comments

@kit-ty-kate
Copy link
Member

kit-ty-kate commented Jul 9, 2021

FROM ocaml/opam
RUN opam --version # 2.0.8
RUN opam switch
RUN opam list
RUN bash -c 'echo | sh <(curl -sL https://raw.githubusercontent.com/ocaml/opam/2.1.0-rc/shell/install.sh) --dev'
RUN opam --version # 2.1.0~beta4
RUN opam switch
RUN opam list
RUN bash -c 'echo | sh <(curl -sL https://raw.githubusercontent.com/ocaml/opam/master/shell/install.sh) --dev'
RUN opam --version # 2.1.0~rc2
RUN opam switch # ????
RUN opam list # ????

Everything goes well until the 4 last commands:

Step 9/12 : RUN bash -c 'echo | sh <(curl -sL https://raw.githubusercontent.com/ocaml/opam/master/shell/install.sh) --dev'
 ---> Running in 25d672d35b24
## Downloading opam 2.1.0~rc2 for linux on x86_64...
## Downloaded.
## Where should it be installed ? [/usr/bin] Write access to /usr/bin required, using 'sudo'.
Command: mv /usr/bin/opam /usr/bin/opam.2.1.0~beta4
## /usr/bin/opam backed up as opam.2.1.0~beta4
## Backing up /home/opam/.opam to .opam.2.1.0~beta4 (this may take a while)
## /home/opam/.opam backed up as .opam.2.1.0~beta4
Write access to /usr/bin required, using 'sudo'.
Command: install -m 755 /tmp/opam-2.1.0-rc2-x86_64-linux /usr/bin/opam
## opam 2.1.0~rc2 installed to /usr/bin
## Converting the opam root format & updating
Configuring from /home/opam/.opamrc and then from built-in defaults.
Checking for available remotes: [ERROR] In /home/opam/.opam/config:
        unsupported or missing file format version; should be 2.0 or older [skipped]

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.

This version of opam requires an update to the layout of /home/opam/.opam from version 2.0 to version 2.1, which can't be reverted.
You may want to back it up before going further.

Continue? [Y/n] y
Format upgrade done.

<><> Updating repositories ><><><><><><><><><><><><><><><><><><><><><><><><><><>
[default] no changes from file:///home/opam/opam-repository
## Run this script again with '--restore 2.1.0~beta4' to revert.
Removing intermediate container 25d672d35b24
 ---> b02b09b4e36c
Step 10/12 : RUN opam --version # 2.1.0~rc2
 ---> Running in dba4eb5dc8b9
2.1.0~rc2
Removing intermediate container dba4eb5dc8b9
 ---> 102e94473826
Step 11/12 : RUN opam switch # ????
 ---> Running in a0c5d1ad38e7
#  switch  compiler  description
Removing intermediate container a0c5d1ad38e7
 ---> 40cf093b1ec3
Step 12/12 : RUN opam list # ????
 ---> Running in a04b5dd02d7f
# No matches found

Looking inside the ~/.opam directory reveals a mostly unchanged opam root, however ~/.opam/config does not have any switches:

opam@92a8720d34dd:~$ diff -ru .opam.2.1.0~beta4/ .opam
diff -ru .opam.2.1.0~beta4/config .opam/config
--- .opam.2.1.0~beta4/config	2021-07-09 14:37:34.000000000 +0100
+++ .opam/config	2021-07-09 14:48:14.688880274 +0100
@@ -1,17 +1,43 @@
-opam-version: "2.1"
-repositories: "default"
-installed-switches: "4.12"
-switch: "4.12"
-jobs: 31
+opam-version: "2.0"
+opam-root-version: "2.1"
 download-jobs: 3
 eval-variables: [
-  sys-ocaml-version
-  ["ocamlc" "-vnum"]
-  "OCaml version present on your system independently of opam, if any"
+  [
+    sys-ocaml-version
+    ["ocamlc" "-vnum"]
+    "OCaml version present on your system independently of opam, if any"
+  ]
+  [
+    sys-ocaml-arch
+    [
+      "sh"
+      "-c"
+      "ocamlc -config 2>/dev/null | tr -d '\\r' | grep '^architecture: ' | sed -e 's/.*: //' -e 's/i386/i686/' -e 's/amd64/x86_64/'"
+    ]
+    "Target architecture of the OCaml compiler present on your system"
+  ]
+  [
+    sys-ocaml-cc
+    [
+      "sh"
+      "-c"
+      "ocamlc -config 2>/dev/null | tr -d '\\r' | grep '^ccomp_type: ' | sed -e 's/.*: //'"
+    ]
+    "Host C Compiler type of the OCaml compiler present on your system"
+  ]
+  [
+    sys-ocaml-libc
+    [
+      "sh"
+      "-c"
+      "ocamlc -config 2>/dev/null | tr -d '\\r' | grep '^os_type: ' | sed -e 's/.*: //' -e 's/Win32/msvc/' -e '/^msvc$/!s/.*/libc/'"
+    ]
+    "Host C Runtime Library type of the OCaml compiler present on your system"
+  ]
 ]
-default-compiler: [
-  "ocaml-system" {>= "4.02.3"}
-  "ocaml-base-compiler"
+default-compiler: ["ocaml-system" "ocaml-base-compiler"]
+default-invariant: [
+  "ocaml" {>= "4.05.0"}
 ]
 depext: true
 depext-run-installs: true
diff -ru .opam.2.1.0~beta4/opam-init/env_hook.sh .opam/opam-init/env_hook.sh
--- .opam.2.1.0~beta4/opam-init/env_hook.sh	2021-07-09 14:37:34.000000000 +0100
+++ .opam/opam-init/env_hook.sh	2021-07-09 14:48:14.688880274 +0100
@@ -1,7 +1,7 @@
 OPAMNOENVNOTICE=true; export OPAMNOENVNOTICE;
 _opam_env_hook() {
  local previous_exit_status=$?;
- eval $(opam env --shell=bash --readonly 2> /dev/null);
+ eval $(opam env --shell=bash --readonly 2> /dev/null <&- );
  return $previous_exit_status;
 };
 if ! [[ "$PROMPT_COMMAND" =~ _opam_env_hook ]]; then
diff -ru .opam.2.1.0~beta4/opam-init/env_hook.zsh .opam/opam-init/env_hook.zsh
--- .opam.2.1.0~beta4/opam-init/env_hook.zsh	2021-07-09 14:37:34.000000000 +0100
+++ .opam/opam-init/env_hook.zsh	2021-07-09 14:48:14.688880274 +0100
@@ -1,6 +1,6 @@
 OPAMNOENVNOTICE=true; export OPAMNOENVNOTICE;
 _opam_env_hook() {
-    eval $(opam env --shell=zsh --readonly 2> /dev/null);
+    eval $(opam env --shell=zsh --readonly 2> /dev/null <&-);
 }
 typeset -ag precmd_functions;
 if [[ -z ${precmd_functions[(r)_opam_env_hook]} ]]; then
diff -ru .opam.2.1.0~beta4/opam-init/hooks/sandbox.sh .opam/opam-init/hooks/sandbox.sh
--- .opam.2.1.0~beta4/opam-init/hooks/sandbox.sh	2021-07-09 14:37:34.000000000 +0100
+++ .opam/opam-init/hooks/sandbox.sh	2021-07-09 14:48:14.684880247 +0100
@@ -11,10 +11,12 @@
     exit 10
 fi
 
-ARGS=(--unshare-net --new-session)
+# --new-session requires bubblewrap 0.1.7
+# --die-with-parent requires bubblewrap 0.1.8
+ARGS=(--unshare-net --new-session --die-with-parent)
 ARGS=("${ARGS[@]}" --proc /proc --dev /dev)
-ARGS=("${ARGS[@]}" --bind "${TMPDIR:-/tmp}" /tmp)
-ARGS=("${ARGS[@]}" --setenv TMPDIR /tmp --setenv TMP /tmp --setenv TEMPDIR /tmp --setenv TEMP /tmp)
+ARGS=("${ARGS[@]}" --setenv TMPDIR /opam-tmp --setenv TMP /opam-tmp --setenv TEMPDIR /opam-tmp --setenv TEMP /opam-tmp)
+ARGS=("${ARGS[@]}" --tmpfs /opam-tmp)
 ARGS=("${ARGS[@]}" --tmpfs /run)
 
 add_mount() {
@@ -55,7 +57,7 @@
 # use OPAM_USER_PATH_RO variable to add them
 # the OPAM_USER_PATH_RO format is the same as PATH
 # ie: export OPAM_USER_PATH_RO=/nix/store:/rw/usrlocal
-add_sys_mounts /usr /bin /lib /lib32 /lib64 /etc /opt /home /var
+add_sys_mounts /usr /bin /lib /lib32 /lib64 /etc /opt /home /var /tmp
 
 # C compilers using `ccache` will write to a shared cache directory
 # that remain writeable. ccache seems widespread in some Fedora systems.
@@ -76,15 +78,20 @@
 }
 
 add_dune_cache_mount() {
-  u_cache=${XDG_CACHE_HOME:-$HOME/.cache}
-  u_dune_cache=$u_cache/dune
-  cache=$(readlink -m "$u_cache")
-  dune_cache=$cache/dune
-  dune_cache=$(readlink -m "$u_dune_cache")
+  local u_cache=${XDG_CACHE_HOME:-$HOME/.cache}
+  local u_dune_cache=$u_cache/dune
+  local cache=$(readlink -m "$u_cache")
+  local dune_cache=$cache/dune
+  local dune_cache=$(readlink -m "$u_dune_cache")
   mkdir -p "${dune_cache}"
   add_mount rw "$u_dune_cache" "$dune_cache"
 }
 
+# mount unusual path in ro
+if  [ -n "${OPAM_USER_PATH_RO-}" ]; then
+   add_mounts ro $(echo "${OPAM_USER_PATH_RO}" | sed 's|:| |g')
+fi
+
 # When using opam variable that must be defined at action time, add them also
 # at init check in OpamAuxCommands.check_and_revert_sandboxing (like
 # OPAM_SWITCH_PREFIX).
@@ -92,32 +99,20 @@
 COMMAND="$1"; shift
 case "$COMMAND" in
     build)
-        # mount unusual path in ro
-        if  [ -n "${OPAM_USER_PATH_RO-}" ]; then
-           add_mounts ro $(echo "${OPAM_USER_PATH_RO}" | sed 's|:| |g')
-        fi
         add_mounts ro "$OPAM_SWITCH_PREFIX"
         add_mounts rw "$PWD"
         add_ccache_mount
         add_dune_cache_mount
         ;;
     install)
-        # mount unusual path in ro
-        if  [ -n "${OPAM_USER_PATH_RO-}" ]; then
-           add_mounts ro  $(echo "${OPAM_USER_PATH_RO}" | sed 's|:| |g')
-        fi
         add_mounts rw "$OPAM_SWITCH_PREFIX"
         add_mounts ro "$OPAM_SWITCH_PREFIX/.opam-switch"
         add_mounts rw "$PWD"
         ;;
     remove)
-        # mount unusual path in ro
-        if  [ -n "${OPAM_USER_PATH_RO-}" ]; then
-           add_mounts ro $(echo "${OPAM_USER_PATH_RO}" | sed 's|:| |g')
-        fi
         add_mounts rw "$OPAM_SWITCH_PREFIX"
         add_mounts ro "$OPAM_SWITCH_PREFIX/.opam-switch"
-        if [ "X${PWD#$OPAM_SWITCH_PREFIX}/.opam-switch/" != "X${PWD}" ]; then
+        if [ "X${PWD#$OPAM_SWITCH_PREFIX/.opam-switch/}" != "X${PWD}" ]; then
           add_mounts rw "$PWD"
         fi
         ;;
@@ -127,4 +122,5 @@
 esac
 
 # Note: we assume $1 can be trusted, see https://github.com/projectatomic/bubblewrap/issues/259
+# As of now we are compatible up to 0.1.8, '--' can be added here when we require >= 0.3.0
 exec bwrap "${ARGS[@]}" "$@"
diff -ru .opam.2.1.0~beta4/opam-init/hooks/sandbox.sh.hash .opam/opam-init/hooks/sandbox.sh.hash
--- .opam.2.1.0~beta4/opam-init/hooks/sandbox.sh.hash	2021-07-09 14:37:34.000000000 +0100
+++ .opam/opam-init/hooks/sandbox.sh.hash	2021-07-09 14:48:14.684880247 +0100
@@ -1 +1 @@
-md5=c51ece9376c419167196f4438f0babcd
\ No newline at end of file
+md5=0ff6dc2bfbe090e3944ce2674aa21357
\ No newline at end of file
Only in .opam.2.1.0~beta4/plugins/bin: opam-depext
Binary files .opam.2.1.0~beta4/repo/default.tar.gz and .opam/repo/default.tar.gz differ
diff -ru .opam.2.1.0~beta4/repo/repos-config .opam/repo/repos-config
--- .opam.2.1.0~beta4/repo/repos-config	2021-07-09 14:39:03.000000000 +0100
+++ .opam/repo/repos-config	2021-07-09 14:49:27.877377522 +0100
@@ -1 +1,2 @@
+opam-version: "2.0"
 repositories: "default" {"file:///home/opam/opam-repository"}
Only in .opam/repo: state-21F1960C.cache
Only in .opam.2.1.0~beta4/repo: state.cache

Hit by @NathanReb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants