<commit_before>{ config, lib, pkgs, ... }:

with lib;

let
  cfg = config.services.home-assistant;

  # cfg.config != null can be assumed here
  configJSON = pkgs.writeText "configuration.json"
    (builtins.toJSON (if cfg.applyDefaultConfig then
    (recursiveUpdate defaultConfig cfg.config) else cfg.config));
  configFile = pkgs.runCommand "configuration.yaml" { } ''
    ${pkgs.remarshal}/bin/json2yaml -i ${configJSON} -o $out
  '';

  lovelaceConfigJSON = pkgs.writeText "ui-lovelace.json"
    (builtins.toJSON cfg.lovelaceConfig);
  lovelaceConfigFile = pkgs.runCommand "ui-lovelace.yaml" { } ''
    ${pkgs.remarshal}/bin/json2yaml -i ${lovelaceConfigJSON} -o $out
  '';

  availableComponents = cfg.package.availableComponents;

  # Given component "parentConfig.platform", returns whether config.parentConfig
  # is a list containing a set with set.platform == "platform".
  #
  # For example, the component sensor.luftdaten is used as follows:
  # config.sensor = [ {
  #   platform = "luftdaten";
  #   ...
  # } ];
  #
  # Beginning with 0.87 Home Assistant is migrating their components to the
  # scheme "platform.subComponent", e.g. "hue.light" instead of "light.hue".
  # See https://developers.home-assistant.io/blog/2019/02/19/the-great-migration.html.
  # Hence, we also check whether we find an entry in the config when interpreting
  # the first part of the path as the component.
  useComponentPlatform = component:
    let
      path = splitString "." component;
      # old: platform is the last part of path<commit_msg>nixos/home-assistant: use `preferLocalBuild = true` for configuration<commit_after>{ config, lib, pkgs, ... }:

with lib;

let
  cfg = config.services.home-assistant;

  # cfg.config != null can be assumed here
  configJSON = pkgs.writeText "configuration.json"
    (builtins.toJSON (if cfg.applyDefaultConfig then
    (recursiveUpdate defaultConfig cfg.config) else cfg.config));
  configFile = pkgs.runCommand "configuration.yaml" { preferLocalBuild = true; } ''
    ${pkgs.remarshal}/bin/json2yaml -i ${configJSON} -o $out
  '';

  lovelaceConfigJSON = pkgs.writeText "ui-lovelace.json"
    (builtins.toJSON cfg.lovelaceConfig);
  lovelaceConfigFile = pkgs.runCommand "ui-lovelace.yaml" { preferLocalBuild = true; } ''
    ${pkgs.remarshal}/bin/json2yaml -i ${lovelaceConfigJSON} -o $out
  '';

  availableComponents = cfg.package.availableComponents;

  # Given component "parentConfig.platform", returns whether config.parentConfig
  # is a list containing a set with set.platform == "platform".
  #
  # For example, the component sensor.luftdaten is used as follows:
  # config.sensor = [ {
  #   platform = "luftdaten";
  #   ...
  # } ];
  #
  # Beginning with 0.87 Home Assistant is migrating their components to the
  # scheme "platform.subComponent", e.g. "hue.light" instead of "light.hue".
  # See https://developers.home-assistant.io/blog/2019/02/19/the-great-migration.html.
  # Hence, we also check whether we find an entry in the config when interpreting
  # the first part of the path as the component.
  useComponentPlatform = component:
    let
      path = splitString "." component;
      # old: platform is the last part of path
{'fraction_non_alphanumeric': 0.11827284105131414, 'fraction_numerical': 0.008135168961201502, 'mean_word_length': 3.6266280752532563, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '405963', 'n_tokens_mistral': 1038, 'n_tokens_neox': 990, 'n_words': 276}