Since NixOS 23.11 there is a new way of packaging Home Assistant custom components, making some of the work written in earlier blog posts irrelevant. Let’s repackage the electrolux_status and it’s dependency tomeko12/pyelectroluxconnect.

If you’re looking for a way to add custom components to your Home Assistant setup, then NixOS has a good solution. NixOS is an open source Linux distribution that is designed to be functional. This can be a good alternative to have a more declarative configuration in contrast to HACS.

First of all let’s create a package for the dependency pyElectroluxConnect

Unfortunately pyelectroluxconnect is not part of the NixOS packages yet, so we need to do it ourselves.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
{ stdenv, pkgs, lib, buildPythonPackage, fetchFromGitHub }:

buildPythonPackage rec {
  pname = "pyelectroluxconnect";
  version = "0.3.20";

  src = fetchFromGitHub {
    owner = "tomeko12";
    repo = "pyelectroluxconnect";
    rev = version;
    sha256 = "sha256-5eTHJsE5Jof5WSZFkf8/1UQafpgxpGTPuDWQMENgAG0=";
  };

  propagatedBuildInputs = [
    pkgs.python311Packages.requests
    pkgs.python311Packages.beautifulsoup4
  ];

  doCheck = false;

  pythonImportsCheck = [ "pyelectroluxconnect" ];

  meta = with lib; {
    description = "Python client package to communicate with the Electrolux Connectivity Platform";
    homepage = "https://github.com/tomeko12/pyelectroluxconnect";
    license = licenses.asl20;
    maintainers = with maintainers; [ nathan-gs ];
  };
}

This package setup is very basic, we use the buildPythonPackage function, it uses fetchFromGitHub to retrieve the latest release. We can retrieve the sha256 hash using the following cli nix-shell -p nix-prefetch-github --run "nix-prefetch-github --rev 0.3.20 tomeko12 pyelectroluxconnect" which fetches the git repo, and figures out the sha256 of the repo.

We declare the requests and beautifulsoup4 dependencies, these were already part of NixOS.

Creating a custom component from electrolux_status

Using the new buildHomeAssistantComponent we declare a package.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
{ stdenv, pkgs, fetchFromGitHub, buildHomeAssistantComponent, pyelectroluxconnect }:

buildHomeAssistantComponent rec {

  owner = "mauro-modolo";
  domain = "electrolux_status";
  version = "4.1.0";

  src = fetchFromGitHub {
    owner = "mauro-midolo";
    repo = "homeassistant_electrolux_status";
    rev = "v${version}";
    sha256 = "sha256-85p4eG0ePW2EI6vzksSbWLhNfkdrzCiu1KChuPwSobU=";
  };

  propagatedBuildInputs = [
    pyelectroluxconnect
  ];

}

Note the pyelectroluxconnect dependency, both at the top as in the propagatedBuildInputs.

Adding the electrolux_status component to Home Assistant

Since NixOS 23.11 there is a new services.home-assistant.customComponents option. There is a small list of already packaged components in NixOS unstable.

1
2
3
4
5
6
services.home-assistant.customComponents = [
    (pkgs.callPackage ../pkgs/home-assistant/custom_components/solis-sensor.nix {})
    (pkgs.callPackage ../pkgs/home-assistant/custom_components/electrolux-status.nix {
      pyelectroluxconnect = (pkgs.python311Packages.callPackage ../pkgs/python/pyelectroluxconnect.nix {});
    })
  ];

I’m adding 2 custom components, solis-sensor only depending on packages already part of NixOS and the just packaged electrolux_status component. For the electrolux_status component, we need to inject the pyelectroluxconnect package.

NOTE

In an earlier version I leveraged an activationScript to make symlinks to the correct packages, this is no longer necessary and will no longer work.

Conclusions

Finally we apply our config using nixos-rebuild switch and we reload Home Assistant. If you want to take a look at more examples, and a slightly more extensive Home Assistant in NixOS setup, take a look at nathan-gs/nix-conf.

Your Home Assistant custom_component is now ready for use.