forked from nix-community/pip2nix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdefault.nix
72 lines (63 loc) · 2.04 KB
/
default.nix
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
{ pkgs ? (import <nixpkgs> {})
, pythonPackages ? "python36Packages"
}:
with pkgs.lib;
let
basePythonPackages = with builtins; if isAttrs pythonPackages
then pythonPackages
else getAttr pythonPackages pkgs;
# Works with the new python-packages, still can fallback to the old
# variant.
basePythonPackagesUnfix = basePythonPackages.__unfix__ or (
self: basePythonPackages.override (a: { inherit self; }));
elem = builtins.elem;
basename = path: last (splitString "/" path);
startsWith = prefix: full: let
actualPrefix = builtins.substring 0 (builtins.stringLength prefix) full;
in actualPrefix == prefix;
src-filter = path: type:
let
ext = last (splitString "." path);
parts = last (splitString "/" path);
in
!elem (basename path) [".git" "__pycache__" ".eggs" "_bootstrap_env"] &&
!elem ext ["egg-info" "pyc"] &&
!startsWith "result" (basename path);
pip2nix-src = builtins.filterSource src-filter ./.;
pythonPackagesLocalOverrides = self: super: {
pip2nix = super.pip2nix.override (attrs: rec {
src = pip2nix-src;
buildInputs = [
self.pip
pkgs.nix
] ++ attrs.buildInputs;
pythonWithSetuptools = self.python.withPackages(ps: with ps; [
setuptools
]);
propagatedBuildInputs = [
pythonWithSetuptools
] ++ attrs.propagatedBuildInputs;
preBuild = ''
export NIX_PATH=nixpkgs=${pkgs.path}
export SSL_CERT_FILE=${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt
'';
postInstall = ''
for f in $out/bin/*
do
wrapProgram $f \
--set PIP2NIX_PYTHON_EXECUTABLE ${pythonWithSetuptools}/bin/python
done
'';
});
pip = basePythonPackages.pip;
};
pythonPackagesGenerated = import ./python-packages.nix {
inherit pkgs;
inherit (pkgs) fetchurl fetchgit fetchhg;
};
myPythonPackages =
(fix
(extends pythonPackagesLocalOverrides
(extends pythonPackagesGenerated
basePythonPackagesUnfix)));
in myPythonPackages.pip2nix