{
  pkgs,
  photoncloudPackages,
  photoncloudModule,
  nixNosModule,
}:

{
  name = "first-boot-topology-vm-smoke";

  nodes = {
    bridge01 =
      { ... }:
      {
        imports = [
          nixNosModule
          photoncloudModule
        ];

        networking.hostName = "bridge01";
        networking.firewall.enable = false;

        environment.systemPackages = with pkgs; [
          jq
        ];

        services.chainfire = {
          enable = true;
          package = photoncloudPackages.chainfire-server;
          nodeId = "bridge01";
          apiAddr = "127.0.0.1:2379";
          raftAddr = "127.0.0.1:2380";
          initialPeers = [ "bridge01=127.0.0.1:2380" ];
        };
        systemd.services.chainfire.environment.RUST_LOG = "error";

        services.first-boot-automation = {
          enable = true;
          useNixNOS = true;
          enableFlareDB = false;
          enableIAM = false;
        };

        plasmacloud.cluster = {
          enable = true;
          name = "bridge-cluster";
          nodes.bridge01 = {
            role = "control-plane";
            ip = "127.0.0.1";
            services = [ "chainfire" ];
            raftPort = 2380;
            apiPort = 2379;
          };
          bootstrap.initialPeers = [ "bridge01" ];
          bgp.asn = 64512;
        };

        system.stateVersion = "24.11";
      };

    stand01 =
      { ... }:
      {
        imports = [
          nixNosModule
          photoncloudModule
        ];

        networking.hostName = "stand01";
        networking.firewall.enable = false;

        environment.systemPackages = with pkgs; [
          jq
        ];

        nix-nos = {
          enable = true;
          clusters.standalone = {
            name = "standalone-cluster";
            bootstrapNode = "stand01";
            nodes.stand01 = {
              role = "control-plane";
              ip = "127.0.0.1";
              services = [ "chainfire" ];
              raftPort = 2380;
              apiPort = 2379;
            };
          };
        };

        services.chainfire = {
          enable = true;
          package = photoncloudPackages.chainfire-server;
          nodeId = "stand01";
          apiAddr = "127.0.0.1:2379";
          raftAddr = "127.0.0.1:2380";
          initialPeers = [ "stand01=127.0.0.1:2380" ];
        };
        systemd.services.chainfire.environment.RUST_LOG = "error";

        services.first-boot-automation = {
          enable = true;
          useNixNOS = true;
          nixnosClusterName = "standalone";
          enableFlareDB = false;
          enableIAM = false;
        };

        system.stateVersion = "24.11";
      };
  };

  testScript = ''
    start_all()
    serial_stdout_off()

    scenarios = [
        (bridge01, "bridge01", "bridge-cluster"),
        (stand01, "stand01", "standalone-cluster"),
    ]

    for machine, node_id, cluster_name in scenarios:
        print(f"validating {node_id}")
        machine.wait_for_unit("chainfire.service")
        print(f"{node_id}: chainfire up")
        machine.wait_until_succeeds("test -f /etc/nixos/secrets/cluster-config.json")
        print(f"{node_id}: config file present")
        machine.succeed(
            "bash -lc 'systemctl restart chainfire-cluster-join.service "
            "|| (systemctl status chainfire-cluster-join.service --no-pager; "
            "journalctl -u chainfire-cluster-join.service --no-pager -n 200; exit 1)'"
        )
        machine.wait_until_succeeds("test -f /var/lib/first-boot-automation/.chainfire-initialized")
        print(f"{node_id}: bootstrap marker present")
        machine.succeed("systemctl is-active chainfire-cluster-join.service")

        machine.succeed(f"jq -r '.node_id' /etc/nixos/secrets/cluster-config.json | grep -x '{node_id}'")
        machine.succeed("jq -r '.bootstrap' /etc/nixos/secrets/cluster-config.json | grep -x true")
        machine.succeed(f"jq -r '.cluster_name' /etc/nixos/secrets/cluster-config.json | grep -x '{cluster_name}'")
        machine.succeed("jq -r '.chainfire_leader_url' /etc/nixos/secrets/cluster-config.json | grep -x 'http://127.0.0.1:8081'")
  '';
}
