-
-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathflake.nix
More file actions
223 lines (204 loc) · 6.4 KB
/
Copy pathflake.nix
File metadata and controls
223 lines (204 loc) · 6.4 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
{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
};
outputs =
{
self,
nixpkgs,
...
}:
let
forAllSystems = lib.genAttrs lib.systems.flakeExposed;
inherit (nixpkgs) lib;
pyproject-nix = import ./default.nix {
inherit 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"
# Takes very long to build on Darwin and should have been adequately tested on Linux only.
"build-make-venv-cross"
];
in
{
inherit (self.checks) x86_64-linux;
aarch64-darwin = strip self.checks.aarch64-darwin;
};
};
inherit (pyproject-nix) lib build;
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 = self.lib;
pkgs = nixpkgs.legacyPackages.x86_64-linux;
}
// {
build = import ./build/lib/test.nix {
pyproject-nix = self;
inherit lib;
pkgs = nixpkgs.legacyPackages.x86_64-linux;
};
};
devShells = forAllSystems (
system:
let
pkgs = nixpkgs.legacyPackages.${system};
mkShell' =
{ nix-unit }:
pkgs.mkShell {
packages = [
nix-unit
(pkgs.python3.withPackages (_ps: [ ]))
pkgs.hivemind
pkgs.reflex
self.formatter.${system}
]
++ self.packages.${system}.doc.nativeBuildInputs;
};
in
{
nix = mkShell' { inherit (pkgs) nix-unit; };
default = self.devShells.${system}.nix;
}
);
checks = forAllSystems (
system:
let
pkgs = nixpkgs.legacyPackages.${system};
in
(lib.mapAttrs' (name: drv: lib.nameValuePair "nixpkgs-${name}" drv) (
pkgs.callPackages ./test { pyproject = self; }
))
// (lib.mapAttrs' (name: drv: lib.nameValuePair "build-${name}" drv) (
pkgs.callPackages ./build/checks { pyproject-nix = self; }
))
// (lib.mapAttrs' (name: drv: lib.nameValuePair "build-hacks-${name}" drv) (
pkgs.callPackages ./build/hacks/checks.nix {
pyproject-nix = self;
}
))
// (lib.mapAttrs' (name: drv: lib.nameValuePair "build-util-${name}" drv) (
pkgs.callPackages ./build/util/checks.nix {
pyproject-nix = self;
}
))
// {
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
'';
typing =
pkgs.runCommand "typing-check"
{
nativeBuildInputs = [
(pkgs.basedpyright.overrideAttrs (old: {
# Nixpkgs build of basedpyright is broken because of a dangling symlinks check
postInstall = old.postInstall + ''
find -L $out -type l -print -delete
'';
}))
pkgs.python3
];
}
''
cd ${self}
basedpyright
mkdir $out
'';
}
// {
# Run a smoke test on 22.11 (the oldest supported nixpkgs)
# to ensure you can instantiate a package set with it
#
# While this older nixpkgs is supported we don't want to run the full gamut of tests because it would take too long.
build-22_11-compat =
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;
})
];
};
in
pkgs'.callPackage ./build/checks/smoke.nix {
name = "build-22_11-compat";
pyproject-nix = self;
};
}
);
formatter = forAllSystems (
system:
let
pkgs = nixpkgs.legacyPackages.${system};
in
pkgs.callPackage ./treefmt.nix { }
);
packages = forAllSystems (
system:
let
pkgs = nixpkgs.legacyPackages.${system};
in
{
doc = pkgs.callPackage ./doc {
inherit self;
};
}
// pkgs.callPackages pyproject-nix.packages { }
);
};
}