]> git.immae.eu Git - github/fretlink/docker-nix.git/blobdiff - alpine/Dockerfile
volume: no need to duplicate the initial nix store
[github/fretlink/docker-nix.git] / alpine / Dockerfile
index 952e3eadb8699f38ffe36a1b5402ace49c6f1f2d..1da307a8cdbcfe8f8cbd9b2d2bde14fe8fe551e5 100644 (file)
@@ -2,7 +2,7 @@
 FROM alpine
 
 ARG NIX_VERSION
-ENV NIX_VERSION ${NIX_VERSION:-2.1.3}
+ENV NIX_VERSION ${NIX_VERSION:-2.3.1}
 ARG LANG
 ENV LANG ${LANG:-"en_US.UTF-8"}
 
@@ -10,15 +10,17 @@ RUN addgroup -g 30000 -S nixbld \
     && for i in $(seq 1 30); do adduser -S -D -h /var/empty -g "Nix build user $i" -u $((30000 + i)) -G nixbld nixbld$i ; done \
     && adduser -D nixuser \
     && mkdir -m 0755 /nix && chown nixuser /nix \
-    && apk add --no-cache bash \
-    && rm -rf /var/cache/apk/*
+    && apk add --no-cache bash xz \
+    && rm -rf /var/cache/apk/* \
+    # sandboxing enabled by default since 2.2
+    && mkdir -p /etc/nix && echo 'sandbox = false' > /etc/nix/nix.conf
 
 USER nixuser
 ENV USER=nixuser
 ENV HOME="/home/nixuser"
 
-RUN cd && wget https://nixos.org/releases/nix/nix-$NIX_VERSION/nix-$NIX_VERSION-x86_64-linux.tar.bz2 \
-    && tar xjf nix-*-x86_64-linux.tar.bz2 \
+RUN cd && wget https://nixos.org/releases/nix/nix-$NIX_VERSION/nix-$NIX_VERSION-x86_64-linux.tar.xz \
+    && tar xJf nix-*-x86_64-linux.tar.xz \
     && ~/nix-*-x86_64-linux/install \
     && rm -rf ~/nix-*-*
 
@@ -27,15 +29,21 @@ RUN echo ". ${ENV}" >> ${HOME}/.profile
 # All subsequent "RUN" will use a login shell
 SHELL ["/usr/bin/env", "bash", "-l", "-c"]
 
-RUN nix-channel --add https://nixos.org/channels/nixpkgs-19.03-darwin nixpkgs \
+RUN nix-channel --add https://nixos.org/channels/nixpkgs-19.09-darwin nixpkgs \
     && nix-channel --add https://nixos.org/channels/nixpkgs-unstable unstable \
     && nix-channel --update
 
 # Propagate UTF8
 # https://github.com/NixOS/nix/issues/599#issuecomment-153885553
 # The same is hapenning with stack2nix
-RUN nix-env -iA nixpkgs.glibcLocales \
-    && echo "export LOCALE_ARCHIVE=$(nix-env --installed --no-name --out-path --query glibc-locales)/lib/locale/locale-archive" >> ${HOME}/.profile
+RUN nix-env -iA nixpkgs.glibcLocales
+
+# < Nix context as a volume
+# We want to be able to define /nix/store as a volume
+VOLUME ["/nix"]
+# Create bash profile
+COPY --chown=nixuser:nixuser files/.profile ${HOME}/.profile
+# />
 
 # Make sure to use "login" shell when running container
 ENTRYPOINT ["/usr/bin/env", "bash", "-l", "-c"]