How I'm running Home Assistant in docker on NixOS

2020-07-19 − 🏷 home-automation 🏷 nix

For the last few years I’ve been into home automation, and since I buy random stuff from different vendors and with various protocols, I use Home Assistant to tie it all together. My main home server is a NixOS box, but for a long while I was running home assistant on my old Arch mac mini, because it was such a chore to handle dependencies with the NixOS home assistant service.

Typically home assistant just installs what you need on the fly, but with the nixos version you need to declare everything manually. However, this winter I migrated over to running NixOS in a docker container declaratively. Recent nixos has gained support for running these containers in systemd.

Setting this up is really easy

    docker-containers.hass = {
      image = "homeassistant/home-assistant:0.112.4";
      environment = { TZ = "Europe/Oslo"; };
      extraDockerOptions = ["--net=host" "--device=/dev/serial/by-id/usb-0658_0200-if00"];
      volumes = [ "/var/lib/homeassistant:/config" ];

Here I’m using the official image, and also demonstrating how to set extra docker options, like host networking or forwarding a usb device.

Nixos also provides other commonly used services natively as nix services.

    services.influxdb.enable = true;
    services.mosquitto = {
      enable = true;
      host = "";
      users = { hass = {acl = [ "topic readwrite #" ]; password = "not-my-password"; }; };
      extraConf = "log_type debug";

Now you can also easily upgrade your install by changing the docker image version and doing nixos-rebuild switch