# Auto-generated using compose2nix v0.3.1.
{ pkgs, lib, ... }:

{
  # Runtime
  virtualisation.podman = {
    enable = true;
    autoPrune.enable = true;
    dockerCompat = true;
    defaultNetwork.settings = {
      # Required for container networking to be able to use names.
      dns_enabled = true;
    };
  };

  # Enable container name DNS for non-default Podman networks.
  # https://github.com/NixOS/nixpkgs/issues/226365
  networking.firewall.interfaces."podman+".allowedUDPPorts = [ 53 ];

  virtualisation.oci-containers.backend = "podman";

  # Containers
  virtualisation.oci-containers.containers."scribe-vault-app" = {
    image = "node:22";
    volumes = [
      "/home/wayne/dev/www/v2-scribevault/frontend:/app:rw"
    ];
    ports = [
      "4173:4173/tcp"
    ];
    cmd = [ "npm" "run" "test" ];
    log-driver = "journald";
    extraOptions = [
      "--network-alias=app"
      "--network=scribe-vault_my-network"
    ];
  };
  systemd.services."podman-scribe-vault-app" = {
    serviceConfig = {
      Restart = lib.mkOverride 90 "no";
    };
    after = [
      "podman-network-scribe-vault_my-network.service"
    ];
    requires = [
      "podman-network-scribe-vault_my-network.service"
    ];
    partOf = [
      "podman-compose-scribe-vault-root.target"
    ];
    wantedBy = [
      "podman-compose-scribe-vault-root.target"
    ];
  };
  virtualisation.oci-containers.containers."scribe-vault-cypress" = {
    image = "cypress/included:cypress-13.17.0-node-22.12.0-chrome-131.0.6778.139-1-ff-133.0.3-edge-131.0.2903.99-1";
    environment = {
      "CYPRESS_BASE_URL" = "http://app:4173";
    };
    volumes = [
      "/home/wayne/dev/www/v2-scribevault/frontend:/app:rw"
    ];
    dependsOn = [
      "scribe-vault-app"
    ];
    log-driver = "journald";
    extraOptions = [
      "--entrypoint=[\"cypress\", \"run\", \"--e2e\"]"
      "--network-alias=cypress"
      "--network=scribe-vault_my-network"
    ];
  };
  systemd.services."podman-scribe-vault-cypress" = {
    serviceConfig = {
      Restart = lib.mkOverride 90 "no";
    };
    after = [
      "podman-network-scribe-vault_my-network.service"
    ];
    requires = [
      "podman-network-scribe-vault_my-network.service"
    ];
    partOf = [
      "podman-compose-scribe-vault-root.target"
    ];
    wantedBy = [
      "podman-compose-scribe-vault-root.target"
    ];
  };

  # Networks
  systemd.services."podman-network-scribe-vault_my-network" = {
    path = [ pkgs.podman ];
    serviceConfig = {
      Type = "oneshot";
      RemainAfterExit = true;
      ExecStop = "podman network rm -f scribe-vault_my-network";
    };
    script = ''
      podman network inspect scribe-vault_my-network || podman network create scribe-vault_my-network --driver=bridge
    '';
    partOf = [ "podman-compose-scribe-vault-root.target" ];
    wantedBy = [ "podman-compose-scribe-vault-root.target" ];
  };

  # Root service
  # When started, this will automatically create all resources and start
  # the containers. When stopped, this will teardown all resources.
  systemd.targets."podman-compose-scribe-vault-root" = {
    unitConfig = {
      Description = "Root target generated by compose2nix.";
    };
    wantedBy = [ "multi-user.target" ];
  };
}
