Home-assistant on Nix
Want to get started with home assistant but you want to do it on NixOS? You've come to the right blogpost. I just did that this week using NixOS inside WSL. To get started with NixOS in WSL, I recommend this guide. Now back to home-assistant.
Getting started
I assume that you have a basic knowledge of NixOS, know how to use /etc/nixos/configuration.nix and the nixos-rebuild switch command.
Jump over to the NixOS wiki home assistant page and grab the config under Declarative configuration (se below).
{
services.home assistant = {
enable = true;
extraComponents = [
# Components required to complete the onboarding
"esphome"
"met"
"radio_browser"
];
config = {
# Includes dependencies for a basic setup
# https://www.home assistant.io/integrations/default_config/
default_config = {};
};
};
}
If you are not on WSL you might want to grab the following line to open up your firewall:
{
networking.firewall.allowedTCPPorts = [ <other ports> 8123 ];
}
If you are like me you can put all this in a file called home-assistant.nix or directly into the configuration.nix. If you do the separate file you I assume you want to put it somewhere else then /etc/nixos/. Remember to create a symbolic link to make it available to your configuration file. To create the link do sudo ln -s <full path>/home assistant.nix /etc/nixos/home assistant.nix and then add
imports = [
# Your other imports...
./home assistant.nix
];
to add it to your configuration. There are of course a 100 ways to organize your .nix files but this is one example. Now run nixos-rebuild switch and wait for it to complete.
Enter home assistant
You can now access home assistant at localhost:8123 and create your user account. Now lets say that you want to add your Shelly H&T devices.
- You go to
Settings > Devices & Services - Click
+ ADD INTEGRATION - Search for Shelly in the list and select it.
- Just to be greeted with the message
Config flow could not be loaded: {"message":"Invalid handler specified"}. This is the "magic" of Nix. Since the entire system is configured declaratively the integrations need to be installed as package. All available home assistant Nix packages can be found on Github and if it is not available I recommend this guide to get it working. So to add the Shelly package, do the following: - Go into your
home assistant.nixfile and add the "shelly" underextraComponents. - Now do
nixos-rebuild switch. - Now the Shelly integration is available in home assistant. The beautiful thing about this is that to create a copy of your home assistant configuration is a breeze since the whole system can be declared using Nix and the copied to another system.
Conclusion
Now you got a minimal home assistant stack up and running on NixSO. I will probably get back and create an update to this post when I migrate from my basic WSL configuration and to a NixOS VM on my Proxmox setup. Best of luck and have fun!