From 78c2ca326e4320ca9b53d2dc7eca8b385d2681af Mon Sep 17 00:00:00 2001 From: Robert Schütz Date: Thu, 1 Feb 2018 13:42:07 +0100 Subject: home-assistant: compute extraComponents from config --- nixos/modules/services/misc/home-assistant.nix | 36 ++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 5 deletions(-) (limited to 'nixos/modules') diff --git a/nixos/modules/services/misc/home-assistant.nix b/nixos/modules/services/misc/home-assistant.nix index bc463d3e670c..4fbf5a412d12 100644 --- a/nixos/modules/services/misc/home-assistant.nix +++ b/nixos/modules/services/misc/home-assistant.nix @@ -6,6 +6,19 @@ let cfg = config.services.home-assistant; configFile = pkgs.writeText "configuration.yaml" (builtins.toJSON cfg.config); + + availableComponents = pkgs.home-assistant.availableComponents; + + # Returns whether component is used in config + useComponent = component: hasAttrByPath (splitString "." component) cfg.config; + + # List of components used in config + extraComponents = filter useComponent availableComponents; + + package = if cfg.autoExtraComponents + then (cfg.package.override { inherit extraComponents; }) + else cfg.package; + in { meta.maintainers = with maintainers; [ dotlambda ]; @@ -29,6 +42,7 @@ in { }; frontend = { }; http = { }; + feedreader.urls = [ "https://nixos.org/blogs.xml" ]; } ''; description = '' @@ -48,10 +62,22 @@ in { ''; description = '' Home Assistant package to use. - Most Home Assistant components require additional dependencies, - which are best specified by overriding pkgs.home-assistant. - You can find the dependencies by searching for failed imports in your log or by looking at this list: - + Override extraPackages in order to add additional dependencies. + ''; + }; + + autoExtraComponents = mkOption { + default = true; + type = types.bool; + description = '' + If set to true, the components used in config + are set as the specified package's extraComponents. + This in turn adds all packaged dependencies to the derivation. + You might still see import errors in your log. + In this case, you will need to package the necessary dependencies yourself + or ask for someone else to package them. + If a dependency is packaged but not automatically added to this list, + you might need to specify it in extraPackages. ''; }; }; @@ -67,7 +93,7 @@ in { ''; serviceConfig = { ExecStart = '' - ${cfg.package}/bin/hass --config "${cfg.configDir}" + ${package}/bin/hass --config "${cfg.configDir}" ''; User = "hass"; Group = "hass"; -- cgit 1.4.1