-
Notifications
You must be signed in to change notification settings - Fork 20
/
default.nix
64 lines (59 loc) · 2.55 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
argsOuter@{...}:
let
# specifying args defaults in this slightly non-standard way to allow us to include the default values in `args`
args = rec {
pkgs = import <nixpkgs> {};
pythonPackages = pkgs.python36Packages;
forDev = true;
localOverridesPath = ./local.nix;
} // argsOuter;
sitePrioNonNix = args.pkgs.writeTextFile {
name = "site-prio-non-nix";
destination = "/${args.pythonPackages.python.sitePackages}/sitecustomize.py";
text = ''
import sys
first_nix_i = next((i for i, p in enumerate(sys.path) if p.startswith("/nix/")), 1)
# after the first nix-provided path in sys.path (presumably the python stdlib itself), re-sort all non-nix
# paths to be before the nix paths. this is helped by python's sort being a stable-sort
sys.path[first_nix_i+1:] = sorted(sys.path[first_nix_i+1:], key=lambda p: p.startswith("/nix/"))
'';
};
in (with args; {
digitalMarketplaceApiEnv = (pkgs.stdenv.mkDerivation rec {
name = "digitalmarketplace-api-env";
shortName = "dm-api";
buildInputs = [
pythonPackages.python
sitePrioNonNix
pkgs.glibcLocales
pkgs.libffi
pkgs.libyaml
# pip requires git to fetch some of its dependencies
pkgs.git
# for `cryptography`
pkgs.openssl
# we *would* just depend on the pkgs.postgresql.lib output but pip wants to use the `pg_config` binary during the
# install process
pkgs.postgresql
pkgs.cacert
] ++ pkgs.stdenv.lib.optionals forDev [
# exotic things possibly go here
];
hardeningDisable = pkgs.stdenv.lib.optionals pkgs.stdenv.isDarwin [ "format" ];
GIT_SSL_CAINFO="${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt";
VIRTUALENV_ROOT = (toString (./.)) + "/venv${pythonPackages.python.pythonVersion}";
VIRTUAL_ENV_DISABLE_PROMPT = "1";
SOURCE_DATE_EPOCH = "315532800";
# if we don't have this, we get unicode troubles in a --pure nix-shell
LANG="en_GB.UTF-8";
shellHook = ''
export PS1="\[\e[0;36m\](nix-shell\[\e[0m\]:\[\e[0;36m\]${shortName})\[\e[0;32m\]\u@\h\[\e[0m\]:\[\e[0m\]\[\e[0;36m\]\w\[\e[0m\]\$ "
if [ ! -e $VIRTUALENV_ROOT ]; then
${pythonPackages.python}/bin/python -m venv $VIRTUALENV_ROOT
fi
source $VIRTUALENV_ROOT/bin/activate
pip install --upgrade pip==18.0 # some packages are sensitive to "old" pips
make -C ${toString (./.)} requirements${pkgs.stdenv.lib.optionalString forDev "-dev"}
'';
}).overrideAttrs (if builtins.pathExists localOverridesPath then (import localOverridesPath args) else (x: x));
})