@@ -316,14 +316,21 @@ rec {
316316 # Files to add to the layer.
317317 contents,
318318 baseJson,
319+ extraCommands,
319320 uid ? 0, gid ? 0,
320321 }:
321322 runCommand "${name}-customisation-layer" {
322323 buildInputs = [ jshon rsync tarsum ];
324+ inherit extraCommands;
323325 }
324326 ''
325327 cp -r ${contents}/ ./layer
326328
329+ if [[ -n $extraCommands ]]; then
330+ chmod ug+w layer
331+ (cd layer; eval "$extraCommands")
332+ fi
333+
327334 # Tar up the layer and throw it into 'layer.tar'.
328335 echo "Packing layer..."
329336 mkdir $out
@@ -494,6 +501,8 @@ rec {
494501 # Time of creation of the image. Passing "now" will make the
495502 # created date be the time of building.
496503 created ? "1970-01-01T00:00:01Z",
504+ # Optional bash script to run on the files prior to fixturizing the layer.
505+ extraCommands ? "", uid ? 0, gid ? 0,
497506 # Docker's lowest maximum layer limit is 42-layers for an old
498507 # version of the AUFS graph driver. We pick 24 to ensure there is
499508 # plenty of room for extension. I believe the actual maximum is
@@ -501,8 +510,6 @@ rec {
501510 maxLayers ? 24
502511 }:
503512 let
504− uid = 0;
505− gid = 0;
506513 baseName = baseNameOf name;
507514 contentsEnv = symlinkJoin { name = "bulk-layers"; paths = (if builtins.isList contents then contents else [ contents ]); };
508515
@@ -531,7 +538,7 @@ rec {
531538 name = baseName;
532539 contents = contentsEnv;
533540 baseJson = configJson;
534− inherit uid gid;
541+ inherit uid gid extraCommands;
535542 };
536543 result = runCommand "docker-image-${baseName}.tar.gz" {
537544 buildInputs = [ jshon pigz coreutils findutils jq ];