How to declare Kodi to have pycryptodomex accessible?

Hi,

I am having problems setting up Kodi with the Netflix plugin from https://github.com/CastagnaIT/plugin.video.netflix. I am having a problem declaring my configuration.nix in such a way that the kodi has access to the pycryptodomex python module. The problem manifests itself in an exception message when the netflix plugin is loaded:

2021-01-09 19:32:48.183 T:140026990024448   ERROR: [plugin.video.netflix (0)] Background services do not start due to the following error
2021-01-09 19:32:48.188 T:140026990024448   ERROR: [plugin.video.netflix (0)] Traceback (most recent call last):
                                              File "/home/kodi/.kodi/addons/plugin.video.netflix/resources/lib/run_service.py", line 68, in init_servers
                                                self._init_server(server)
                                              File "/home/kodi/.kodi/addons/plugin.video.netflix/resources/lib/run_service.py", line 89, in _init_server
                                                (self.HOST_ADDRESS, select_port(server['name']))
                                              File "/home/kodi/.kodi/addons/plugin.video.netflix/resources/lib/services/msl/http_server.py", line 95, in __init__
                                                self.msl_handler = MSLHandler()
                                              File "/home/kodi/.kodi/addons/plugin.video.netflix/resources/lib/services/msl/msl_handler.py", line 76, in __init__
                                                self._init_msl_handler()
                                              File "/home/kodi/.kodi/addons/plugin.video.netflix/resources/lib/services/msl/msl_handler.py", line 100, in _init_msl_handler
                                                self.msl_requests = MSLRequests(msl_data)
                                              File "/home/kodi/.kodi/addons/plugin.video.netflix/resources/lib/services/msl/msl_requests.py", line 35, in __init__
                                                super(MSLRequests, self).__init__()
                                              File "/home/kodi/.kodi/addons/plugin.video.netflix/resources/lib/services/msl/msl_request_builder.py", line 32, in __init__
                                                from .default_crypto import DefaultMSLCrypto as MSLCrypto
                                              File "/home/kodi/.kodi/addons/plugin.video.netflix/resources/lib/services/msl/default_crypto.py", line 32, in <module>
                                                from Crypto.Random import get_random_bytes
                                            ImportError: No module named Crypto.Random

My configuration.nix is the following:

{ config, pkgs, ... }:

with pkgs;
let
  my-python-packages = python-packages: with python-packages; [
    pip
    # other python packages you want
  ];
  python-with-my-packages = python3.withPackages my-python-packages;
in {
  imports =
    [ # Include the results of the hardware scan.
      ./hardware-configuration.nix
    ];

  # Configure keymap in X11
  services.xserver.layout = "pl";
  # services.xserver.xkbOptions = "eurosign:e";

  services.xserver.enable = true;

  services.xserver.desktopManager.kodi.enable = true;

  services.xserver.displayManager.lightdm.enable = true;
  services.xserver.displayManager.autoLogin.enable = true;
  services.xserver.displayManager.autoLogin.user = "kodi";

  # Define a user account
  users.users.kodi.isNormalUser = true;
  users.users.kodi.extraGroups = [ "audio" ];
  users.users.kodi.packages = with pkgs; [

  	# https://github.com/NixOS/nixpkgs/pull/105741
	(kodi.override { plugins = with kodiPlugins; [
		(python2Packages.pycryptodomex // { extraRuntimeDependencies = []; })
		(python2Packages.pycryptodome // { extraRuntimeDependencies = []; })
	]; })

  ];

  # Enable sound.
  sound.enable = true;
  # hardware.pulseaudio.enable = true;

  system.stateVersion = "20.09"; # Did you read the comment?

}

I have tried to use an override as you can see above based on what I found in the referenced pull request for Kodi. This doesn’t help however and I seem to be stuck. Does anyone have any hints on what should be done to make kodi see the python module? I have searched on stackoverflow and github issues but apart from the referenced pullrequest I haven’t found any information about such an issue.

Probably should have read your post more clearly… I’ll take a look and get back to you.

You need to override the pkgs.kodi, which setting services.xserver.desktopManager.kodi.enable = true; will make your system use, via an overlay. Something like this should work:

  services.xserver.enable = true;

  services.xserver.desktopManager.kodi.enable = true;

  services.xserver.displayManager.lightdm.enable = true;
  services.xserver.displayManager.autoLogin.enable = true;
  services.xserver.displayManager.autoLogin.user = "kodi";

  nixpkgs.overlays = [
    (self: super: {
      kodi = (super.kodi.override {
        plugins = with super.kodiPlugins; [
          (self.kodi.pythonPackages.pycryptodomex // { extraRuntimeDependencies = []; }) # for netflix
        ];
      });
    })
  ];

Thanks a lot, the below worked:

  nixpkgs.overlays = [
    (self: super: {
      kodi = (super.kodi.override {
        plugins = with super.kodiPlugins; [
          (pythonPackages.pycryptodomex // { extraRuntimeDependencies = []; }) # for netflix
        ];
      });
    })
  ];

I was trying to do an override before but I’m a beginner in nixos and it was a bit unclear to me how to do this properly.