diff --git a/nixos/modules/services/misc/home-assistant.nix b/nixos/modules/services/misc/home-assistant.nix index 8279d075bafb..2de25d87ed39 100644 --- a/nixos/modules/services/misc/home-assistant.nix +++ b/nixos/modules/services/misc/home-assistant.nix @@ -24,6 +24,8 @@ let availableComponents = cfg.package.availableComponents; + explicitComponents = cfg.package.extraComponents; + usedPlatforms = config: if isAttrs config then optional (config ? platform) config.platform @@ -42,10 +44,13 @@ let # } ]; useComponentPlatform = component: elem component (usedPlatforms cfg.config); - # Returns whether component is used in config + useExplicitComponent = component: elem component explicitComponents; + + # Returns whether component is used in config or explicitly passed into package useComponent = component: hasAttrByPath (splitString "." component) cfg.config - || useComponentPlatform component; + || useComponentPlatform component + || useExplicitComponent component; # List of components used in config extraComponents = filter useComponent availableComponents; diff --git a/nixos/tests/home-assistant.nix b/nixos/tests/home-assistant.nix index 0894736bac9c..1ab5755863f7 100644 --- a/nixos/tests/home-assistant.nix +++ b/nixos/tests/home-assistant.nix @@ -24,6 +24,11 @@ in { services.home-assistant = { inherit configDir; enable = true; + package = (pkgs.home-assistant.override { + extraComponents = [ "zha" ]; + }).overrideAttrs (oldAttrs: { + doInstallCheck = false; + }); config = { homeassistant = { name = "Home"; @@ -87,6 +92,8 @@ in { with subtest("Check that capabilities are passed for emulated_hue to bind to port 80"): hass.wait_for_open_port(80) hass.succeed("curl --fail http://localhost:80/description.xml") + with subtest("Check extra components are considered in systemd unit hardening"): + hass.succeed("systemctl show -p DeviceAllow home-assistant.service | grep -q char-ttyUSB") with subtest("Print log to ease debugging"): output_log = hass.succeed("cat ${configDir}/home-assistant.log") print("\n### home-assistant.log ###\n") diff --git a/pkgs/servers/home-assistant/default.nix b/pkgs/servers/home-assistant/default.nix index 4b4cb222e964..5febf010dff8 100644 --- a/pkgs/servers/home-assistant/default.nix +++ b/pkgs/servers/home-assistant/default.nix @@ -888,7 +888,7 @@ in with py.pkgs; buildPythonApplication rec { ''; passthru = { - inherit availableComponents; + inherit availableComponents extraComponents; python = py; tests = { inherit (nixosTests) home-assistant;