{
  description = "UltraCloud Test Cluster";

  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
    ultracloud.url = "path:../..";
  };

  outputs = { self, nixpkgs, ultracloud }:
    let
      system = "x86_64-linux";
      pkgs = import nixpkgs { inherit system; };
      clusterPython = pkgs.python3.withPackages (ps: [ ps.python-snappy ]);
      testClusterOverlay = final: prev:
        let
          disableChecks = drv: drv.overrideAttrs (_: { doCheck = false; });
        in {
          chainfire-server = disableChecks prev.chainfire-server;
          flaredb-server = disableChecks prev.flaredb-server;
          iam-server = disableChecks prev.iam-server;
          coronafs-server = disableChecks prev.coronafs-server;
          plasmavmc-server = disableChecks prev.plasmavmc-server;
          prismnet-server = disableChecks prev.prismnet-server;
          flashdns-server = disableChecks prev.flashdns-server;
          fiberlb-server = disableChecks prev.fiberlb-server;
          lightningstor-server = disableChecks prev.lightningstor-server;
          lightningstor-node = disableChecks prev.lightningstor-node;
          nightlight-server = disableChecks prev.nightlight-server;
          creditservice-server = disableChecks prev.creditservice-server;
          apigateway-server = disableChecks prev.apigateway-server;
          k8shost-server = disableChecks prev.k8shost-server;
          deployer-server = disableChecks prev.deployer-server;
          deployer-ctl = disableChecks prev.deployer-ctl;
          nix-agent = disableChecks prev.nix-agent;
          node-agent = disableChecks prev.node-agent;
          fleet-scheduler = disableChecks prev.fleet-scheduler;
        };

      mkNode = nodeName: nixpkgs.lib.nixosSystem {
        inherit system;
        modules = [
          ./${nodeName}.nix
          {
             nixpkgs.overlays = [ ultracloud.overlays.default testClusterOverlay ];
          }
        ];
      };

      clusterHarness = pkgs.writeShellApplication {
        name = "ultracloud-test-cluster";
        runtimeInputs = with pkgs; [
          bash
          coreutils
          curl
          ultracloud.packages.${system}.chainfire-server
          ultracloud.packages.${system}.deployer-server
          ultracloud.packages.${system}.deployer-ctl
          findutils
          gawk
          gitMinimal
          grpcurl
          gnugrep
          iproute2
          jq
          nix
          openssh
          python3
          procps
          clusterPython
          qemu
          sshpass
          vde2
        ];
        text = ''
          repo_root="$(${pkgs.gitMinimal}/bin/git rev-parse --show-toplevel 2>/dev/null || ${pkgs.coreutils}/bin/pwd)"
          export PHOTON_CLUSTER_FLAKE="''${repo_root}/nix/test-cluster"
          exec "''${repo_root}/nix/test-cluster/run-cluster.sh" "$@"
        '';
      };

      vmGuestImage = (nixpkgs.lib.nixosSystem {
        inherit system;
        modules = [ ./vm-guest-image.nix ];
      }).config.system.build.image;
      vmBenchGuestImage = (nixpkgs.lib.nixosSystem {
        inherit system;
        modules = [ ./vm-bench-guest-image.nix ];
      }).config.system.build.image;
    in {
      nixosConfigurations = {
        node01 = mkNode "node01";
        node02 = mkNode "node02";
        node03 = mkNode "node03";
        node04 = mkNode "node04";
        node05 = mkNode "node05";
        node06 = mkNode "node06";
        storage-node01 = mkNode "storage-node01";
        storage-node02 = mkNode "storage-node02";
        storage-node03 = mkNode "storage-node03";
        storage-node04 = mkNode "storage-node04";
        storage-node05 = mkNode "storage-node05";
      };

      packages.${system} = {
        cluster = clusterHarness;
        vmGuestImage = vmGuestImage;
        vmBenchGuestImage = vmBenchGuestImage;
        deployerClusterState =
          self.nixosConfigurations.node06.config.system.build.ultracloudDeployerClusterState;
      };

      apps.${system}.cluster = {
        type = "app";
        program = "${clusterHarness}/bin/ultracloud-test-cluster";
      };

      devShells.${system}.default = pkgs.mkShell {
        packages = with pkgs; [
          curl
          grpcurl
          jq
          llvmPackages.clang
          llvmPackages.libclang
          openssh
          protobuf
          clusterPython
          qemu
          sshpass
          vde2
        ];
        LIBCLANG_PATH = "${pkgs.llvmPackages.libclang.lib}/lib";
        PROTOC = "${pkgs.protobuf}/bin/protoc";
      };
    };
}
