Search code examples
containersnixpodman

Unable to build podman compatiable containers using nix-build and dockerTools.buildImage


The following is invidious.nix, which builds a container that contains nix packages for Bash, Busybox and Invidious:

let
  # nixos-22.05 / https://status.nixos.org/
  pkgs = import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/d86a4619b7e80bddb6c01bc01a954f368c56d1df.tar.gz") {};
in rec {

  docker = pkgs.dockerTools.buildImage {
    name = "invidious";
    contents = [ pkgs.busybox pkgs.bash pkgs.invidious ];
    config = {
      Cmd = [ "/bin/bash" ];
      Env = [];
      Volumes = {};
    };
  };
}

If I try to load the container with docker load < result, Docker can correctly load the container.

docker load < result
14508d34fd29: Loading layer [==================================================>]  156.6MB/156.6MB
Loaded image: invidious:2nrcdxgz46isccfgyzdcbirs0vvqhp55

However, if I attempt the same thing using podman, I get the following error:

podman load < result
Error: payload does not match any of the supported image formats:
 * oci: initializing source oci:/var/tmp/podman3824611648:: open /var/tmp/podman3824611648/index.json: not a directory
 * oci-archive: loading index: open /var/tmp/oci1927542201/index.json: no such file or directory
 * docker-archive: loading tar component manifest.json: archive/tar: invalid tar header
 * dir: open /var/tmp/podman3824611648/manifest.json: not a directory

If I inspect the result, it does appear to have the correct format for an OCI container:

tar tvfz result
dr-xr-xr-x root/root         0 1979-12-31 19:00 ./
-r--r--r-- root/root       391 1979-12-31 19:00 027302622543ef251be6d3f2d616f98c73399d8cd074b0d1497e5a7da5e6c882.json
dr-xr-xr-x root/root         0 1979-12-31 19:00 669db3729b40e36a9153569b747788611e547f0b50a9f7d77107a04c6ddd887e/
-r--r--r-- root/root         3 1979-12-31 19:00 669db3729b40e36a9153569b747788611e547f0b50a9f7d77107a04c6ddd887e/VERSION
-r--r--r-- root/root       353 1979-12-31 19:00 669db3729b40e36a9153569b747788611e547f0b50a9f7d77107a04c6ddd887e/json
-r--r--r-- root/root 156579840 1979-12-31 19:00 669db3729b40e36a9153569b747788611e547f0b50a9f7d77107a04c6ddd887e/layer.tar
-r--r--r-- root/root       280 1979-12-31 19:00 manifest.json
-r--r--r-- root/root       128 1979-12-31 19:00 repositories

How do I get nix-build to create compliant containers that podman can read?

nix-build version: 2.10.3

podman version: 4.2.0


Solution

  • It turns out, the version of podman I'm running can't read gzipped tar files. The following works:

    zcat result | podman load