aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorPaul Bonaud <paul.bonaud@fretlink.com>2020-05-04 18:46:33 +0200
committerPaul Bonaud <paul.bonaud@fretlink.com>2020-05-04 19:11:05 +0200
commit3e331d51d19f4335fa7c2583ce855d7acc1ece21 (patch)
tree50bd6ae2133eb56c1e481eebb6eeedad95ad6aac
parent937d660cdc7b7b82cc6e75641ee6f21ff43e017a (diff)
downloaddocker-nix-3e331d51d19f4335fa7c2583ce855d7acc1ece21.tar.gz
docker-nix-3e331d51d19f4335fa7c2583ce855d7acc1ece21.tar.zst
docker-nix-3e331d51d19f4335fa7c2583ce855d7acc1ece21.zip
volume: no need to duplicate the initial nix store
This is a partial revert of #7 where we added a copy of the initial nix store to make sure it's not lost when we use a volume for the /nix mounting point in the container. However this was an unecessary duplication. The initial nix store is already present in the docker image and can be retrieved by using a “named” volume with `-v nix-store:/nix`, docker will copy the /nix path of the image inside a volume called `nix-store` on the host machine for us we don't need to it manually. Of course if mounting an empty directory from the host machine (with `-v /tmp/nix-store:/nix`) then the image won't boot (because docker will NOT copy the content of the /nix path inside the image into the /tmp/nix-store path of the host machine). This change drastically reduces the image size (basically /2 as we were duplicating the biggest source of disk space…) ``` REPOSITORY TAG IMAGE ID CREATED SIZE docker-nix 2.3.4-vol f74209e25515 About a minute ago 1.58GB docker-nix 2.3.4 61880484ceb1 12 minutes ago 835MB ``` Let's be 🍃 instead of ⛰️
-rw-r--r--alpine/Dockerfile3
-rw-r--r--debian/Dockerfile3
-rwxr-xr-xfiles/.profile3
3 files changed, 0 insertions, 9 deletions
diff --git a/alpine/Dockerfile b/alpine/Dockerfile
index 0e42345..1da307a 100644
--- a/alpine/Dockerfile
+++ b/alpine/Dockerfile
@@ -40,9 +40,6 @@ RUN nix-env -iA nixpkgs.glibcLocales
40 40
41# < Nix context as a volume 41# < Nix context as a volume
42# We want to be able to define /nix/store as a volume 42# We want to be able to define /nix/store as a volume
43# We thus need to "save" the current nix context to be able
44# to restore it at startup time
45RUN cp -R /nix /home/nixuser/initial-nix
46VOLUME ["/nix"] 43VOLUME ["/nix"]
47# Create bash profile 44# Create bash profile
48COPY --chown=nixuser:nixuser files/.profile ${HOME}/.profile 45COPY --chown=nixuser:nixuser files/.profile ${HOME}/.profile
diff --git a/debian/Dockerfile b/debian/Dockerfile
index 90b2e65..7e4eaea 100644
--- a/debian/Dockerfile
+++ b/debian/Dockerfile
@@ -40,9 +40,6 @@ RUN nix-env -iA nixpkgs.glibcLocales
40 40
41# < Nix context as a volume 41# < Nix context as a volume
42# We want to be able to define /nix/store as a volume 42# We want to be able to define /nix/store as a volume
43# We thus need to "save" the current nix context to be able
44# to restore it at startup time
45RUN cp -R /nix /home/nixuser/initial-nix
46VOLUME ["/nix"] 43VOLUME ["/nix"]
47# Create bash profile 44# Create bash profile
48COPY --chown=nixuser:nixuser files/.profile ${HOME}/.profile 45COPY --chown=nixuser:nixuser files/.profile ${HOME}/.profile
diff --git a/files/.profile b/files/.profile
index 68b4473..2fadec2 100755
--- a/files/.profile
+++ b/files/.profile
@@ -1,8 +1,5 @@
1#!/usr/bin/env bash 1#!/usr/bin/env bash
2 2
3# Copy initial saved nix context if the /nix is empty
4[ ! "$(ls -A /nix)" ] && cp -R ~/initial-nix/* /nix/
5
6# Source nix environment 3# Source nix environment
7nix_profile="/home/nixuser/.nix-profile/etc/profile.d/nix.sh" 4nix_profile="/home/nixuser/.nix-profile/etc/profile.d/nix.sh"
8# shellcheck source=/home/nixuser/.nix-profile/etc/profile.d/nix.sh 5# shellcheck source=/home/nixuser/.nix-profile/etc/profile.d/nix.sh