2
2
3
3
set -eu
4
4
5
- # for target in alpine archlinux centos debian fedora gentoo opensuse oraclelinux ubuntu; do
5
+ # for target in alpine archlinux centos debian fedora gentoo opensuse oraclelinux ubuntu nix ; do
6
6
target=$1
7
7
dir=.github/actions/$target
8
8
@@ -102,6 +102,12 @@ RUN apt install -y $mainlibs $ocaml
102
102
RUN apt install -y g++
103
103
EOF
104
104
;;
105
+ nix)
106
+ cat > $dir /Dockerfile << EOF
107
+ FROM nixos/nix
108
+ RUN nix-channel --update
109
+ RUN nix-env -i gnum4 git rsync patch bzip2 gnumake wget ocaml ocaml5.1.1-ocaml-compiler-libs unzip gcc diffutils patch getconf-glibc gnused
110
+ EOF
105
111
esac
106
112
107
113
OCAML_INVARIANT=" \" ocaml\" {>= \" 4.09.0\" $OCAML_CONSTRAINT }"
@@ -121,12 +127,34 @@ RUN echo 'default-invariant: [ $OCAML_INVARIANT ]' > /opam/opamrc
121
127
RUN /usr/bin/opam init --no-setup --disable-sandboxing --bare --config /opam/opamrc git+$OPAM_REPO #$OPAM_REPO_SHA
122
128
RUN echo 'archive-mirrors: "https://opam.ocaml.org/cache"' >> \$ OPAMROOT/config
123
129
RUN /usr/bin/opam switch create this-opam --formula='$OCAML_INVARIANT '
130
+ EOF
131
+
132
+ # we can't `nix-env -i binutils`
133
+ # https://github.com/NixOS/nix/issues/10587
134
+ if [ $target == " nix" ]; then
135
+ cat >> $dir /Dockerfile << EOF
136
+ RUN nix-shell -p binutils --run "/usr/bin/opam install opam-core opam-state opam-solver opam-repository opam-format opam-client --deps"
137
+ EOF
138
+ else
139
+ cat >> $dir /Dockerfile << EOF
124
140
RUN /usr/bin/opam install opam-core opam-state opam-solver opam-repository opam-format opam-client --deps
141
+ EOF
142
+ fi
143
+
144
+ cat >> $dir /Dockerfile << EOF
125
145
RUN /usr/bin/opam clean -as --logs
126
146
COPY entrypoint.sh /opam/entrypoint.sh
127
- ENTRYPOINT ["/opam/entrypoint.sh"]
128
147
EOF
129
148
149
+ if [ $target == " nix" ]; then
150
+ cat >> $dir /Dockerfile << EOF
151
+ ENTRYPOINT ["nix-shell", "-p", "binutils", "--run", "/opam/entrypoint.sh"]
152
+ EOF
153
+ else
154
+ cat >> $dir /Dockerfile << EOF
155
+ ENTRYPOINT ["/opam/entrypoint.sh"]
156
+ EOF
157
+ fi
130
158
131
159
# ## Generate the entrypoint
132
160
cat > $dir /entrypoint.sh << EOF
@@ -142,10 +170,23 @@ cd /github/workspace
142
170
#git clone https://github.com/ocaml/opam --single-branch --branch 2.2 --depth 1 local-opam
143
171
#cd local-opam
144
172
145
- opam install . --deps
146
- eval \$ (opam env)
173
+ /usr/bin/ opam install . --deps
174
+ eval \$ (/usr/bin/ opam env)
147
175
./configure
148
176
make
177
+
178
+ EOF
179
+
180
+ if [ $target == " nix" ]; then
181
+ cat >> $dir /entrypoint.sh << EOF
182
+ ./opam var --global os-family=nixos
183
+ ./opam var --global os-distribution=nixos
184
+
185
+ EOF
186
+ fi
187
+
188
+
189
+ cat >> $dir /entrypoint.sh << EOF
149
190
./opam config report
150
191
./opam switch create confs --empty
151
192
EOF
0 commit comments