-
-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathflake.nix
More file actions
246 lines (227 loc) · 7.06 KB
/
flake.nix
File metadata and controls
246 lines (227 loc) · 7.06 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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
{
description = "Uv2nix";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
pyproject-nix.url = "github:pyproject-nix/pyproject.nix";
pyproject-nix.inputs.nixpkgs.follows = "nixpkgs";
};
outputs =
{
self,
nixpkgs,
pyproject-nix,
...
}@inputs:
let
forAllSystems = lib.genAttrs lib.systems.flakeExposed;
inherit (nixpkgs) lib;
ciFlake =
let
lockFile = builtins.fromJSON (builtins.readFile ./ci/flake.lock);
flake-compat-node = lockFile.nodes.${lockFile.nodes.root.inputs.flake-compat};
flake-compat = builtins.fetchTarball {
inherit (flake-compat-node.locked) url;
sha256 = flake-compat-node.locked.narHash;
};
in
import flake-compat {
copySourceTreeToStore = false;
src = ./ci;
};
in
{
githubActions = (import ciFlake.inputs.nix-github-actions).mkGithubMatrix {
checks =
let
strip = lib.flip removeAttrs [
# No need to run formatter check on multiple platforms
"formatter"
];
in
{
inherit (self.checks) x86_64-linux;
aarch64-darwin = strip self.checks.aarch64-darwin;
};
};
lib = import ./lib {
inherit pyproject-nix;
inherit lib;
};
templates =
let
root = ./templates;
dirs = lib.attrNames (lib.filterAttrs (_: type: type == "directory") (builtins.readDir root));
in
lib.listToAttrs (
map (
dir:
let
path = root + "/${dir}";
template = import (path + "/flake.nix");
in
lib.nameValuePair dir {
inherit path;
inherit (template) description;
}
) dirs
);
# Expose unit tests for external discovery
libTests = import ./lib/test.nix {
inherit lib pyproject-nix;
uv2nix = self.lib;
pkgs = nixpkgs.legacyPackages.x86_64-linux;
};
devShells = forAllSystems (
system:
let
pkgs = nixpkgs.legacyPackages.${system};
mkShell' =
{ nix-unit }:
pkgs.mkShell {
packages = [
pkgs.hivemind
pkgs.mdbook
pkgs.reflex
nix-unit
pkgs.mdbook-cmdrun
self.packages.${system}.uv-bin
pkgs.python3
self.formatter.${system}
pkgs.npins
]
++ self.packages.${system}.doc.nativeBuildInputs;
env = {
UV_NO_SYNC = "1";
UV_PYTHON_DOWNLOADS = "never";
UV_PYTHON = pkgs.python3.interpreter;
};
};
in
{
nix = mkShell' { inherit (pkgs) nix-unit; };
default = self.devShells.${system}.nix;
}
);
checks = forAllSystems (
system:
let
pkgs = nixpkgs.legacyPackages.${system};
in
builtins.removeAttrs self.packages.${system} [ "default" ]
// import ./dev/checks.nix {
inherit pyproject-nix pkgs lib;
uv2nix = self.lib;
}
//
# Test flake templates
(
let
inherit (builtins) mapAttrs functionArgs;
# Call a nested flake with the inputs from this one.
callFlake =
path:
let
flake' = import (path + "/flake.nix");
args = mapAttrs (name: _: inputs'.${name}) (functionArgs flake'.outputs);
flake = flake'.outputs args;
inputs' = inputs // {
uv2nix = self;
self = flake;
pyproject-build-systems =
let
overlay = import ./dev/build-systems.nix;
in
{
# Expose same attrs as pyproject-build-systems
overlays = {
default = overlay;
wheel = overlay;
sdist = overlay;
};
};
};
in
flake;
in
lib.listToAttrs (
lib.concatLists (
lib.mapAttrsToList (
template: _:
let
flake = callFlake (./templates + "/${template}");
mkChecks =
prefix: attr:
lib.mapAttrsToList (check: drv: lib.nameValuePair "template-${template}-${prefix}-${check}" drv) (
flake.${attr}.${system} or { }
);
in
mkChecks "check" "checks" ++ mkChecks "package" "packages" ++ mkChecks "devShell" "devShells"
) (builtins.readDir ./templates)
)
)
)
// {
formatter =
pkgs.runCommand "fmt-check"
{
nativeBuildInputs = [ self.formatter.${system} ];
}
''
export HOME=$(mktemp -d)
cp -r ${self} $(stripHash "${self}")
chmod -R +w .
cd source
treefmt --fail-on-change
touch $out
'';
}
// (
let
pkgs' = import ciFlake.inputs.nixpkgs-22_11 {
inherit system;
overlays = [
(_: _: {
# The pyproject.nix test harness inherits sources from pythonPackages
# and 22.11 versions fail to build for various reasons.
inherit (pkgs) python3Packages;
# Older uv versions lack important features, and 22.11 doesn't even contain uv.
# Users of older channels need to pass a more recent uv.
# Hint: Uv2nix provides a uv-bin package.
inherit (pkgs) uv;
})
];
};
checks' = import ./dev/checks.nix {
inherit pyproject-nix;
pkgs = pkgs';
inherit (pkgs') lib;
uv2nix = self.lib;
};
in
lib.optionalAttrs (!pkgs'.stdenv.isDarwin) {
# Fails on aarch64-darwin with oom
trivial-22_11 = builtins.trace system checks'.trivial;
}
)
);
packages = forAllSystems (
system:
let
pkgs = nixpkgs.legacyPackages.${system};
in
{
doc = pkgs.callPackage ./doc {
inherit self;
};
uv-bin = pkgs.callPackage ./pkgs/uv-bin { };
}
);
formatter = forAllSystems (
system:
let
pkgs = nixpkgs.legacyPackages.${system};
in
pkgs.callPackage ./treefmt.nix { }
);
};
}