···2020 fromImageName = null;
2121 fromImageTag = "latest";
22222323- contents = pkgs.redis;
2323+ copyToRoot = pkgs.buildEnv {
2424+ name = "image-root";
2525+ paths = [ pkgs.redis ];
2626+ pathsToLink = [ "/bin" ];
2727+ };
2828+2429 runAsRoot = ''
2530 #!${pkgs.runtimeShell}
2631 mkdir -p /data
···46514752- `fromImageTag` can be used to further specify the tag of the base image within the repository, in case an image contains multiple tags. By default it's `null`, in which case `buildImage` will peek the first tag available for the base image.
48534949-- `contents` is a derivation that will be copied in the new layer of the resulting image. This can be similarly seen as `ADD contents/ /` in a `Dockerfile`. By default it's `null`.
5454+- `copyToRoot` is a derivation that will be copied in the new layer of the resulting image. This can be similarly seen as `ADD contents/ /` in a `Dockerfile`. By default it's `null`.
50555156- `runAsRoot` is a bash script that will run as root in an environment that overlays the existing layers of the base image with the new resulting layer, including the previously copied `contents` derivation. This can be similarly seen as `RUN ...` in a `Dockerfile`.
5257···8186 name = "hello";
8287 tag = "latest";
8388 created = "now";
8484- contents = pkgs.hello;
8989+ copyToRoot = pkgs.buildEnv {
9090+ name = "image-root";
9191+ paths = [ pkgs.hello ];
9292+ pathsToLink = [ "/bin" ];
9393+ };
85948695 config.Cmd = [ "/bin/hello" ];
8796}
···305305 </listitem>
306306 <listitem>
307307 <para>
308308+ <literal>dockerTools.buildImage</literal> deprecates the
309309+ misunderstood <literal>contents</literal> parameter, in favor
310310+ of <literal>copyToRoot</literal>. Use
311311+ <literal>copyToRoot = buildEnv { ... };</literal> or similar
312312+ if you intend to add packages to <literal>/bin</literal>.
313313+ </para>
314314+ </listitem>
315315+ <listitem>
316316+ <para>
308317 memtest86+ was updated from 5.00-coreboot-002 to 6.00-beta2.
309318 It is now the upstream version from https://www.memtest.org/,
310319 as coreboot’s fork is no longer available.
+3
nixos/doc/manual/release-notes/rl-2211.section.md
···114114115115- Matrix Synapse now requires entries in the `state_group_edges` table to be unique, in order to prevent accidentally introducing duplicate information (for example, because a database backup was restored multiple times). If your Synapse database already has duplicate rows in this table, this could fail with an error and require manual remediation.
116116117117+- `dockerTools.buildImage` deprecates the misunderstood `contents` parameter, in favor of `copyToRoot`.
118118+ Use `copyToRoot = buildEnv { ... };` or similar if you intend to add packages to `/bin`.
119119+117120- memtest86+ was updated from 5.00-coreboot-002 to 6.00-beta2. It is now the upstream version from https://www.memtest.org/, as coreboot's fork is no longer available.
118121119122- Add udev rules for the Teensy family of microcontrollers.
···332332 , # JSON containing configuration and metadata for this layer.
333333 baseJson
334334 , # Files to add to the layer.
335335- contents ? null
335335+ copyToRoot ? null
336336 , # When copying the contents into the image, preserve symlinks to
337337 # directories (see `rsync -K`). Otherwise, transform those symlinks
338338 # into directories.
···344344 }:
345345 runCommand "docker-layer-${name}"
346346 {
347347- inherit baseJson contents extraCommands;
347347+ inherit baseJson extraCommands;
348348+ contents = copyToRoot;
348349 nativeBuildInputs = [ jshon rsync tarsum ];
349350 }
350351 ''
···390391 , # Script to run as root. Bash.
391392 runAsRoot
392393 , # Files to add to the layer. If null, an empty layer will be created.
393393- contents ? null
394394+ # To add packages to /bin, use `buildEnv` or similar.
395395+ copyToRoot ? null
394396 , # When copying the contents into the image, preserve symlinks to
395397 # directories (see `rsync -K`). Otherwise, transform those symlinks
396398 # into directories.
···418420419421 inherit fromImage fromImageName fromImageTag diskSize;
420422421421- preMount = lib.optionalString (contents != null && contents != [ ]) ''
423423+ preMount = lib.optionalString (copyToRoot != null && copyToRoot != [ ]) ''
422424 echo "Adding contents..."
423423- for item in ${escapeShellArgs (map (c: "${c}") (toList contents))}; do
425425+ for item in ${escapeShellArgs (map (c: "${c}") (toList copyToRoot))}; do
424426 echo "Adding $item..."
425427 rsync -a${if keepContentsDirlinks then "K" else "k"} --chown=0:0 $item/ layer/
426428 done
···500502 , # Tag of the parent image; will be read from the image otherwise.
501503 fromImageTag ? null
502504 , # Files to put on the image (a nix store path or list of paths).
503503- contents ? null
505505+ copyToRoot ? null
504506 , # When copying the contents into the image, preserve symlinks to
505507 # directories (see `rsync -K`). Otherwise, transform those symlinks
506508 # into directories.
···517519 diskSize ? 1024
518520 , # Time of creation of the image.
519521 created ? "1970-01-01T00:00:01Z"
522522+ , # Deprecated.
523523+ contents ? null
520524 ,
521525 }:
522526523527 let
528528+ checked =
529529+ lib.warnIf (contents != null)
530530+ "in docker image ${name}: The contents parameter is deprecated. Change to copyToRoot if the contents are designed to be copied to the root filesystem, such as when you use `buildEnv` or similar between contents and your packages. Use copyToRoot = buildEnv { ... }; or similar if you intend to add packages to /bin."
531531+ lib.throwIf (contents != null && copyToRoot != null) "in docker image ${name}: You can not specify both contents and copyToRoot."
532532+ ;
533533+534534+ rootContents = if copyToRoot == null then contents else copyToRoot;
535535+524536 baseName = baseNameOf name;
525537526538 # Create a JSON blob of the configuration. Set the date to unix zero.
···545557 mkPureLayer
546558 {
547559 name = baseName;
548548- inherit baseJson contents keepContentsDirlinks extraCommands uid gid;
560560+ inherit baseJson keepContentsDirlinks extraCommands uid gid;
561561+ copyToRoot = rootContents;
549562 } else
550563 mkRootLayer {
551564 name = baseName;
552565 inherit baseJson fromImage fromImageName fromImageTag
553553- contents keepContentsDirlinks runAsRoot diskSize
566566+ keepContentsDirlinks runAsRoot diskSize
554567 extraCommands;
568568+ copyToRoot = rootContents;
555569 };
556570 result = runCommand "docker-image-${baseName}.tar.gz"
557571 {
···715729 '';
716730717731 in
718718- result;
732732+ checked result;
719733720734 # Merge the tarballs of images built with buildImage into a single
721735 # tarball that contains all images. Running `docker load` on the resulting
···776790 # contents. The main purpose is to be able to use nix commands in
777791 # the container.
778792 # Be careful since this doesn't work well with multilayer.
779779- buildImageWithNixDb = args@{ contents ? null, extraCommands ? "", ... }: (
793793+ # TODO: add the dependencies of the config json.
794794+ buildImageWithNixDb = args@{ copyToRoot ? contents, contents ? null, extraCommands ? "", ... }: (
780795 buildImage (args // {
781781- extraCommands = (mkDbExtraCommand contents) + extraCommands;
796796+ extraCommands = (mkDbExtraCommand copyToRoot) + extraCommands;
782797 })
783798 );
784799800800+ # TODO: add the dependencies of the config json.
785801 buildLayeredImageWithNixDb = args@{ contents ? null, extraCommands ? "", ... }: (
786802 buildLayeredImage (args // {
787803 extraCommands = (mkDbExtraCommand contents) + extraCommands;
+72-25
pkgs/build-support/docker/examples.nix
···2424 bash = buildImage {
2525 name = "bash";
2626 tag = "latest";
2727- contents = pkgs.bashInteractive;
2727+ copyToRoot = pkgs.buildEnv {
2828+ name = "image-root";
2929+ paths = [ pkgs.bashInteractive ];
3030+ pathsToLink = [ "/bin" ];
3131+ };
2832 };
29333034 # 2. service example, layered on another image
···3640 fromImage = bash;
3741 # fromImage = debian;
38423939- contents = pkgs.redis;
4343+ copyToRoot = pkgs.buildEnv {
4444+ name = "image-root";
4545+ paths = [ pkgs.redis ];
4646+ pathsToLink = [ "/bin" ];
4747+ };
4848+4049 runAsRoot = ''
4150 mkdir -p /data
4251 '';
···118127 # 5. example of multiple contents, emacs and vi happily coexisting
119128 editors = buildImage {
120129 name = "editors";
121121- contents = [
122122- pkgs.coreutils
123123- pkgs.bash
124124- pkgs.emacs
125125- pkgs.vim
126126- pkgs.nano
127127- ];
130130+ copyToRoot = pkgs.buildEnv {
131131+ name = "image-root";
132132+ pathsToLink = [ "/bin" ];
133133+ paths = [
134134+ pkgs.coreutils
135135+ pkgs.bash
136136+ pkgs.emacs
137137+ pkgs.vim
138138+ pkgs.nano
139139+ ];
140140+ };
128141 };
129142130143 # 6. nix example to play with the container nix store
···132145 nix = buildImageWithNixDb {
133146 name = "nix";
134147 tag = "latest";
135135- contents = [
136136- # nix-store uses cat program to display results as specified by
137137- # the image env variable NIX_PAGER.
138138- pkgs.coreutils
139139- pkgs.nix
140140- pkgs.bash
141141- ];
148148+ copyToRoot = pkgs.buildEnv {
149149+ name = "image-root";
150150+ pathsToLink = [ "/bin" ];
151151+ paths = [
152152+ # nix-store uses cat program to display results as specified by
153153+ # the image env variable NIX_PAGER.
154154+ pkgs.coreutils
155155+ pkgs.nix
156156+ pkgs.bash
157157+ ];
158158+ };
142159 config = {
143160 Env = [
144161 "NIX_PAGER=cat"
···155172 name = "onTopOfPulledImage";
156173 tag = "latest";
157174 fromImage = nixFromDockerHub;
158158- contents = [ pkgs.hello ];
175175+ copyToRoot = pkgs.buildEnv {
176176+ name = "image-root";
177177+ pathsToLink = [ "/bin" ];
178178+ paths = [ pkgs.hello ];
179179+ };
159180 };
160181161182 # 8. regression test for erroneous use of eval and string expansion.
···163184 runAsRootExtraCommands = pkgs.dockerTools.buildImage {
164185 name = "runAsRootExtraCommands";
165186 tag = "latest";
166166- contents = [ pkgs.coreutils ];
187187+ copyToRoot = pkgs.buildEnv {
188188+ name = "image-root";
189189+ pathsToLink = [ "/bin" ];
190190+ paths = [ pkgs.coreutils ];
191191+ };
167192 # The parens here are to create problematic bash to embed and eval. In case
168193 # this is *embedded* into the script (with nix expansion) the initial quotes
169194 # will close the string and the following parens are unexpected
···176201 unstableDate = pkgs.dockerTools.buildImage {
177202 name = "unstable-date";
178203 tag = "latest";
179179- contents = [ pkgs.coreutils ];
204204+ copyToRoot = pkgs.buildEnv {
205205+ name = "image-root";
206206+ pathsToLink = [ "/bin" ];
207207+ paths = [ pkgs.coreutils ];
208208+ };
180209 created = "now";
181210 };
182211···265294 name = "l3";
266295 fromImage = l2;
267296 tag = "latest";
268268- contents = [ pkgs.coreutils ];
297297+ copyToRoot = pkgs.buildEnv {
298298+ name = "image-root";
299299+ pathsToLink = [ "/bin" ];
300300+ paths = [ pkgs.coreutils ];
301301+ };
269302 extraCommands = ''
270303 mkdir -p tmp
271304 echo layer3 > tmp/layer3
···290323 name = "child";
291324 fromImage = environmentVariablesParent;
292325 tag = "latest";
293293- contents = [ pkgs.coreutils ];
326326+ copyToRoot = pkgs.buildEnv {
327327+ name = "image-root";
328328+ pathsToLink = [ "/bin" ];
329329+ paths = [ pkgs.coreutils ];
330330+ };
294331 config = {
295332 Env = [
296333 "FROM_CHILD=true"
···424461 name = "layers-unpack-order-${layerName}";
425462 tag = "latest";
426463 fromImage = parent;
427427- contents = [ pkgs.coreutils ];
464464+ copyToRoot = pkgs.buildEnv {
465465+ name = "image-root";
466466+ pathsToLink = [ "/bin" ];
467467+ paths = [ pkgs.coreutils ];
468468+ };
428469 runAsRoot = ''
429470 #!${pkgs.runtimeShell}
430471 echo -n "${layerName}" >> /layer-order
···441482 # buildImage without explicit tag
442483 bashNoTag = pkgs.dockerTools.buildImage {
443484 name = "bash-no-tag";
444444- contents = pkgs.bashInteractive;
485485+ # Not recommended. Use `buildEnv` between copy and packages to avoid file duplication.
486486+ copyToRoot = pkgs.bashInteractive;
445487 };
446488447489 # buildLayeredImage without explicit tag
···501543 in crossPkgs.dockerTools.buildImage {
502544 name = "hello-cross";
503545 tag = "latest";
504504- contents = crossPkgs.hello;
546546+ copyToRoot = pkgs.buildEnv {
547547+ name = "image-root";
548548+ pathsToLink = [ "/bin" ];
549549+ paths = [ crossPkgs.hello ];
550550+ };
505551 };
506552507553 # layered image where a store path is itself a symlink
···643689 build-image-with-path = buildImage {
644690 name = "build-image-with-path";
645691 tag = "latest";
646646- contents = [ pkgs.bashInteractive ./test-dummy ];
692692+ # Not recommended. Use `buildEnv` between copy and packages to avoid file duplication.
693693+ copyToRoot = [ pkgs.bashInteractive ./test-dummy ];
647694 };
648695649696 layered-image-with-path = pkgs.dockerTools.streamLayeredImage {