dockerTools.buildImage ADD/COPY equivalent

If, for example, I have a python script that I want to copy into a docker image how would I do that with dockerTools.buildImage? I’m looking for something like ADD or COPY in a normal Dockerfile.

You’re looking for contents

I haven’t tested this, but from the description, this should work:

buildImage {
  contents = [

and then should exist at / within the container

Paths will be added to the nixstore, (e.g. /nix/store/… then included as an input for the derivation


I solved by creating a new directory, putting my script there, then including ./directory in contents. Thanks!

Note to anyone in the future stuck on this: it needs to be in a directory, just specifying the filename will give you errors


I have just tried this approach (contents = [ ./dir ];) and got an error:

Executing pre-mount steps...
Adding contents...
Adding /absolute/path/to/dir
rsync: change_dir "/absolute/path/to/dir" failed: No such file or directory (2)
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1189) [sender=3.1.3]

The path it shows is correct.

Hosted by Flying Circus.