{ config, lib, pkgs, ... }:

with lib;

let

  cfg = config.services.homeAssistantConfig;

  mkMagicMergeOption = { description ? "", example ? { }, default ? { }, ... }:
    mkOption {
      inherit example description default;
      type = with lib.types;
        let
          valueType = nullOr (oneOf [
            bool
            int
            float
            str
            (attrsOf valueType)
            (listOf valueType)
          ]) // {
            description = "";
            emptyValue.value = { };
          };
        in valueType;
    };

in {

  options.services.homeAssistantConfig = mkMagicMergeOption {
    description = ''
      home-assistant configuration
    '';
  };

  config = mkIf (cfg != null) { services.home-assistant.config = cfg; };
}