]> git.immae.eu Git - github/fretlink/docker-nix.git/blobdiff - debian/Dockerfile
Merge pull request #9 from ismaelbouyaf/use_dedicated_system
[github/fretlink/docker-nix.git] / debian / Dockerfile
index f7034d281a5a256a0fc6acc74763712f394d7db3..632a7412ce191a89fe8f74e98d7c3d5e4ed4905c 100644 (file)
@@ -2,7 +2,7 @@
 FROM debian:stable-slim
 
 ARG NIX_VERSION
-ENV NIX_VERSION ${NIX_VERSION:-2.2.1}
+ENV NIX_VERSION ${NIX_VERSION:-2.3.9}
 ARG LANG
 ENV LANG ${LANG:-"en_US.UTF-8"}
 
@@ -10,7 +10,7 @@ RUN addgroup --gid 30000 --system nixbld \
     && for i in $(seq 1 30); do adduser --system --disabled-password --home /var/empty --gecos "Nix build user $i" --uid $((30000 + i)) --ingroup nixbld nixbld$i ; done \
     && adduser --disabled-password nixuser \
     && mkdir -m 0755 /nix && chown nixuser /nix \
-    && apt update && apt install -y wget bzip2 \
+    && apt update && apt install -y wget xz-utils \
     && apt clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \
     # sandboxing enabled by default since 2.2
     && mkdir -p /etc/nix && echo 'sandbox = false' > /etc/nix/nix.conf
@@ -18,26 +18,32 @@ RUN addgroup --gid 30000 --system nixbld \
 USER nixuser
 ENV USER=nixuser
 ENV HOME="/home/nixuser"
+ENV NIX_SYSTEM_PATH="/nix/var/nix/profiles/system"
+ENV NIX_PROFILE="$HOME/nix-envs"
 
-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 \
-    && ~/nix-*-x86_64-linux/install \
+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_PROFILE="$NIX_SYSTEM_PATH" ~/nix-*-x86_64-linux/install \
     && rm -rf ~/nix-*-*
 
-ENV ENV="/home/nixuser/.nix-profile/etc/profile.d/nix.sh"
-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 \
-    && nix-channel --add https://nixos.org/channels/nixpkgs-unstable unstable \
+# Create bash profile
+COPY --chown=nixuser:nixuser files/.profile ${HOME}/.profile
+
+RUN nix-channel --add https://nixos.org/channels/nixos-unstable nixpkgs \
     && 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 -p "$NIX_SYSTEM_PATH" -iA nixpkgs.glibcLocales
+
+# < Nix context as a volume
+# We want to be able to define /nix/store as a volume
+VOLUME ["/nix"]
+# />
 
 # Make sure to use "login" shell when running container
 ENTRYPOINT ["/usr/bin/env", "bash", "-l", "-c"]