{ config, lib, options, ... }:

let
  hostName = config.networking.hostName;
  hasClusterModule = lib.hasAttrByPath [ "ultracloud" "cluster" "enable" ] options;
  clusterNode =
    if hasClusterModule && config.ultracloud.cluster.enable && config.ultracloud.cluster.nodes ? "${hostName}" then
      config.ultracloud.cluster.nodes.${hostName}
    else
      null;
  clusterInstallPlan =
    if clusterNode != null then
      clusterNode.installPlan
    else
      null;
  defaultDiskDevice =
    if clusterInstallPlan != null && clusterInstallPlan.targetDiskById != null then
      clusterInstallPlan.targetDiskById
    else if clusterInstallPlan != null then
      clusterInstallPlan.targetDisk
    else
      null;
in
{
  options.ultracloud.install.diskDevice = lib.mkOption {
    type = lib.types.nullOr lib.types.str;
    default = null;
    description = "Install target disk path used by Disko-enabled host configurations";
  };

  config.ultracloud.install.diskDevice = lib.mkDefault defaultDiskDevice;
}
