summary refs log tree commit diff
path: root/pkgs/build-support/docker
diff options
context:
space:
mode:
authorJaka Hudoklin <jakahudoklin@gmail.com>2018-12-25 23:04:16 +0100
committerJaka Hudoklin <jakahudoklin@gmail.com>2019-01-10 16:02:23 +0100
commit954cda5c9d05b105cdc7bc7871c7d124736545c6 (patch)
treea1eba1dbf7f3f026c07a43eb3a11cd1fa298492d /pkgs/build-support/docker
parente46ee5e09d702b9d1fbe963de8c0987d82e80540 (diff)
downloadnixpkgs-954cda5c9d05b105cdc7bc7871c7d124736545c6.tar
nixpkgs-954cda5c9d05b105cdc7bc7871c7d124736545c6.tar.gz
nixpkgs-954cda5c9d05b105cdc7bc7871c7d124736545c6.tar.bz2
nixpkgs-954cda5c9d05b105cdc7bc7871c7d124736545c6.tar.lz
nixpkgs-954cda5c9d05b105cdc7bc7871c7d124736545c6.tar.xz
nixpkgs-954cda5c9d05b105cdc7bc7871c7d124736545c6.tar.zst
nixpkgs-954cda5c9d05b105cdc7bc7871c7d124736545c6.zip
dockerTools: allow to pass extraCommands, uid and gid to buildLayeredImage
Diffstat (limited to 'pkgs/build-support/docker')
-rw-r--r--pkgs/build-support/docker/default.nix13
-rw-r--r--pkgs/build-support/docker/examples.nix1
2 files changed, 11 insertions, 3 deletions
diff --git a/pkgs/build-support/docker/default.nix b/pkgs/build-support/docker/default.nix
index f16cb7cec13..b6347f031f9 100644
--- a/pkgs/build-support/docker/default.nix
+++ b/pkgs/build-support/docker/default.nix
@@ -316,14 +316,21 @@ rec {
     # Files to add to the layer.
     contents,
     baseJson,
+    extraCommands,
     uid ? 0, gid ? 0,
   }:
     runCommand "${name}-customisation-layer" {
       buildInputs = [ jshon rsync tarsum ];
+      inherit extraCommands;
     }
     ''
       cp -r ${contents}/ ./layer
 
+      if [[ -n $extraCommands ]]; then
+        chmod ug+w layer
+        (cd layer; eval "$extraCommands")
+      fi
+
       # Tar up the layer and throw it into 'layer.tar'.
       echo "Packing layer..."
       mkdir $out
@@ -494,6 +501,8 @@ rec {
     # Time of creation of the image. Passing "now" will make the
     # created date be the time of building.
     created ? "1970-01-01T00:00:01Z",
+    # Optional bash script to run on the files prior to fixturizing the layer.
+    extraCommands ? "", uid ? 0, gid ? 0,
     # Docker's lowest maximum layer limit is 42-layers for an old
     # version of the AUFS graph driver. We pick 24 to ensure there is
     # plenty of room for extension. I believe the actual maximum is
@@ -501,8 +510,6 @@ rec {
     maxLayers ? 24
   }:
     let
-      uid = 0;
-      gid = 0;
       baseName = baseNameOf name;
       contentsEnv = symlinkJoin { name = "bulk-layers"; paths = (if builtins.isList contents then contents else [ contents ]); };
 
@@ -531,7 +538,7 @@ rec {
           name = baseName;
           contents = contentsEnv;
           baseJson = configJson;
-          inherit uid gid;
+          inherit uid gid extraCommands;
         };
       result = runCommand "docker-image-${baseName}.tar.gz" {
         buildInputs = [ jshon pigz coreutils findutils jq ];
diff --git a/pkgs/build-support/docker/examples.nix b/pkgs/build-support/docker/examples.nix
index 090bfafa085..41eddefe32b 100644
--- a/pkgs/build-support/docker/examples.nix
+++ b/pkgs/build-support/docker/examples.nix
@@ -155,6 +155,7 @@ rec {
   layered-image = pkgs.dockerTools.buildLayeredImage {
     name = "layered-image";
     tag = "latest";
+    extraCommands = ''echo "(extraCommand)" > extraCommands'';
     config.Cmd = [ "${pkgs.hello}/bin/hello" ];
     contents = [ pkgs.hello pkgs.bash pkgs.coreutils ];
   };