-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
161 lines (146 loc) · 4.94 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
{
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.flake-parts.lib) mkFlake;
lib = import ./lib { inherit (inputs.nixpkgs) lib; };
inherit (lib.attrsets) optionalAttrs;
inherit (lib.upstreamable.attrsets) mkHydraJobsRecurseByDefault;
in
mkFlake { inherit inputs; } {
systems = [
"aarch64-linux"
"x86_64-linux"
];
imports = [
inputs.treefmt-nix.flakeModule
inputs.git-hooks-nix.flakeModule
];
flake = {
cuda-lib = lib.cuda;
upstreamable-lib = lib.upstreamable;
overlays.default = import ./overlay.nix;
};
transposition.hydraJobs.adHoc = true;
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 ];
};
devShells = {
inherit (config.packages) cuda-redist;
default = config.treefmt.build.devShell;
};
legacyPackages = pkgs;
packages = {
default = config.packages.cuda-redist;
cuda-redist = pkgs.python311Packages.callPackage ./scripts/cuda-redist { };
};
hydraJobs = mkHydraJobsRecurseByDefault {
pkgsCuda =
{
# 8.9 supported by all versions of CUDA 12
sm_89 = {
inherit (pkgs.pkgsCuda.sm_89) cudaPackages_12_2_2 cudaPackages_12_6_3;
};
}
// optionalAttrs (pkgs.stdenv.hostPlatform.system == "aarch64-linux") {
# Xavier (7.2) is only supported up to CUDA 12.2.2 by cuda-compat on JetPack 5.
# Unfortunately, NVIDIA isn't releasing support for Xavier on JetPack 6, so we're stuck.
sm_72 = {
inherit (pkgs.pkgsCuda.sm_72) cudaPackages_12_2_2;
};
# Orin (8.7) is only supported up to CUDA 12.2.2 by cuda-compat on JetPack 5.
# Orin has a JetPack 6 release which allows it to run later versions of CUDA, but it has not yet been
# packaged by https://github.com/anduril/jetpack-nixos.
sm_87 = {
inherit (pkgs.pkgsCuda.sm_87) cudaPackages_12_2_2;
};
};
};
pre-commit.settings.hooks =
let
nixToolConfig = {
enable = true;
excludes = [
"cuda-packages/wip/"
];
};
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;
};
};
};
};
}