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

Support Nix depexts with opam env #5982

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 47 additions & 29 deletions .github/scripts/depexts/generate-actions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

set -eu

#for target in alpine archlinux centos debian fedora gentoo opensuse oraclelinux ubuntu; do
#for target in alpine archlinux centos debian fedora gentoo opensuse oraclelinux ubuntu nix; do
target=$1
dir=.github/actions/$target

mkdir -p $dir
mkdir -p "$dir"

### Generate the action
cat >$dir/action.yml << EOF
cat > "$dir/action.yml" << EOF
name: 'depexts-$target'
description: 'Test external dependencies handling for $target'
runs:
Expand All @@ -25,23 +25,23 @@ OCAML_CONSTRAINT=''

case "$target" in
alpine)
cat >$dir/Dockerfile << EOF
cat > "$dir/Dockerfile" << EOF
FROM alpine
RUN apk add $mainlibs $ocaml
RUN apk add g++
EOF
;;
archlinux)
# no automake
cat >$dir/Dockerfile << EOF
cat > "$dir/Dockerfile" << EOF
FROM archlinux
RUN pacman -Syu --noconfirm $mainlibs $ocaml gcc diffutils
EOF
;;
centos)
# CentOS 7 doesn't support OCaml 5 (GCC is too old)
OCAML_CONSTRAINT=' & < "5.0"'
cat >$dir/Dockerfile << EOF
cat > "$dir/Dockerfile" << EOF
FROM almalinux:9.4
RUN dnf install 'dnf-command(config-manager)' -y
RUN dnf config-manager --set-enabled crb
Expand All @@ -51,15 +51,15 @@ RUN sed -i 's/ID="almalinux"/ID="centos"/' /etc/os-release
EOF
;;
debian)
cat >$dir/Dockerfile << EOF
cat > "$dir/Dockerfile" << EOF
FROM debian
RUN apt update
RUN apt install -y $mainlibs $ocaml
RUN apt install -y g++
EOF
;;
fedora)
cat >$dir/Dockerfile << EOF
cat > "$dir/Dockerfile" << EOF
FROM fedora
RUN dnf install -y $mainlibs $ocaml diffutils
RUN dnf install -y gcc-c++
Expand All @@ -69,7 +69,7 @@ EOF
mainlibs=${mainlibs/git/dev-vcs\/git}
mainlibs=${mainlibs/tar/app-arch\/tar}
mainlibs=${mainlibs/bzip2/app-arch\/bzip2}
cat >$dir/Dockerfile << EOF
cat > "$dir/Dockerfile" << EOF
# name the portage image
FROM gentoo/portage as portage
# image is based on stage3
Expand All @@ -83,35 +83,41 @@ EOF
;;
opensuse)
# glpk-dev is installed manually because os-family doesn't handle tumbleweed
cat >$dir/Dockerfile << EOF
cat > "$dir/Dockerfile" << EOF
FROM opensuse/leap:15.3
RUN zypper --non-interactive install $mainlibs $ocaml diffutils gzip glpk-devel
RUN zypper --non-interactive install gcc-c++
EOF
;;
oraclelinux)
cat >$dir/Dockerfile << EOF
cat > "$dir/Dockerfile" << EOF
FROM oraclelinux:8
RUN yum install -y $mainlibs
RUN yum install -y gcc-c++
EOF
;;
ubuntu)
cat >$dir/Dockerfile << EOF
cat > "$dir/Dockerfile" << EOF
FROM ubuntu:20.04
RUN apt update
RUN apt install -y $mainlibs $ocaml
RUN apt install -y g++
EOF
;;
nix)
cat > "$dir/Dockerfile" << EOF
FROM nixos/nix
RUN nix-channel --update
RUN nix-env -iA nixpkgs.gnum4 nixpkgs.git nixpkgs.rsync nixpkgs.patch nixpkgs.bzip2 nixpkgs.gnumake nixpkgs.wget nixpkgs.ocaml nixpkgs.ocamlPackages.ocaml-compiler-libs nixpkgs.unzip nixpkgs.gcc nixpkgs.diffutils nixpkgs.patch nixpkgs.getconf nixpkgs.gnused
EOF
esac

OCAML_INVARIANT="\"ocaml\" {>= \"4.09.0\"$OCAML_CONSTRAINT}"

# Copy 2.1 opam binary from cache
cp binary/opam $dir/opam
cp binary/opam "$dir/opam"

cat >>$dir/Dockerfile << EOF
cat >> "$dir/Dockerfile" << EOF
RUN test -d /opam || mkdir /opam
ENV OPAMROOTISOK=1
ENV OPAMROOT=/opam/root
Expand All @@ -129,9 +135,8 @@ COPY entrypoint.sh /opam/entrypoint.sh
ENTRYPOINT ["/opam/entrypoint.sh"]
EOF


### Generate the entrypoint
cat >$dir/entrypoint.sh << EOF
cat > "$dir/entrypoint.sh" << EOF
#!/bin/sh
set -eux

Expand All @@ -144,10 +149,23 @@ cd /github/workspace
#git clone https://github.com/ocaml/opam --single-branch --branch 2.2 --depth 1 local-opam
#cd local-opam

opam install . --deps
eval \$(opam env)
/usr/bin/opam install . --deps
eval \$(/usr/bin/opam env)
./configure
make

EOF

if [ "$target" = nix ]; then
cat >> "$dir/entrypoint.sh" << EOF
./opam var --global os-family=nixos
./opam var --global os-distribution=nixos

EOF
fi


cat >> "$dir/entrypoint.sh" << EOF
./opam config report
./opam switch create confs --empty
EOF
Expand All @@ -156,42 +174,42 @@ EOF

DEPEXTS2TEST=""
test_depext () {
DEPEXTS2TEST="$DEPEXTS2TEST $@"
DEPEXTS2TEST="$DEPEXTS2TEST $*"
}

test_depext conf-gmp.4 conf-which.1

if [ $target != "gentoo" ]; then
if [ "$target" != gentoo ]; then
test_depext conf-autoconf.0.1
fi

# disable automake for centos, as os-family returns rhel
if [ $target != "centos" ] && [ $target != "gentoo" ] && [ $target != "opensuse" ]; then
if [ "$target" != centos ] && [ "$target" != gentoo ] && [ "$target" != opensuse ]; then
test_depext conf-automake.1
fi

# additionna
if [ $target != "oraclelinux" ] && [ $target != "xxx" ]; then
if [ "$target" != oraclelinux ] && [ "$target" != xxx ]; then
test_depext conf-dpkg.1 # gentoo
fi

# package with os-version check

if [ $target = "debian" ] || [ $target = "ubuntu" ]; then
if [ "$target" = debian ] || [ "$target" = ubuntu ]; then
test_depext conf-sundials.2
# conf-libgccjit.1 conf-rdkit.1
fi

if [ $target = "alpine" ]; then
if [ "$target" = alpine ]; then
test_depext conf-clang-format.1
# conf-pandoc.0.1
fi

if [ $target = "fedora" ]; then
if [ "$target" = fedora ]; then
test_depext conf-emacs.1
fi

if [ $target = "oraclelinux" ] || [ $target = "centos" ]; then
if [ "$target" = oraclelinux ] || [ "$target" = centos ]; then
test_depext conf-pkg-config.3
fi

Expand All @@ -203,7 +221,7 @@ if [ -z "$DEPEXTS2TEST" ]; then
exit 3
fi

cat >>$dir/entrypoint.sh << EOF
cat >> "$dir/entrypoint.sh" << EOF
ERRORS=""
test_depexts () {
for pkg in \$@ ; do
Expand All @@ -222,10 +240,10 @@ fi
EOF

# Test depexts update
cat >>$dir/entrypoint.sh << EOF
cat >> "$dir/entrypoint.sh" << EOF
./opam update --depexts || ERRORS="\$ERRORS opam-update-depexts"
EOF

chmod +x $dir/entrypoint.sh
chmod +x "$dir/entrypoint.sh"

#done
6 changes: 6 additions & 0 deletions .github/scripts/main/hygiene.sh
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,12 @@ else
(set +x; echo -e "shell/install.sh: \e[31mERROR\e[0m") 2>/dev/null
ERROR=1
fi
if shellcheck .github/scripts/depexts/generate-actions.sh ; then
(set +x; echo ".github/scripts/depexts/generate-actions.sh: OK") 2>/dev/null
else
(set +x; echo -e ".github/scripts/depexts/generate-actions.sh: \e[31mERROR\e[0m") 2>/dev/null
ERROR=1
fi
(set +x ; echo -en "::endgroup::check shell scripts using shellcheck\r") 2>/dev/null

exit $ERROR
18 changes: 18 additions & 0 deletions .github/workflows/depexts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,21 @@ jobs:
- name: depexts actions ubuntu
uses: ./.github/actions/ubuntu
id: depexts-ubuntu

depexts-nix:
needs: opam-cache
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: opam binary cache
uses: actions/cache@v3
with:
path: binary/opam
key: binary-${{ env.OPAMVERSION }}
- name: generate action
run: |
bash .github/scripts/depexts/generate-actions.sh nix
- name: depexts actions nix
uses: ./.github/actions/nix
id: depexts-nix
6 changes: 6 additions & 0 deletions master_changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ users)
* Relax lookup on OpenBSD to consider all installed packages [#6362 @semarie]
* Speedup the detection of available system packages with pacman and brew [#6324 @kit-ty-kate]

[NEW] Support providing external dependencies with Nix
* Always pass --no-version-check and --no-write-registry to Cygwin setup [#6046 @dra27]
* Use --quiet-mode noinput for the internal Cygwin installation (which is definitely a fully-specified command line) and --quiet-mode unattended for external Cygwin installations (in case the user does need to select something, e.g. a mirror) [#6046 @dra27]
* [BUG] Fix apt/debian lookup for installed packages [#6054 @rjbou]
* [NEW] Support providing external dependencies with Nix [#5982 @RyanGibb]

## Format upgrade

## Sandbox
Expand Down
13 changes: 9 additions & 4 deletions src/client/opamClient.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1602,9 +1602,10 @@ let update_with_init_config ?(overwrite=false) config init_config =

let check_for_sys_packages config system_packages =
if system_packages <> [] then
let ((missing, _) as set) =
let (missing, required, available) =
OpamSysInteract.packages_status config
(OpamSysPkg.Set.of_list system_packages)
~old_packages:OpamSysPkg.Set.empty
in
if not (OpamSysPkg.Set.is_empty missing) then
let vars = OpamFile.Config.global_variables config in
Expand All @@ -1613,8 +1614,11 @@ let check_for_sys_packages config system_packages =
|> OpamVariable.Map.of_list
in
(*Lazy.force header;*)
OpamSolution.print_depext_msg set;
OpamSolution.install_sys_packages ~confirm:true env config missing ()
OpamSolution.print_depext_msg (missing, available);
ignore
(OpamSolution.install_sys_packages
~confirm:true ~sys_packages:missing ~required
env config None)

let reinit ?(init_config=OpamInitDefaults.init_config()) ~interactive
?dot_profile ?update_config ?env_hook ?completion ?inplace
Expand Down Expand Up @@ -2348,7 +2352,8 @@ let install_t t ?ask ?(ignore_conflicts=false) ?(depext_only=false)
in
if depext_only then
(OpamSolution.install_depexts ~force_depext:true ~confirm:false t
(OpamSolver.all_packages solution)), None
~new_packages:(OpamSolver.all_packages solution)
~all_packages:t.installed), None
else
let add_roots =
match add_to_roots, deps_only with
Expand Down
Loading
Loading