diff options
author | Domen Kožar <domen@dev.si> | 2020-03-08 23:05:27 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-08 23:05:27 +0100 |
commit | 508a2c684964b66d4c3e56c912b0dd52248abd04 (patch) | |
tree | ee25929bc60113b88c8091a07a419aca2bd5378b /pkgs/build-support | |
parent | dd5e9ab4f2953c0e5c76f3e7b4763a6fe3e9c692 (diff) | |
parent | 6dab1b50a63fa6e9dfb9bd9eddd3f5d5c7b055ef (diff) | |
download | nixlib-508a2c684964b66d4c3e56c912b0dd52248abd04.tar nixlib-508a2c684964b66d4c3e56c912b0dd52248abd04.tar.gz nixlib-508a2c684964b66d4c3e56c912b0dd52248abd04.tar.bz2 nixlib-508a2c684964b66d4c3e56c912b0dd52248abd04.tar.lz nixlib-508a2c684964b66d4c3e56c912b0dd52248abd04.tar.xz nixlib-508a2c684964b66d4c3e56c912b0dd52248abd04.tar.zst nixlib-508a2c684964b66d4c3e56c912b0dd52248abd04.zip |
Merge pull request #80921 from hercules-ci/buildLayeredImage-allow-empty-store
buildLayeredImage: Allow empty store, no paths to add
Diffstat (limited to 'pkgs/build-support')
-rw-r--r-- | pkgs/build-support/docker/default.nix | 9 | ||||
-rw-r--r-- | pkgs/build-support/docker/examples.nix | 22 |
2 files changed, 27 insertions, 4 deletions
diff --git a/pkgs/build-support/docker/default.nix b/pkgs/build-support/docker/default.nix index ff9949bc8dda..28c0d2dfcae1 100644 --- a/pkgs/build-support/docker/default.nix +++ b/pkgs/build-support/docker/default.nix @@ -319,6 +319,8 @@ rec { enableParallelBuilding = true; } '' + mkdir layers + # Delete impurities for store path layers, so they don't get # shared and taint other projects. cat ${configJson} \ @@ -330,13 +332,12 @@ rec { # created, and that no paths are missed. If you change the # following head and tail call lines, double-check that your # code behaves properly when the number of layers equals: - # maxLayers-1, maxLayers, and maxLayers+1 + # maxLayers-1, maxLayers, and maxLayers+1, 0 paths() { - cat $paths ${lib.concatMapStringsSep " " (path: "| grep -v ${path}") (closures ++ [ overallClosure ])} + cat $paths ${lib.concatMapStringsSep " " (path: "| (grep -v ${path} || true)") (closures ++ [ overallClosure ])} } - # We need to sponge to avoid grep broken pipe error when maxLayers == 1 - paths | sponge | head -n $((maxLayers - 1)) | cat -n | xargs -r -P$NIX_BUILD_CORES -n2 ${storePathToLayer} + paths | head -n $((maxLayers - 1)) | cat -n | xargs -r -P$NIX_BUILD_CORES -n2 ${storePathToLayer} if [ $(paths | wc -l) -ge $maxLayers ]; then paths | tail -n+$maxLayers | xargs ${storePathToLayer} $maxLayers fi diff --git a/pkgs/build-support/docker/examples.nix b/pkgs/build-support/docker/examples.nix index f0dcf236c0e4..f42b35e64943 100644 --- a/pkgs/build-support/docker/examples.nix +++ b/pkgs/build-support/docker/examples.nix @@ -258,4 +258,26 @@ rec { maxLayers = 2; }; + # 17. Create a "layered" image without nix store layers. This is not + # recommended, but can be useful for base images in rare cases. + no-store-paths = pkgs.dockerTools.buildLayeredImage { + name = "no-store-paths"; + tag = "latest"; + extraCommands = '' + chmod a+w bin + + # This removes sharing of busybox and is not recommended. We do this + # to make the example suitable as a test case with working binaries. + cp -r ${pkgs.pkgsStatic.busybox}/* . + ''; + contents = [ + # This layer has no dependencies and its symlinks will be dereferenced + # when creating the customization layer. + (pkgs.runCommand "layer-to-flatten" {} '' + mkdir -p $out/bin + ln -s /bin/true $out/bin/custom-true + '' + ) + ]; + }; } |