From ad719a45037641bf03524b956b0e71218634528e Mon Sep 17 00:00:00 2001 From: Martin Weinelt Date: Sun, 11 Feb 2024 03:54:28 +0100 Subject: [PATCH 1/2] home-assistant: update patch to follow symlinks in static dir --- pkgs/servers/home-assistant/default.nix | 2 +- .../patches/static-follow-symlinks.patch | 12 ++++++ .../patches/static-symlinks.patch | 37 ------------------- 3 files changed, 13 insertions(+), 38 deletions(-) create mode 100644 pkgs/servers/home-assistant/patches/static-follow-symlinks.patch delete mode 100644 pkgs/servers/home-assistant/patches/static-symlinks.patch diff --git a/pkgs/servers/home-assistant/default.nix b/pkgs/servers/home-assistant/default.nix index a3d74d51c4df..107a93fed6a9 100644 --- a/pkgs/servers/home-assistant/default.nix +++ b/pkgs/servers/home-assistant/default.nix @@ -485,7 +485,7 @@ in python.pkgs.buildPythonApplication rec { # leave this in, so users don't have to constantly update their downstream patch handling patches = [ # Follow symlinks in /var/lib/hass/www - ./patches/static-symlinks.patch + ./patches/static-follow-symlinks.patch # Patch path to ffmpeg binary (substituteAll { diff --git a/pkgs/servers/home-assistant/patches/static-follow-symlinks.patch b/pkgs/servers/home-assistant/patches/static-follow-symlinks.patch new file mode 100644 index 000000000000..c99a8d88a1e8 --- /dev/null +++ b/pkgs/servers/home-assistant/patches/static-follow-symlinks.patch @@ -0,0 +1,12 @@ +diff --git a/homeassistant/components/http/static.py b/homeassistant/components/http/static.py +index e6e773d4c0..b53e0b4a11 100644 +--- a/homeassistant/components/http/static.py ++++ b/homeassistant/components/http/static.py +@@ -31,7 +31,6 @@ def _get_file_path(rel_url: str, directory: Path) -> Path | None: + # where the static dir is totally different + raise HTTPForbidden + filepath: Path = directory.joinpath(filename).resolve() +- filepath.relative_to(directory) + # on opening a dir, load its contents if allowed + if filepath.is_dir(): + return None diff --git a/pkgs/servers/home-assistant/patches/static-symlinks.patch b/pkgs/servers/home-assistant/patches/static-symlinks.patch deleted file mode 100644 index 7784a60f6b2a..000000000000 --- a/pkgs/servers/home-assistant/patches/static-symlinks.patch +++ /dev/null @@ -1,37 +0,0 @@ -diff --git a/homeassistant/components/frontend/__init__.py b/homeassistant/components/frontend/__init__.py -index 2ec991750f..9a937006ce 100644 ---- a/homeassistant/components/frontend/__init__.py -+++ b/homeassistant/components/frontend/__init__.py -@@ -383,7 +383,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: - - local = hass.config.path("www") - if os.path.isdir(local): -- hass.http.register_static_path("/local", local, not is_dev) -+ hass.http.register_static_path("/local", local, not is_dev, follow_symlinks=True) - - # Can be removed in 2023 - hass.http.register_redirect("/config/server_control", "/developer-tools/yaml") -diff --git a/homeassistant/components/http/__init__.py b/homeassistant/components/http/__init__.py -index 122b7b79ce..3cf2b7e0db 100644 ---- a/homeassistant/components/http/__init__.py -+++ b/homeassistant/components/http/__init__.py -@@ -411,16 +411,16 @@ class HomeAssistantHTTP: - ) - - def register_static_path( -- self, url_path: str, path: str, cache_headers: bool = True -+ self, url_path: str, path: str, cache_headers: bool = True, follow_symlinks: bool = False - ) -> None: - """Register a folder or file to serve as a static path.""" - if os.path.isdir(path): - if cache_headers: - resource: CachingStaticResource | web.StaticResource = ( -- CachingStaticResource(url_path, path) -+ CachingStaticResource(url_path, path, follow_symlinks=follow_symlinks) - ) - else: -- resource = web.StaticResource(url_path, path) -+ resource = web.StaticResource(url_path, path, follow_symlinks=follow_symlinks) - self.app.router.register_resource(resource) - self.app["allow_configured_cors"](resource) - return From 055a8f709ad75bec0aa723e7b413a695d24d7e3a Mon Sep 17 00:00:00 2001 From: Martin Weinelt Date: Sun, 11 Feb 2024 04:09:52 +0100 Subject: [PATCH 2/2] nixos/home-assistant: always add dependencies for default integrations These are loaded unconditionally during bootstrap, and home-assistant will now fail to start, if these aren't provided. --- .../home-automation/home-assistant.nix | 41 ++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/nixos/modules/services/home-automation/home-assistant.nix b/nixos/modules/services/home-automation/home-assistant.nix index 5c2ea8f1840b..3423eebe9ed6 100644 --- a/nixos/modules/services/home-automation/home-assistant.nix +++ b/nixos/modules/services/home-automation/home-assistant.nix @@ -52,7 +52,7 @@ let hasAttrByPath (splitString "." component) cfg.config || useComponentPlatform component || useExplicitComponent component - || builtins.elem component cfg.extraComponents; + || builtins.elem component (cfg.extraComponents ++ cfg.defaultIntegrations); # Final list of components passed into the package to include required dependencies extraComponents = filter useComponent availableComponents; @@ -103,6 +103,45 @@ in { description = lib.mdDoc "The config directory, where your {file}`configuration.yaml` is located."; }; + defaultIntegrations = mkOption { + type = types.listOf (types.enum availableComponents); + # https://github.com/home-assistant/core/blob/dev/homeassistant/bootstrap.py#L109 + default = [ + "application_credentials" + "frontend" + "hardware" + "logger" + "network" + "system_health" + + # key features + "automation" + "person" + "scene" + "script" + "tag" + "zone" + + # built-in helpers + "counter" + "input_boolean" + "input_button" + "input_datetime" + "input_number" + "input_select" + "input_text" + "schedule" + "timer" + + # non-supervisor + "backup" + ]; + readOnly = true; + description = '' + List of integrations set are always set up, unless in recovery mode. + ''; + }; + extraComponents = mkOption { type = types.listOf (types.enum availableComponents); default = [