-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathflake.nix
213 lines (194 loc) · 5.79 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
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
{
description = "Uv2nix";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable-small";
pyproject-nix.url = "github:pyproject-nix/pyproject.nix";
pyproject-nix.inputs.nixpkgs.follows = "nixpkgs";
};
outputs =
{
self,
nixpkgs,
pyproject-nix,
...
}@inputs:
let
npins = import ./npins;
forAllSystems = lib.genAttrs lib.systems.flakeExposed;
inherit (nixpkgs) lib;
in
{
githubActions = (import npins.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; };
lix = mkShell' {
nix-unit =
let
lix = pkgs.lixVersions.latest;
in
(pkgs.nix-unit.override {
# Hacky overriding :)
nixVersions = lib.mapAttrs (_n: _v: lix) pkgs.nixVersions;
# nix = pkgs.lixVersions.latest;
}).overrideAttrs
(_old: {
pname = "lix-unit";
name = "lix-unit-${lix.version}";
inherit (lix) version;
src = npins.lix-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 = {
overlays.default = import ./dev/build-systems.nix;
};
};
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
'';
}
);
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 { }
);
};
}