summary refs log tree commit diff
path: root/pkgs/build-support/docker/default.nix
diff options
context:
space:
mode:
authorRyan Trinkle <ryan.trinkle@gmail.com>2017-04-23 09:45:21 -0400
committerRyan Trinkle <ryan.trinkle@gmail.com>2017-04-23 09:45:21 -0400
commitdce2c258ac33ee1cd3b3e852b36e1d8fa11f33a1 (patch)
tree9aef017953a310824d5960368a242ffd49440870 /pkgs/build-support/docker/default.nix
parent9f6baaa89a5428eac9c133a136faffc3ee5fd52d (diff)
downloadnixpkgs-dce2c258ac33ee1cd3b3e852b36e1d8fa11f33a1.tar
nixpkgs-dce2c258ac33ee1cd3b3e852b36e1d8fa11f33a1.tar.gz
nixpkgs-dce2c258ac33ee1cd3b3e852b36e1d8fa11f33a1.tar.bz2
nixpkgs-dce2c258ac33ee1cd3b3e852b36e1d8fa11f33a1.tar.lz
nixpkgs-dce2c258ac33ee1cd3b3e852b36e1d8fa11f33a1.tar.xz
nixpkgs-dce2c258ac33ee1cd3b3e852b36e1d8fa11f33a1.tar.zst
nixpkgs-dce2c258ac33ee1cd3b3e852b36e1d8fa11f33a1.zip
dockerTools: optionally preserve directory symlinks
In some cases, this seems to save a lot (>40%) of space.
Diffstat (limited to 'pkgs/build-support/docker/default.nix')
-rw-r--r--pkgs/build-support/docker/default.nix21
1 files changed, 17 insertions, 4 deletions
diff --git a/pkgs/build-support/docker/default.nix b/pkgs/build-support/docker/default.nix
index 7f63664dadd..8230eb69c29 100644
--- a/pkgs/build-support/docker/default.nix
+++ b/pkgs/build-support/docker/default.nix
@@ -233,6 +233,10 @@ rec {
     baseJson,
     # Files to add to the layer.
     contents ? null,
+    # When copying the contents into the image, preserve symlinks to
+    # directories (see `rsync -K`).  Otherwise, transform those symlinks
+    # into directories.
+    keepContentsDirlinks ? false,
     # Additional commands to run on the layer before it is tar'd up.
     extraCommands ? ""
   }:
@@ -247,7 +251,7 @@ rec {
         echo "Adding contents..."
         for item in $contents; do
           echo "Adding $item"
-          rsync -ak --chown=0:0 $item/ layer/
+          rsync -a${if keepContentsDirlinks then "K" else "k"} --chown=0:0 $item/ layer/
         done
       else
         echo "No contents to add to layer."
@@ -286,6 +290,10 @@ rec {
     runAsRoot,
     # Files to add to the layer. If null, an empty layer will be created.
     contents ? null,
+    # When copying the contents into the image, preserve symlinks to
+    # directories (see `rsync -K`).  Otherwise, transform those symlinks
+    # into directories.
+    keepContentsDirlinks ? false,
     # JSON containing configuration and metadata for this layer.
     baseJson,
     # Existing image onto which to append the new layer.
@@ -310,7 +318,7 @@ rec {
         echo "Adding contents..."
         for item in ${toString contents}; do
           echo "Adding $item..."
-          rsync -ak --chown=0:0 $item/ layer/
+          rsync -a${if keepContentsDirlinks then "K" else "k"} --chown=0:0 $item/ layer/
         done
       '';
 
@@ -372,6 +380,10 @@ rec {
     fromImageTag ? null,
     # Files to put on the image (a nix store path or list of paths).
     contents ? null,
+    # When copying the contents into the image, preserve symlinks to
+    # directories (see `rsync -K`).  Otherwise, transform those symlinks
+    # into directories.
+    keepContentsDirlinks ? false,
     # Docker config; e.g. what command to run on the container.
     config ? null,
     # Optional bash script to run on the files prior to fixturizing the layer.
@@ -397,11 +409,12 @@ rec {
         if runAsRoot == null
         then mkPureLayer {
           name = baseName;
-          inherit baseJson contents extraCommands;
+          inherit baseJson contents keepContentsDirlinks extraCommands;
         } else mkRootLayer {
           name = baseName;
           inherit baseJson fromImage fromImageName fromImageTag
-                  contents runAsRoot diskSize extraCommands;
+                  contents keepContentsDirlinks runAsRoot diskSize
+                  extraCommands;
         };
       result = runCommand "docker-image-${baseName}.tar.gz" {
         buildInputs = [ jshon pigz coreutils findutils ];