See part 1 for the actual setup of a custom_component in NixOS. During part 2 we will look howto package an additional python dependency, not part of NixOS yet.

We are going to package the tomeko12/pyelectroluxconnect package.

First of all declare a package

{ lib
, buildPythonPackage
, requests
, beautifulsoup4
, fetchFromGitHub

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

  src = fetchFromGitHub {
    owner = "tomeko12";
    repo = "pyelectroluxconnect";
    rev = version;
    sha256 = "1jkbmaiwad5kmryqmm83jvab8vy6kxvj2v8vn0jggsa4xm7rzgwm";

  propagatedBuildInputs = [ requests beautifulsoup4 ];

  doCheck = false;

  pythonImportsCheck = [ "pyelectroluxconnect" ];

  meta = with lib; {
    description = "Python client package to communicate with the Electrolux Connectivity Platform";
    homepage = "";
    license = licenses.asl20;
    maintainers = with maintainers; [ nathan-gs ];

We save this to a file pyelectroluxconnect.nix.

Import the package

In services.home-assistant.extraPackages we can declare extra dependencies.

extraPackages = ps: with ps; [
  (callPackage pyelectroluxconnect.nix {})

In this case spotipy is an already packaged dependency in NixOS (ever growing), be sure to first check

(callPackage pyelectroluxconnect.nix {}) is a function call that evaluates the Nix expression in the file pyelectroluxconnect.nix with an empty set {} as the argument.


Finally we apply our config using nixos-rebuild switch and we reload Home Assistant.

Your Home Assistant custom_component with extra dependencies is now ready for use.