Caching dependencies of a container image

I am building an image using dockerTools.buildImage. How do I get the store paths of the dependencies listed in the contents attribute once the image is built and in the store?

When you use dockerTools.buildImage like

image = pkgs.dockerTools.buildImage {
  name = "hello";
  tag = "latest";
  created = "now";
  contents = with pkgs; [ hello neofetch ];

  config.Cmd = [ "/bin/hello" ];

it creates a tarball in the store. You can’t refer to the specific files in the tarball, but you can refer to the tarball with image.outPath even before building it.

Again, regardless of whether the image is built or not, you can refer to the Nix store paths of the contents like

map toString image.buildArgs.contents

But those paths are the Nix store paths of the inputs, not related to the docker image. Maybe I misunderstood you.

1 Like

is precisely what I was looking for! Thanks!