Podman container from `dependsOn` fails to start after reboot due to dependent container

I have a container parent and container child. child dependsOn on parent. I think there might be a bug where the generated systemd scripts block each other.

The container config looks something along the lines of:

virtualisation.podman.enable = true;
virtualisation.oci-containers.containers = {
    parent= {
      user = "root";
      image = "parent:latest";
    child = {
      dependsOn = ["parent"];
      image = "child:latest";

This works fine for nixos-rebuild switch but after a crash (service probably not stopped properly) and reboot the parent container can not start:

server systemd[1]: Starting podman-parent.service...
server pre-start[90566]: Error: container <HASH_OF_PARENT_CONTAINER> has dependent containers which must be removed before it: <HASH_OF_CHILD_CONTAINER>: container already exists
server podman-parent-start[90618]: Error: container <HASH_OF_PARENT_CONTAINER> has dependent containers which must be removed before it: <HASH_OF_CHILD_CONTAINER>: container already exists

The prestart script of the parent is

set -o errexit
set -o nounset
set -o pipefail

podman rm -f parent || true

rm -f /run/podman-'parent'.ctr-id

I guess this is where it fails while running podman rm -f parent || true because there are still dependent containers.

Shouldn’t NixOS delete all dependent containers first?

I think it may be relevant to podman itself?
The restart policies behaves slightly differently than Docker.
My understanding is that this must be explicitly enabled or configured per contianer:

Have you tried to create a dedicated systemd service to handle containers restart instead?


# in /etc/systemd/system/my-service.service


ExecStart=/usr/bin/docker start something
ExecStop=/usr/bin/docker stop something
ExecStopPost=/usr/bin/docker after stop



# enable
sudo systemctl enable my-container.service

# start
sudo systemctl start my-container.service

I haven’t tried creating a systemd file manually, since I want to keep my configuration as declarative as possible . My “solution” was to remove the dependsOn. The dependency between my containers is also enforced by child using the network of the parent.

Depending on how you’re trying to enforce (to declare all), converting a systemd into nix sythax may be an option? with systemd.services.my-service maybe also system.activationScripts.my-script to initial set the env

Then add a depency within systemd.services.my-service.requires / systemd.services.my-service.wantedBy