mirror of
https://github.com/ilyakooo0/nixpkgs.git
synced 2024-09-21 12:38:41 +03:00
nixos/home-assistant: don't run json2yaml at every start
This commit is contained in:
parent
7cc7c5374c
commit
f908f6c982
@ -6,12 +6,18 @@ let
|
|||||||
cfg = config.services.home-assistant;
|
cfg = config.services.home-assistant;
|
||||||
|
|
||||||
# cfg.config != null can be assumed here
|
# cfg.config != null can be assumed here
|
||||||
configFile = pkgs.writeText "configuration.json"
|
configJSON = pkgs.writeText "configuration.json"
|
||||||
(builtins.toJSON (if cfg.applyDefaultConfig then
|
(builtins.toJSON (if cfg.applyDefaultConfig then
|
||||||
(recursiveUpdate defaultConfig cfg.config) else cfg.config));
|
(recursiveUpdate defaultConfig cfg.config) else cfg.config));
|
||||||
|
configFile = pkgs.runCommand "configuration.yaml" { } ''
|
||||||
|
${pkgs.remarshal}/bin/json2yaml -i ${configJSON} -o $out
|
||||||
|
'';
|
||||||
|
|
||||||
lovelaceConfigFile = pkgs.writeText "ui-lovelace.json"
|
lovelaceConfigJSON = pkgs.writeText "ui-lovelace.json"
|
||||||
(builtins.toJSON cfg.lovelaceConfig);
|
(builtins.toJSON cfg.lovelaceConfig);
|
||||||
|
lovelaceConfigFile = pkgs.runCommand "ui-lovelace.yaml" { } ''
|
||||||
|
${pkgs.remarshal}/bin/json2yaml -i ${lovelaceConfigJSON} -o $out
|
||||||
|
'';
|
||||||
|
|
||||||
availableComponents = pkgs.home-assistant.availableComponents;
|
availableComponents = pkgs.home-assistant.availableComponents;
|
||||||
|
|
||||||
@ -175,15 +181,11 @@ in {
|
|||||||
description = "Home Assistant";
|
description = "Home Assistant";
|
||||||
after = [ "network.target" ];
|
after = [ "network.target" ];
|
||||||
preStart = optionalString (cfg.config != null) ''
|
preStart = optionalString (cfg.config != null) ''
|
||||||
config="${cfg.configDir}/configuration.yaml"
|
rm -f "${cfg.configDir}/configuration.yaml"
|
||||||
rm -f $config
|
ln -s ${configFile} "${cfg.configDir}/configuration.yaml"
|
||||||
${pkgs.remarshal}/bin/json2yaml -i ${configFile} -o $config
|
|
||||||
chmod 444 $config
|
|
||||||
'' + optionalString (cfg.lovelaceConfig != null) ''
|
'' + optionalString (cfg.lovelaceConfig != null) ''
|
||||||
config="${cfg.configDir}/ui-lovelace.yaml"
|
rm -f "${cfg.configDir}/ui-lovelace.yaml"
|
||||||
rm -f $config
|
ln -s ${lovelaceConfigFile} "${cfg.configDir}/ui-lovelace.yaml"
|
||||||
${pkgs.remarshal}/bin/json2yaml -i ${lovelaceConfigFile} -o $config
|
|
||||||
chmod 444 $config
|
|
||||||
'';
|
'';
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
ExecStart = "${package}/bin/hass --config '${cfg.configDir}'";
|
ExecStart = "${package}/bin/hass --config '${cfg.configDir}'";
|
||||||
|
@ -71,7 +71,8 @@ in {
|
|||||||
|
|
||||||
# The config is specified using a Nix attribute set,
|
# The config is specified using a Nix attribute set,
|
||||||
# but then converted from JSON to YAML
|
# but then converted from JSON to YAML
|
||||||
$hass->succeed("test -f ${configDir}/configuration.yaml");
|
$hass->succeed("test -L ${configDir}/configuration.yaml");
|
||||||
|
$hass->succeed("test -L ${configDir}/ui-lovelace.yaml");
|
||||||
|
|
||||||
# Check that Home Assistant's web interface and API can be reached
|
# Check that Home Assistant's web interface and API can be reached
|
||||||
$hass->waitForOpenPort(8123);
|
$hass->waitForOpenPort(8123);
|
||||||
|
Loading…
Reference in New Issue
Block a user