mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-07-13 21:50:33 +03:00
Merge pull request #54541 from dotlambda/home-assistant-0.86
home-assistant: 0.85.1 -> 0.86.4
This commit is contained in:
commit
7003a28916
5 changed files with 152 additions and 62 deletions
|
@ -6,9 +6,18 @@ let
|
|||
cfg = config.services.home-assistant;
|
||||
|
||||
# cfg.config != null can be assumed here
|
||||
configFile = pkgs.writeText "configuration.json"
|
||||
configJSON = pkgs.writeText "configuration.json"
|
||||
(builtins.toJSON (if cfg.applyDefaultConfig then
|
||||
(lib.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
|
||||
'';
|
||||
|
||||
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 = pkgs.home-assistant.availableComponents;
|
||||
|
||||
|
@ -45,6 +54,8 @@ let
|
|||
defaultConfig = {
|
||||
homeassistant.time_zone = config.time.timeZone;
|
||||
http.server_port = (toString cfg.port);
|
||||
} // optionalAttrs (cfg.lovelaceConfig != null) {
|
||||
lovelace.mode = "yaml";
|
||||
};
|
||||
|
||||
in {
|
||||
|
@ -99,6 +110,53 @@ in {
|
|||
'';
|
||||
};
|
||||
|
||||
configWritable = mkOption {
|
||||
default = false;
|
||||
type = types.bool;
|
||||
description = ''
|
||||
Whether to make <filename>configuration.yaml</filename> writable.
|
||||
This only has an effect if <option>config</option> is set.
|
||||
This will allow you to edit it from Home Assistant's web interface.
|
||||
However, bear in mind that it will be overwritten at every start of the service.
|
||||
'';
|
||||
};
|
||||
|
||||
lovelaceConfig = mkOption {
|
||||
default = null;
|
||||
type = with types; nullOr attrs;
|
||||
# from https://www.home-assistant.io/lovelace/yaml-mode/
|
||||
example = literalExample ''
|
||||
{
|
||||
title = "My Awesome Home";
|
||||
views = [ {
|
||||
title = "Example";
|
||||
cards = [ {
|
||||
type = "markdown";
|
||||
title = "Lovelace";
|
||||
content = "Welcome to your **Lovelace UI**.";
|
||||
} ];
|
||||
} ];
|
||||
}
|
||||
'';
|
||||
description = ''
|
||||
Your <filename>ui-lovelace.yaml</filename> as a Nix attribute set.
|
||||
Setting this option will automatically add
|
||||
<literal>lovelace.mode = "yaml";</literal> to your <option>config</option>.
|
||||
Beware that setting this option will delete your previous <filename>ui-lovelace.yaml</filename>
|
||||
'';
|
||||
};
|
||||
|
||||
lovelaceConfigWritable = mkOption {
|
||||
default = false;
|
||||
type = types.bool;
|
||||
description = ''
|
||||
Whether to make <filename>ui-lovelace.yaml</filename> writable.
|
||||
This only has an effect if <option>lovelaceConfig</option> is set.
|
||||
This will allow you to edit it from Home Assistant's web interface.
|
||||
However, bear in mind that it will be overwritten at every start of the service.
|
||||
'';
|
||||
};
|
||||
|
||||
package = mkOption {
|
||||
default = pkgs.home-assistant;
|
||||
defaultText = "pkgs.home-assistant";
|
||||
|
@ -144,12 +202,17 @@ in {
|
|||
systemd.services.home-assistant = {
|
||||
description = "Home Assistant";
|
||||
after = [ "network.target" ];
|
||||
preStart = lib.optionalString (cfg.config != null) ''
|
||||
config=${cfg.configDir}/configuration.yaml
|
||||
rm -f $config
|
||||
${pkgs.remarshal}/bin/json2yaml -i ${configFile} -o $config
|
||||
chmod 444 $config
|
||||
'';
|
||||
preStart = optionalString (cfg.config != null) (if cfg.configWritable then ''
|
||||
cp --no-preserve=mode ${configFile} "${cfg.configDir}/configuration.yaml"
|
||||
'' else ''
|
||||
rm -f "${cfg.configDir}/configuration.yaml"
|
||||
ln -s ${configFile} "${cfg.configDir}/configuration.yaml"
|
||||
'') + optionalString (cfg.lovelaceConfig != null) (if cfg.lovelaceConfigWritable then ''
|
||||
cp --no-preserve=mode ${lovelaceConfigFile} "${cfg.configDir}/ui-lovelace.yaml"
|
||||
'' else ''
|
||||
rm -f "${cfg.configDir}/ui-lovelace.yaml"
|
||||
ln -s ${lovelaceConfigFile} "${cfg.configDir}/ui-lovelace.yaml"
|
||||
'');
|
||||
serviceConfig = {
|
||||
ExecStart = "${package}/bin/hass --config '${cfg.configDir}'";
|
||||
User = "hass";
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue