summary refs log tree commit diff
path: root/pkgs/build-support/docker
diff options
context:
space:
mode:
authorRobert Hensing <robert@roberthensing.nl>2021-05-25 15:04:45 +0200
committerRobert Hensing <robert@roberthensing.nl>2021-05-26 15:11:42 +0200
commit5259d66b7487b94233821e28aafb0683ae3f1df6 (patch)
treef35e0515750525e1e0a698e0cdcd73b72fbf7f9b /pkgs/build-support/docker
parent69de7cc12abfa1d0434750e5d346c299992a57ec (diff)
downloadnixpkgs-5259d66b7487b94233821e28aafb0683ae3f1df6.tar
nixpkgs-5259d66b7487b94233821e28aafb0683ae3f1df6.tar.gz
nixpkgs-5259d66b7487b94233821e28aafb0683ae3f1df6.tar.bz2
nixpkgs-5259d66b7487b94233821e28aafb0683ae3f1df6.tar.lz
nixpkgs-5259d66b7487b94233821e28aafb0683ae3f1df6.tar.xz
nixpkgs-5259d66b7487b94233821e28aafb0683ae3f1df6.tar.zst
nixpkgs-5259d66b7487b94233821e28aafb0683ae3f1df6.zip
dockerTools: Allow omitting all store paths
Adds includeStorePaths, allowing the omission of the store paths.
You generally want to leave it on, but tooling may disable this
to insert the store paths more efficiently via other means, such
as bind mounting the host store.
Diffstat (limited to 'pkgs/build-support/docker')
-rw-r--r--pkgs/build-support/docker/default.nix12
-rw-r--r--pkgs/build-support/docker/examples.nix25
2 files changed, 36 insertions, 1 deletions
diff --git a/pkgs/build-support/docker/default.nix b/pkgs/build-support/docker/default.nix
index 5e66c81e4ff..5bbf1b63f2b 100644
--- a/pkgs/build-support/docker/default.nix
+++ b/pkgs/build-support/docker/default.nix
@@ -37,6 +37,10 @@
 
 let
 
+  inherit (lib)
+    optionals
+    ;
+
   mkDbExtraCommand = contents: let
     contentsList = if builtins.isList contents then contents else [ contents ];
   in ''
@@ -787,6 +791,10 @@ rec {
     # We pick 100 to ensure there is plenty of room for extension. I
     # believe the actual maximum is 128.
     maxLayers ? 100,
+    # Whether to include store paths in the image. You generally want to leave
+    # this on, but tooling may disable this to insert the store paths more
+    # efficiently via other means, such as bind mounting the host store.
+    includeStorePaths ? true,
   }:
     assert
       (lib.assertMsg (maxLayers > 1)
@@ -834,7 +842,9 @@ rec {
         '';
       };
 
-      closureRoots = [ baseJson ] ++ contentsList;
+      closureRoots = optionals includeStorePaths /* normally true */ (
+        [ baseJson ] ++ contentsList
+      );
       overallClosure = writeText "closure" (lib.concatStringsSep " " closureRoots);
 
       # These derivations are only created as implementation details of docker-tools,
diff --git a/pkgs/build-support/docker/examples.nix b/pkgs/build-support/docker/examples.nix
index 7dbee38feeb..de90eab3ea1 100644
--- a/pkgs/build-support/docker/examples.nix
+++ b/pkgs/build-support/docker/examples.nix
@@ -516,4 +516,29 @@ rec {
     bash
     layeredImageWithFakeRootCommands
   ];
+
+  helloOnRoot = pkgs.dockerTools.streamLayeredImage {
+    name = "hello";
+    tag = "latest";
+    contents = [
+      (pkgs.buildEnv {
+        name = "hello-root";
+        paths = [ pkgs.hello ];
+      })
+    ];
+    config.Cmd = [ "hello" ];
+  };
+
+  helloOnRootNoStore = pkgs.dockerTools.streamLayeredImage {
+    name = "hello";
+    tag = "latest";
+    contents = [
+      (pkgs.buildEnv {
+        name = "hello-root";
+        paths = [ pkgs.hello ];
+      })
+    ];
+    config.Cmd = [ "hello" ];
+    includeStorePaths = false;
+  };
 }