summary refs log tree commit diff
path: root/pkgs/build-support
diff options
context:
space:
mode:
authorUtku Demir <me@utdemir.com>2020-07-04 22:00:57 +1200
committerUtku Demir <me@utdemir.com>2020-07-04 22:00:57 +1200
commitcc46362929dbb5d13a8ff8c4669ac3a8d47db028 (patch)
treea010a8fc180cb4d032f91f9156fcea6903fef5eb /pkgs/build-support
parentf6ef771ab905608a9894fdd0439479f29880b6e6 (diff)
downloadnixpkgs-cc46362929dbb5d13a8ff8c4669ac3a8d47db028.tar
nixpkgs-cc46362929dbb5d13a8ff8c4669ac3a8d47db028.tar.gz
nixpkgs-cc46362929dbb5d13a8ff8c4669ac3a8d47db028.tar.bz2
nixpkgs-cc46362929dbb5d13a8ff8c4669ac3a8d47db028.tar.lz
nixpkgs-cc46362929dbb5d13a8ff8c4669ac3a8d47db028.tar.xz
nixpkgs-cc46362929dbb5d13a8ff8c4669ac3a8d47db028.tar.zst
nixpkgs-cc46362929dbb5d13a8ff8c4669ac3a8d47db028.zip
dockerTools: Support files directly under /nix/store
Also makes sure that the files inside a layer added in a sorted order
to make the results more deterministic.
Diffstat (limited to 'pkgs/build-support')
-rw-r--r--pkgs/build-support/docker/examples.nix10
-rw-r--r--pkgs/build-support/docker/stream_layered_image.py8
2 files changed, 14 insertions, 4 deletions
diff --git a/pkgs/build-support/docker/examples.nix b/pkgs/build-support/docker/examples.nix
index b040d830b31..8b77d6011d3 100644
--- a/pkgs/build-support/docker/examples.nix
+++ b/pkgs/build-support/docker/examples.nix
@@ -335,4 +335,14 @@ rec {
     };
   };
 
+  # 19. Support files in the store on buildLayeredImage
+  # See: https://github.com/NixOS/nixpkgs/pull/91084#issuecomment-653496223
+  filesInStore = pkgs.dockerTools.buildLayeredImage {
+    name = "file-in-store";
+    tag = "latest";
+    config.Cmd = [
+      "${pkgs.coreutils}/bin/cat"
+      (pkgs.writeText "somefile" "some data")
+    ];
+  };
 }
diff --git a/pkgs/build-support/docker/stream_layered_image.py b/pkgs/build-support/docker/stream_layered_image.py
index 4348513338d..609af30c8bb 100644
--- a/pkgs/build-support/docker/stream_layered_image.py
+++ b/pkgs/build-support/docker/stream_layered_image.py
@@ -39,6 +39,7 @@ import json
 import hashlib
 import pathlib
 import tarfile
+import itertools
 import threading
 from datetime import datetime
 from collections import namedtuple
@@ -87,10 +88,9 @@ def archive_paths_to(obj, paths, mtime, add_nix, filter=None):
             tar.addfile(apply_filters(dir("/nix/store")))
 
         for path in paths:
-            ti = tar.gettarinfo(os.path.join("/", path))
-            tar.addfile(apply_filters(append_root(ti)))
-
-            for filename in pathlib.Path(path).rglob("*"):
+            path = pathlib.Path(path)
+            files = itertools.chain([path], path.rglob("*"))
+            for filename in sorted(files):
                 ti = append_root(tar.gettarinfo(filename))
 
                 # copy hardlinks as regular files