# Build a raw Navi hive attrset from host specs + deployment targets.
# Call `inputs.navi.lib.makeHive` on the result to produce `flake.naviHive`.
{ lib, inputs, ... }: {
  flake.lib.mkNaviHiveConfig =
    {
      metaNixpkgs,
      hostSpecs,
      deployments,
    }:
    let
      deployNodes = lib.filterAttrs (name: _: deployments ? ${name}) hostSpecs;
    in
    {
      meta = {
        nixpkgs = metaNixpkgs;
        nodeNixpkgs = lib.mapAttrs (
          name: spec:
          import inputs.nixpkgs {
            system = spec.system;
          }
        ) deployNodes;
        nodeSpecialArgs = lib.mapAttrs (_: spec: spec.specialArgs) deployNodes;
        allowApplyAll = false;
      };
    }
    //     lib.mapAttrs (
      name: spec:
      {
        imports = spec.modules or [ spec.configuration ];
        deployment = deployments.${name};
      }
    ) deployNodes;
}
