How do I use oci-containers "imageFile"?

Alternate title: “How do I use an image that I saved to disk?”

Hello everybody,
I am using NixOs in an air-gapped environment and want to make sure my containers always work.
Currently there is a registry available in the private network, but I don’t want to rely on it, I want to place my “image.tar” on the local system storage and load it from there . I saw the “virtualisation.oci-containers.containers..imageFile” option but it is requesting a “package”, which I don’t really get.
But looking at the source code it looks like it would work if I was able to enter a path to the file.

So yea, I am a bit lost. Is what I want to do is possible?

Yes it is possible, I have found a way to make it work:

imageFile = fetchTree {
      type = "file";
      url = "file:///must/be/absolute/path/file.tar";
    };

Please note:

  • The image tag in the tar file has to match exactly with the “image” value,
  • The URL in the fetchTree has to be absolute. Does not work with relative paths.

Maybe there is a nix builtin function to convert a relative path to absolute, idk.

1 Like

That works. Thank you so much.

1 Like

Ahhh… If only I had read the documentation for Podman correctly.

https://docs.podman.io/en/latest/markdown/podman-run.1.html#image

After all it is possible to simply do it like this:

virtualisation.oci-containers.containers = {
  "imagefiletest" = {
    image = "docker-archive:<path-to-image>";
  };
};

Cool, good to know. Feels brittle to me though

  • It’s podman specific, oci-containers module does not understand this prop
  • It does not go through the nix store.

I think the real solution is to put the tarball to a flake and use it the “nix” way. But that are just my thoughts. In the end I concluded that for my use case using the imageFile property is not necessary.