Home Assistant: Difference between revisions

From NixOS Wiki
imported>Mic92
add nix-shell expression
imported>Mweinelt
update location block to use options instead of verbatim extraConfig
Line 8: Line 8:
<syntaxHighlight lang=nix>
<syntaxHighlight lang=nix>
   services.nginx = {
   services.nginx = {
    recommendedProxyConfig = true;
     virtualHosts."hass.your-domain.tld" = {
     virtualHosts."hass.your-domain.tld" = {
       addSSL = true;
       addSSL = true;
Line 14: Line 15:
         proxy_buffering off;
         proxy_buffering off;
       '';
       '';
       locations."/".extraConfig = ''
       locations."/" = {
         proxy_pass http://127.0.0.1:8123;
         proxyPass = "http://127.0.0.1:8123";
         proxy_set_header Host $host;
         proxyWebsockets = true;
        proxy_redirect http:// https://;
       };
        proxy_http_version 1.1;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;
       '';
     };
     };
   };
   };

Revision as of 16:38, 22 January 2021

Home Assistant is an open source home automation software that puts local control and privacy first. Powered by a worldwide community of tinkerers and DIY enthusiasts.

Home Assistant with nginx as a reverse proxy

If you run a public Home Assistant instance it is a good idea to enable SSL/TLS. The following configuration generates a certificate using letsencrypt:

  services.nginx = {
    recommendedProxyConfig = true;
    virtualHosts."hass.your-domain.tld" = {
      addSSL = true;
      enableACME = true;
      extraConfig = ''
        proxy_buffering off;
      '';
      locations."/" = {
        proxyPass = "http://127.0.0.1:8123";
        proxyWebsockets = true;
      };
    };
  };

Adding postgresql support

Home-assistant supports PostgreSQL as a database backend for, among other things, its logger and history components. It's a lot more scalable and typically provides faster response times than the SQLite database, that is used by default.

Remember to make backups of your database, for home-assistant is becoming more and more stateful and has moved away from a completely declarative YAML configuration for new and core components.

  services.home-assistant = {
    package = (pkgs.home-assistant.override {
      extraPackages = py: with py; [ psycopg2 ];
    });
    config.recorder.db_url = "postgresql://@/hass";
  };

  services.postgresql = {
    enable = true;
    ensureDatabases = [ "hass" ];
    ensureUsers = [{
      name = "hass";
      ensurePermissions = {
        "DATABASE hass" = "ALL PRIVILEGES";
      };
    }];
  };

Run home-assistant from github repository

When developing home-assistant for some test dependencies additional libraries are needed. A nix-shell expression for this is available here.

Add custom lovelace modules

This pull request describes how to add custom lovelace modules.

Example configurations

- Mic92's config