{ config, pkgs, ... }:

{
  # https://nixos.wiki/wiki/Podman#Install_and_configure_podman_with_NixOS_service_configuration
  # https://search.nixos.org/options?channel=23.05&query=virtualisation.podman

  # TODO: Run as systemd services. https://nixos.wiki/wiki/Podman#Run_Podman_containers_as_systemd_services
  # TODO: Podman Terminal UI. https://github.com/containers/podman-tui#podman-tui

  environment.systemPackages = with pkgs; [
    podman-compose
  ];

  virtualisation = {
    podman = {
      enable = true;

      # Create a `docker` alias for podman, to use it as a drop-in replacement.
      dockerCompat = true;

      # Required for containers under podman-compose to be able to talk to each other.
      defaultNetwork.settings = {
        dns_enabled = true;
      };

      # Run `podman system prune` every week.
      autoPrune.enable = true;
      autoPrune.dates = "weekly";
      autoPrune.flags = [
        # Recursively remove all unused pods, containers, images, networks, and volume data.
        # https://docs.podman.io/en/stable/markdown/podman-system-prune.1.html#all-a
        "--all"
        # Prune volumes currently unused by any container
        # https://docs.podman.io/en/stable/markdown/podman-system-prune.1.html#volumes
        "--volumes"
        # Only remove containers and images created at least one week ago.
        # https://docs.podman.io/en/stable/markdown/podman-system-prune.1.html#filter-filters
        # https://pkg.go.dev/maze.io/x/duration#ParseDuration
        "--filter until=7d"
      ];
    };
  };
}
