Home-Assistant extra python dependency conflicts

i packaged an optional dependency for home-assistant (gtts-token) to get google_translate TTS working. However, adding it to extraPackages results in conflicts as it seems home-assistant module overrides specific dependencies (in that case the requests and cryptography package).

The dependency is gtts-token (generated by nixpkgs-pytools):

{ lib
, buildPythonPackage
, fetchPypi
, requests
}:

buildPythonPackage rec {
  pname = "gtts-token";
  version = "1.1.3";

  src = fetchPypi {
    pname = "gTTS-token";
    inherit version;
    sha256 = "9d6819a85b813f235397ef931ad4b680f03d843c9b2a9e74dd95175a4bc012c5";
  };

  propagatedBuildInputs = [
    requests
  ];

  meta = with lib; {
    description = "Calculates a token to run the Google Translate text to speech";
    homepage = https://github.com/boudewijn26/gTTS-token;
    license = licenses.mit;
    # maintainers = [ maintainers. ];
  };
}

I tried to add the package like this to home-assistant:

let
  gtts-token = pkgs.python36.pkgs.callPackage ./gtts-token.nix {  };
in {
  services.home-assistant = {
    enable = true;
    package = pkgs.home-assistant.override { python3 = pkgs.python36;
              extraPackages = ps: with ps; [ gtts-token ];
  };
}

The error log i get looks like this:

builder for '/nix/store/8fmd7r98554m8x0iy1shs03jx470l93g-homeassistant-0.86.4.drv' failed with exit code 1; last 10 log lines:
    urllib3 1.24.1 (/nix/store/lbi6rc1sg567sz1ck9y9msk3grqg0shi-python3.6-urllib3-1.24.1/lib/python3.6/site-packages)
    urllib3 1.24.1 (/nix/store/r2pfi05b631z289vj3mr5nh17hfyqcyk-python3.6-urllib3-1.24.1/lib/python3.6/site-packages)
  Found duplicated packages in closure for dependency 'cryptography': 
    cryptography 2.3.1 (/nix/store/flvjy2ni1xkfi49wrnxhx1vv7czxh512-python3.6-cryptography-2.3.1/lib/python3.6/site-packages)
    cryptography 2.5 (/nix/store/3v4n97phd97xm7rlb3abdxx18zyc6g2p-python3.6-cryptography-2.5/lib/python3.6/site-packages)
  Found duplicated packages in closure for dependency 'pyOpenSSL': 
    pyOpenSSL 19.0.0 (/nix/store/znbigq92cdymgnh3nz5aham62qm5da9c-python3.6-pyOpenSSL-19.0.0/lib/python3.6/site-packages)
    pyOpenSSL 19.0.0 (/nix/store/x65q4wydiqbmjbmcgkycs4ih70q544ds-python3.6-pyOpenSSL-19.0.0/lib/python3.6/site-packages)
  
  Package duplicates found in closure, see above. Usually this happens if two packages depend on different version of the same dependency.
cannot build derivation '/nix/store/pd8f3r5zqmnlq0mmq0kcp3v5yfydrp1j-unit-home-assistant.service.drv': 1 dependencies couldn't be built

I thought about getting the correct dependencies from config.services.home-assistant.package however i am unsure how to get the exact dependencies here.

Is there a way to get the package into my module anyway? Iā€™d rather not clone nixpkgs and manage my own fork to get what i need :rocket: .

I finally managed to fix the issue, and for anyone with the same issue, this is what worked for me:

{
  services.home-assistant = {
    enable = true;
    package = pkgs.home-assistant.override {
      extraPackages = ps: with ps; [
        (callPackage ./gtts-token.nix { })
      ];
    };
  };
}
1 Like