diff options
author | Robert Schütz <robert.schuetz@stud.uni-heidelberg.de> | 2018-02-04 01:30:47 +0100 |
---|---|---|
committer | Robert Schütz <robert.schuetz@stud.uni-heidelberg.de> | 2018-02-04 11:09:55 +0100 |
commit | 59eb19224b9aebf3b2f86915ab8e85e4024e9b24 (patch) | |
tree | 25abcbdbe3cae3234ac58aed20ad5a90b810a1ac /nixos/modules/services/misc | |
parent | 88c16a63c6e4355f1e7f78e1727f19a1c8eabee0 (diff) | |
download | nixlib-59eb19224b9aebf3b2f86915ab8e85e4024e9b24.tar nixlib-59eb19224b9aebf3b2f86915ab8e85e4024e9b24.tar.gz nixlib-59eb19224b9aebf3b2f86915ab8e85e4024e9b24.tar.bz2 nixlib-59eb19224b9aebf3b2f86915ab8e85e4024e9b24.tar.lz nixlib-59eb19224b9aebf3b2f86915ab8e85e4024e9b24.tar.xz nixlib-59eb19224b9aebf3b2f86915ab8e85e4024e9b24.tar.zst nixlib-59eb19224b9aebf3b2f86915ab8e85e4024e9b24.zip |
nixos/home-assistant: support platform=... scheme for autoExtraComponents
See https://home-assistant.io/components/sensor.luftdaten/ for an example component using that scheme.
Diffstat (limited to 'nixos/modules/services/misc')
-rw-r--r-- | nixos/modules/services/misc/home-assistant.nix | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/nixos/modules/services/misc/home-assistant.nix b/nixos/modules/services/misc/home-assistant.nix index 666fa68b01ce..cc60a143fa6c 100644 --- a/nixos/modules/services/misc/home-assistant.nix +++ b/nixos/modules/services/misc/home-assistant.nix @@ -9,8 +9,27 @@ let availableComponents = pkgs.home-assistant.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"; + # ... + # } ]; + useComponentPlatform = component: + let + path = splitString "." component; + parentConfig = attrByPath (init path) null cfg.config; + platform = last path; + in isList parentConfig && any + (item: item.platform or null == platform) + parentConfig; + # Returns whether component is used in config - useComponent = component: hasAttrByPath (splitString "." component) cfg.config; + useComponent = component: + hasAttrByPath (splitString "." component) cfg.config + || useComponentPlatform component; # List of components used in config extraComponents = filter useComponent availableComponents; |