Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docker: allow grouping derivations into explicit layers #157670

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions pkgs/build-support/docker/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,8 @@ rec {
fromImage ? null
, # Files to put on the image (a nix store path or list of paths).
contents ? [ ]
, # List of lists of paths to explicitly put into individual layers
explicitLayers ? [ ]
, # Docker config; e.g. what command to run on the container.
config ? { }
, # Time of creation of the image. Passing "now" will make the
Expand Down Expand Up @@ -923,7 +925,7 @@ rec {
paths() {
cat $paths ${lib.concatMapStringsSep " "
(path: "| (grep -v ${path} || true)")
unnecessaryDrvs}
(unnecessaryDrvs ++ (lib.concatLists explicitLayers))}
}

# Compute the number of layers that are already used by a potential
Expand All @@ -939,10 +941,14 @@ rec {
# one layer will be taken up by the customisation layer
(( usedLayers += 1 ))

# explicitLayers
(( usedLayers += ${toString (lib.length explicitLayers)} ))

if ! (( $usedLayers < $maxLayers )); then
echo >&2 "Error: usedLayers $usedLayers layers to store 'fromImage' and" \
"'extraCommands', but only maxLayers=$maxLayers were" \
"allowed. At least 1 layer is required to store contents."
echo >&2 "Error: usedLayers $usedLayers layers to store 'fromImage'," \
"`explicitLayers`, and 'extraCommands', but only" \
"maxLayers=$maxLayers were allowed." \
"At least 1 layer is required to store contents."
exit 1
fi
availableLayers=$(( maxLayers - usedLayers ))
Expand All @@ -961,10 +967,11 @@ rec {
paths |
jq -sR '
rtrimstr("\n") | split("\n")
| (.[:$maxLayers-1] | map([.])) + [ .[$maxLayers-1:] ]
| (.[:$maxLayers-1] | map([.])) + $explicitLayers + [ .[$maxLayers-1:] ]
| map(select(length > 0))
' \
--argjson maxLayers "$availableLayers"
--argjson maxLayers "$availableLayers" \
--argjson explicitLayers '${builtins.toJSON explicitLayers}'
)"

cat ${baseJson} | jq '
Expand Down