-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
167 lines (152 loc) · 4.62 KB
/
flake.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
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
{
inputs = {
flake-parts = {
inputs.nixpkgs-lib.follows = "nixpkgs";
url = "github:hercules-ci/flake-parts";
};
nixpkgs.url = "github:nixos/nixpkgs";
git-hooks-nix = {
inputs = {
nixpkgs-stable.follows = "nixpkgs";
nixpkgs.follows = "nixpkgs";
};
url = "github:cachix/git-hooks.nix";
};
treefmt-nix = {
inputs.nixpkgs.follows = "nixpkgs";
url = "github:numtide/treefmt-nix";
};
};
outputs =
inputs:
let
inherit (inputs.nixpkgs.lib.attrsets)
genAttrs
getAttrs
recurseIntoAttrs
;
inherit (inputs.nixpkgs.lib.lists) optionals;
inherit (inputs.flake-parts.lib) mkFlake;
cuda-lib = import ./cuda-lib { inherit (inputs.nixpkgs) lib; };
inherit (cuda-lib.utils) flattenDrvTree;
in
mkFlake { inherit inputs; } {
systems = [
"aarch64-linux"
"x86_64-linux"
];
imports = [
inputs.treefmt-nix.flakeModule
inputs.git-hooks-nix.flakeModule
];
flake = {
inherit cuda-lib;
overlays.default = import ./overlay.nix;
};
perSystem =
{
config,
pkgs,
system,
...
}:
{
_module.args.pkgs = import inputs.nixpkgs {
inherit system;
# TODO: Due to the way Nixpkgs is built in stages, the config attribute set is not re-evaluated.
# This is problematic for us because we use it to signal the CUDA capabilities to the overlay.
# The only way I've found to combat this is to use pkgs.extend, which is not ideal.
# TODO: This also means that Nixpkgs needs to be imported *with* the correct config attribute set
# from the start, unless they're willing to re-import Nixpkgs with the correct config.
config = {
allowUnfree = true;
cudaSupport = true;
};
overlays = [ inputs.self.overlays.default ];
};
checks =
let
tree =
genAttrs
(
[
"sm_89"
]
++ optionals (pkgs.stdenv.hostPlatform.system == "aarch64-linux") [
"sm_72"
"sm_87"
]
)
(
realArchitecture:
recurseIntoAttrs (
getAttrs [
"cudaPackages_11"
"cudaPackages_12"
] pkgs.pkgsCuda.${realArchitecture}
)
);
in
flattenDrvTree (recurseIntoAttrs tree);
devShells = {
inherit (config.packages) cuda-redist;
default = config.devShells.cuda-redist;
};
legacyPackages = pkgs;
packages = {
default = config.packages.cuda-redist;
cuda-redist = pkgs.python311Packages.callPackage ./scripts/cuda-redist { };
};
pre-commit.settings.hooks =
let
nixToolConfig = {
enable = true;
excludes = [
"cudaPackages-wip/"
"versioned-packages/"
];
};
in
{
# Formatter checks
treefmt = {
enable = true;
inherit (nixToolConfig) excludes;
package = config.treefmt.build.wrapper;
};
# Nix checks
deadnix = nixToolConfig;
nil = nixToolConfig;
statix = nixToolConfig;
};
treefmt = {
projectRootFile = "flake.nix";
programs = {
# Markdown, YAML
# JSON is not formatted; it should not be modified because it is either vendored from NVIDIA or
# produced by a script.
prettier = {
enable = true;
includes = [
"*.md"
"*.yaml"
];
excludes = [ "*.json" ];
settings = {
embeddedLanguageFormatting = "auto";
printWidth = 120;
tabWidth = 2;
};
};
# Nix
nixfmt.enable = true;
# Python
ruff.enable = true;
# Shell
shellcheck.enable = true;
shfmt.enable = true;
};
};
};
};
}