blob: 86d2968dbcfbb9a14eaa229cd8b7c92105fab967 (
plain)
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
{
description = "Poetry Python dev shell with CUDA + common native libs";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
};
outputs = { self, nixpkgs }:
let
systems = [
"x86_64-linux"
"aarch64-linux"
];
forAllSystems = f:
nixpkgs.lib.genAttrs systems (system: f system);
in
{
devShells = forAllSystems (system:
let
pkgs = import nixpkgs {
inherit system;
config = {
allowUnfree = true;
cudaSupport = true;
};
};
python = pkgs.python312;
runtimeLibs = with pkgs; [
stdenv.cc.cc.lib
zlib
openssl
libffi
sqlite
xz
bzip2
readline
ncurses
expat
openblas
glib
libGL
libxkbcommon
xorg.libX11
xorg.libXext
xorg.libXrender
xorg.libXi
xorg.libXrandr
xorg.libXcursor
xorg.libXfixes
xorg.libXinerama
alsa-lib
ffmpeg
cudaPackages.cudatoolkit
cudaPackages.cudnn
];
libPath = pkgs.lib.makeLibraryPath runtimeLibs;
dynamicLinker = pkgs.lib.fileContents "${pkgs.stdenv.cc}/nix-support/dynamic-linker";
in
{
default = pkgs.mkShell {
packages = with pkgs; [
python
poetry
# build tools for packages with native extensions
pkg-config
gcc
gfortran
gnumake
cmake
ninja
patchelf
git
] ++ runtimeLibs;
NIX_LD = dynamicLinker;
NIX_LD_LIBRARY_PATH = libPath;
LD_LIBRARY_PATH = libPath + ":/run/opengl-driver/lib:/run/opengl-driver-32/lib";
CUDA_PATH = "${pkgs.cudaPackages.cudatoolkit}";
CUDA_HOME = "${pkgs.cudaPackages.cudatoolkit}";
POETRY_VIRTUALENVS_CREATE = "true";
POETRY_VIRTUALENVS_IN_PROJECT = "true";
shellHook = ''
export PATH="${python}/bin:$PATH"
if [ -f pyproject.toml ]; then
poetry env use ${python}/bin/python >/dev/null 2>&1 || true
# Uncomment this block if you want first entry into nix develop
# to automatically install the project deps.
#
# if [ ! -d .venv ]; then
# echo "No .venv found; running poetry install..."
# poetry install
# fi
echo
echo "Python: $(which python)"
echo "Poetry env: $(poetry env info --path 2>/dev/null || true)"
echo "Run once: poetry install"
echo "Then: poetry run python3 main.py"
echo
fi
'';
};
});
};
}
|