]> git.immae.eu Git - github/fretlink/docker-nix.git/commitdiff
Merge pull request #9 from ismaelbouyaf/use_dedicated_system
authorismaelbouyaf <ismael.bouya@fretlink.com>
Thu, 17 Dec 2020 14:07:41 +0000 (15:07 +0100)
committerGitHub <noreply@github.com>
Thu, 17 Dec 2020 14:07:41 +0000 (15:07 +0100)
Use dedicated system path for nix

alpine/Dockerfile
debian/Dockerfile
files/.profile

index 2c4ae1f812edd74afec73db38206086a49b257a2..db794af285bbbf9fc247343fffc5f58e51145fbb 100644 (file)
@@ -2,7 +2,7 @@
 FROM alpine
 
 ARG NIX_VERSION
-ENV NIX_VERSION ${NIX_VERSION:-2.3.4}
+ENV NIX_VERSION ${NIX_VERSION:-2.3.9}
 ARG LANG
 ENV LANG ${LANG:-"en_US.UTF-8"}
 
@@ -18,31 +18,31 @@ RUN addgroup -g 30000 -S 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.xz \
     && tar xJf nix-*-x86_64-linux.tar.xz \
-    && ~/nix-*-x86_64-linux/install \
+    && 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.09-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
+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"]
-# Create bash profile
-COPY --chown=nixuser:nixuser files/.profile ${HOME}/.profile
 # />
 
 # Make sure to use "login" shell when running container
index e5d410e52c882db4dfa30c2bd440ccf9dfcfa19f..632a7412ce191a89fe8f74e98d7c3d5e4ed4905c 100644 (file)
@@ -2,7 +2,7 @@
 FROM debian:stable-slim
 
 ARG NIX_VERSION
-ENV NIX_VERSION ${NIX_VERSION:-2.3.4}
+ENV NIX_VERSION ${NIX_VERSION:-2.3.9}
 ARG LANG
 ENV LANG ${LANG:-"en_US.UTF-8"}
 
@@ -18,31 +18,31 @@ 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.xz \
     && tar xJf nix-*-x86_64-linux.tar.xz \
-    && ~/nix-*-x86_64-linux/install \
+    && 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.09-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
+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"]
-# Create bash profile
-COPY --chown=nixuser:nixuser files/.profile ${HOME}/.profile
 # />
 
 # Make sure to use "login" shell when running container
index 2fadec23bba0e09dd90e119fb8756f5571cd9002..80d968e5670ebd46ece9cac66ebf8550358a4fab 100755 (executable)
@@ -1,11 +1,13 @@
 #!/usr/bin/env bash
 
 # Source nix environment
-nix_profile="/home/nixuser/.nix-profile/etc/profile.d/nix.sh"
-# shellcheck source=/home/nixuser/.nix-profile/etc/profile.d/nix.sh
+nix_profile="$NIX_SYSTEM_PATH/etc/profile.d/nix.sh"
+# shellcheck source=$NIX_SYSTEM_PATH/etc/profile.d/nix.sh
 [ -e "${nix_profile}" ] && . "${nix_profile}"
 
 # Propagate UTF8
 # https://github.com/NixOS/nix/issues/599#issuecomment-153885553
-LOCALE_ARCHIVE="$(nix-env --installed --no-name --out-path --query glibc-locales)/lib/locale/locale-archive"
+LOCALE_ARCHIVE="$NIX_SYSTEM_PATH/lib/locale/locale-archive"
 export LOCALE_ARCHIVE
+
+PATH="$NIX_PROFILE/bin:$PATH:$NIX_SYSTEM_PATH/bin"