Apache wsgi_mod with specific python27 packages

Hello All,
I would like to ask how to get pkgs.apacheHttpdPackages.mod_wsgi to use specific python environment or python with desired site packages.

The desired python environment that works is in default.nix below. I know it should be somehow possible to do it with overlays but I can’t seem to figure out how. Would anybody know how to do these things?

Many thanks.

default.nix mentioned above, note that ignoreCollisions = true;:

with import <nixpkgs> {};
stdenv.mkDerivation rec {
  name = "pjbrefct";

  # Mandatory boilerplate for buildable env
  env = buildEnv { name = name; paths = buildInputs; };
  builder = builtins.toFile "builder.sh" ''
    source $stdenv/setup; ln -s $env $out
  '';

  # Customizable development requirements
  buildInputs = [
    # Add packages from nix-env -qaP | grep -i needle queries

    # With Python configuration requiring a special wrapper
    (python27.buildEnv.override {
      ignoreCollisions = true;
      extraLibs = with python27Packages; [
        # Add pythonPackages without the prefix
        Babel chardet decorator docutils feedparser gevent greenlet html2text jinja2 libsass lxml Mako markupsafe mock  ofxparse passlib pillow psutil psycopg2 pydot  pyparsing pypdf2 pyserial python-dateutil pytz pyusb qrcode reportlab requests suds-jurko vobject werkzeug xlwt xlrd simplejson pychart unittest2 pycountry numpy unicodecsv  matplotlib pyyaml openidc-client
        
      ];
    })
  ];

  # Customizable development shell setup with at last SSL certs set
  #shellHook = ''
  #  export SSL_CERT_FILE=${cacert}/etc/ssl/certs/ca-bundle.crt
  #'';
}

My nixos:

 - system: `"x86_64-linux"`
 - host os: `Linux 4.19.72, NixOS, 19.03.git.2dfae8e (Koi)`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.2.2`
 - channels(root): `"nixos-19.03.173506.2dfae8e22fd"`
 - channels(jan): `""`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixos`

Let’s assume that you’d want to run a Python 2.x package called FOOBAR in mod_wsgi. Then you need to make the appropriate Python search path known to Apache:

httpd = {
  extraConfig = ''
    WSGISocketPrefix /run/httpd/wsgi
    WSGIDaemonProcess foobar threads=25 python-path=${
      lib.makeSearchPath pkgs.python2.sitePackages
        pkgs.python2Packages.FOOBAR.requiredPythonModules
    }
  '';
};

Now,you’ll typically have some “main” script that implements the WSGI app. Let’s say that program lives in webRoot. Then you can attach a virtual host to that application by defining:

virtualHosts = [
  { hostName = "example.org";
    extraConfig = ''
      <Directory "${webRoot}">
        <Files wsgi.py>
          Require all granted
        </Files>
        WSGIProcessGroup foobar
      </Directory>
      WSGIScriptAlias / ${webRoot}/wsgi.py
    '';
  }
]

Thanks peti, I thought I will be able to pass somehow the list of python packages to mod_wsgi as an argument. But this solution is good. Thanks a lot.