-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflake.nix
More file actions
182 lines (163 loc) · 5.28 KB
/
Copy pathflake.nix
File metadata and controls
182 lines (163 loc) · 5.28 KB
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
flake-compat = {
url = "github:NixOS/flake-compat";
flake = false;
};
flake-parts = {
url = "github:hercules-ci/flake-parts";
inputs.nixpkgs-lib.follows = "nixpkgs";
};
pre-commit-hooks = {
url = "github:cachix/git-hooks.nix";
inputs.nixpkgs.follows = "nixpkgs";
};
treefmt-nix = {
url = "github:numtide/treefmt-nix";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs =
inputs@{
flake-parts,
...
}:
flake-parts.lib.mkFlake { inherit inputs; } {
imports = [
inputs.treefmt-nix.flakeModule
inputs.pre-commit-hooks.flakeModule
];
systems = [
"x86_64-linux"
"aarch64-linux"
"aarch64-darwin"
];
perSystem =
{
config,
pkgs,
lib,
...
}:
let
# Use Python 3.13 from nixpkgs
python = pkgs.python313;
# Unfree packages
/*
cudaVersion = "12_8";
pkgs-unfree = import inputs.nixpkgs {
inherit system;
config.allowUnfree = true;
config.cudaSupport = true;
};
inherit (pkgs-unfree.linuxPackages) nvidia_x11;
inherit (pkgs-unfree."cudaPackages_${cudaVersion}")
cudatoolkit
cuda_cudart
cuda_nvrtc
cudnn
nccl
cutensor
cusparselt
;
*/
in
{
# https://flake.parts/options/treefmt-nix.html
# Example: https://github.com/nix-community/buildbot-nix/blob/main/nix/treefmt/flake-module.nix
treefmt = {
projectRootFile = "flake.nix";
settings.global.excludes = [ ];
programs = {
autocorrect.enable = true;
nixfmt.enable = true;
ruff-format.enable = true;
};
};
# https://flake.parts/options/git-hooks-nix.html
# Example: https://github.com/cachix/git-hooks.nix/blob/master/template/flake.nix
pre-commit.settings.hooks = {
commitizen.enable = true;
eclint.enable = true;
markdownlint.enable = true;
ruff.enable = true;
treefmt.enable = true;
};
# This devShell adds Python and CUDA toolchain.
/*
devShells.cuda = pkgs.mkShell rec {
inputsFrom = [
config.treefmt.build.devShell
config.pre-commit.devShell
];
shellHook = ''
unset PYTHONPATH
# CUDA-related
export CUDA_PATH=${cudatoolkit}
export LD_LIBRARY_PATH="${lib.makeLibraryPath pkgs.pythonManylinuxPackages.manylinux1}:${nvidia_x11}/lib:${lib.makeLibraryPath packages}:$LD_LIBRARY_PATH"
export EXTRA_LDFLAGS="-L/lib -L${nvidia_x11}/lib"
export EXTRA_CCFLAGS="-I/usr/include"
echo 1>&2 "Welcome to the development shell!"
'';
packages =
[
python
cudatoolkit
cuda_cudart
cuda_nvrtc
cudnn
nccl
cutensor
cusparselt
nvidia_x11
]
++ (with pkgs; [
libGLU
libGL
xorg.libXi
xorg.libXmu
freeglut
xorg.libXv
xorg.libXrandr
binutils
uv
]);
env = {
# Force uv to use Python interpreter from venv
UV_PYTHON = python.interpreter;
# Prevent uv from downloading managed Python's
UV_PYTHON_DOWNLOADS = "never";
};
};
*/
# It is of course perfectly OK to keep using an impure virtualenv workflow and only use uv2nix to build packages.
# This devShell simply adds Python and undoes the dependency leakage done by Nixpkgs Python infrastructure.
devShells.impure = pkgs.mkShell {
inputsFrom = [
config.treefmt.build.devShell
config.pre-commit.devShell
];
shellHook = ''
unset PYTHONPATH
echo 1>&2 "Welcome to the development shell!"
'';
packages = [
python
pkgs.uv
];
env = {
# Force uv to use Python interpreter from venv
UV_PYTHON = python.interpreter;
# Prevent uv from downloading managed Python's
UV_PYTHON_DOWNLOADS = "never";
}
// lib.optionalAttrs pkgs.stdenv.isLinux {
# Python libraries often load native shared objects using dlopen(3).
# Setting LD_LIBRARY_PATH makes the dynamic library loader aware of libraries without using RPATH for lookup.
LD_LIBRARY_PATH = lib.makeLibraryPath pkgs.pythonManylinuxPackages.manylinux1;
};
};
};
};
}