Repository navigation
Expand file tree
/
Copy pathflake.nix
More file actions
347 lines (331 loc) · 13.6 KB
/
Copy pathflake.nix
File metadata and controls
347 lines (331 loc) · 13.6 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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
{
description = "T3 Code and every provider it supports, updated minutes after each upstream release";
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
# The binary cache, offered to `nix run` and friends. Nix asks first (or
# takes --accept-flake-config) and uses it only for trusted users or a
# cache the machine trusts already, so the README also gives the lines to
# add by hand.
# The binary cache (lib/cache.nix), written out because Nix reads
# `nixConfig` without evaluating it. The cache-settings check compares
# these with lib/cache.nix.
nixConfig = {
extra-substituters = [ "https://t3code-nix.cachix.org" ];
extra-trusted-public-keys = [
"t3code-nix.cachix.org-1:FwZvqgRcnUjCSEUmdosysof1pTedbm/TTmlk8IeDsJA="
];
};
outputs =
{ self, nixpkgs }:
let
inherit (nixpkgs) lib;
systems = [
"x86_64-linux"
"aarch64-linux"
];
forAllSystems = lib.genAttrs systems;
# Not supported: `nix run` there says so (lib/unsupported.nix).
otherSystems = [
"x86_64-darwin"
"aarch64-darwin"
];
cache = import ./lib/cache.nix;
# What the NixOS and Home Manager modules share (lib/module-core.nix).
core = import ./lib/module-core.nix {
inherit (self) packages;
# nixpkgs = "stable": only evaluated when chosen.
stable = lib.mapAttrs (_: l: l.stable) self.legacyPackages;
# The server's database copy, from the flake's own package set.
serverBackup = forAllSystems (system: {
unstable = import ./lib/server-backup.nix { pkgs = pkgsFor system; };
stable = import ./lib/server-backup.nix { pkgs = stablePkgsFor system; };
});
};
# Running this flake's own outputs is the opt-in to the unfree
# packages it bundles, and to those only (see README, "Unfree
# packages").
# The overlay leaves the decision to the user's own nixpkgs config.
unfreePackages = import ./pkgs/unfree.nix;
pkgsFor =
system:
import nixpkgs {
inherit system;
config.allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) unfreePackages;
# Nothing from the user's nixpkgs config (default.nix is impure).
overlays = [ ];
};
# NixOS stable (the stable toggle): the nixos-NN.MM revision
# versions/nixpkgs-stable.json pins, fetched only when used.
stablePin = lib.importJSON ./versions/nixpkgs-stable.json;
stableSrc = builtins.fetchTarball {
url = "https://github.com/NixOS/nixpkgs/archive/${stablePin.rev}.tar.gz";
sha256 = stablePin.narHash;
};
# Home Manager master, for the hm-* checks (lib/hm-checks.nix) and
# vmTests.homeManager: fetched only when one of them is evaluated.
homeManagerPin = lib.importJSON ./ci/home-manager.json;
homeManagerSrc = builtins.fetchTarball {
url = "https://github.com/nix-community/home-manager/archive/${homeManagerPin.rev}.tar.gz";
sha256 = homeManagerPin.narHash;
};
stablePkgsFor =
system:
import stableSrc {
inherit system;
config.allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) unfreePackages;
overlays = [ ];
};
# NixOS stable without unfree packages allowed (free-variant's twin).
stableFreePkgsFor =
system:
import stableSrc {
inherit system;
overlays = [ ];
};
# The stable set users get: the snapshot's pins (versions/stable/).
stableFor =
system:
import ./pkgs {
pkgs = stablePkgsFor system;
pinsDir = ./versions/stable;
nixpkgs = "stable";
};
# What a snapshot move would give (the stable-next checks): the current
# pins, on NixOS stable, without the nightly packages.
stableNextFor =
system:
lib.filterAttrs (n: _: !lib.hasSuffix "-nightly" n) (
import ./pkgs {
pkgs = stablePkgsFor system;
nixpkgs = "stable";
}
);
# lib/checks.nix with a package set, its pins and the harness's pkgs: the
# default checks, and the same recipe for the NixOS-stable suites.
checksWith =
{
pkgs,
packages,
pinsDir,
system,
stable ? false,
freeSet ? null,
noFallback ? packages,
}:
pkgs.callPackage ./lib/checks.nix {
inherit
self
cache
packages
pinsDir
stable
freeSet
noFallback
;
homeManager = homeManagerSrc;
# nixpkgs as an overlay user without allowUnfree has it.
overlayPkgs = import nixpkgs {
inherit system;
overlays = [ self.overlays.default ];
};
# The same, with the unfree packages the flake's outputs allow,
# so its derivations can be compared with theirs.
overlayAllowed = (pkgsFor system).appendOverlays [ self.overlays.default ];
};
defaultChecks =
system:
checksWith {
inherit system;
pkgs = pkgsFor system;
packages = self.packages.${system};
pinsDir = ./versions;
noFallback = import ./pkgs {
pkgs = pkgsFor system;
electronFallback = false;
};
};
# A NixOS-stable suite (lib/stable-suite.nix), each check named
# <prefix><check>: the stable set and the snapshot (prefix "stable-"),
# or the stable-next set and versions/ ("stable-next-"). Built by one
# recipe, so a pair has the same derivations when the pins are equal.
suiteFor =
system: prefix: packages: pinsDir:
let
suite = import ./lib/stable-suite.nix;
checks = checksWith {
inherit system packages pinsDir;
pkgs = stablePkgsFor system;
stable = true;
# The same set without unfree packages allowed (free-variant).
freeSet = import ./pkgs {
pkgs = stableFreePkgsFor system;
inherit pinsDir;
nixpkgs = "stable";
};
};
present = builtins.filter (n: packages ? ${n});
in
lib.mapAttrs' (n: v: lib.nameValuePair "${prefix}${n}" v) (
lib.genAttrs (present suite.twinnedPackages) (n: packages.${n})
// lib.genAttrs suite.twinnedChecks (n: checks.${n})
# The module with nixpkgs = "stable", on this set (no default original).
// {
module-eval = (stablePkgsFor system).callPackage ./lib/stable-module-eval.nix {
inherit self cache;
set = packages;
};
# Every package of the set evaluates (init too, which isn't built).
eval = (stablePkgsFor system).runCommand "eval" { } (
builtins.deepSeq (map (p: p.drvPath) (builtins.attrValues packages)) "touch $out"
);
}
);
in
{
# Every package under pkgs.t3code-nix; the app and the providers also at
# the top level, but never over a different nixpkgs program of the
# same name (lib/overlay.nix). `default` is a flake-output convention,
# not a package name.
overlays.default =
final: prev:
let
# The fallback file is about the flake's pinned nixpkgs, not yours.
ours = removeAttrs (import ./pkgs {
pkgs = final;
electronFallback = false;
}) [ "default" ];
names = import ./lib/overlay.nix;
topLevel = builtins.filter (
name: !(prev ? ${name}) || builtins.elem name names.sameAsNixpkgs
) names.candidates;
# The top-level t3code replaces nixpkgs' (sameAsNixpkgs), which has
# the CLI too (`t3`, and `t3code-desktop`); modules written for it,
# Home Manager's programs.t3code among them, run that `t3`.
top = ours // {
t3code = ours.t3code.override { withCli = true; };
};
in
{
t3code-nix = ours;
}
// lib.getAttrs topLevel top;
packages =
forAllSystems (system: import ./pkgs { pkgs = pkgsFor system; })
// lib.genAttrs otherSystems (system: {
default = import ./lib/unsupported.nix system;
});
nixosModules = rec {
t3code = import ./nixos/module.nix { inherit core cache; };
default = t3code;
};
# programs.t3code-nix for Home Manager (home-manager/module.nix).
homeModules = rec {
t3code-nix = import ./home-manager/module.nix { inherit core; };
default = t3code-nix;
};
# The same, under the name older guides use.
homeManagerModules = self.homeModules;
# Every package builds and passes its version probe, plus the smoke tests.
checks = forAllSystems (
system:
let
pkgs = pkgsFor system;
own =
# `default` is t3code again: checked once.
removeAttrs self.packages.${system} [ "default" ]
# callPackage adds override helpers; keep only the checks themselves.
// lib.filterAttrs (_: lib.isDerivation) (defaultChecks system);
suite = import ./lib/stable-suite.nix;
listed = with suite; twinnedPackages ++ twinnedChecks ++ nightly ++ guards ++ flakeLevel;
names = builtins.attrNames own ++ [ "stable-names" ];
unlisted = builtins.filter (n: !builtins.elem n listed) names;
gone = builtins.filter (n: !builtins.elem n names) listed;
# The stable set's package names come from the snapshot's pin files
# alone (pkgs/default.nix filters with builtins), so listing them
# never imports nixpkgs-stable and can't fail on it.
stableNames = builtins.attrNames self.legacyPackages.${system}.stable;
snapshotNightly =
builtins.filter (lib.hasSuffix "-nightly.json") (
builtins.attrNames (builtins.readDir ./versions/stable)
)
++ builtins.filter (lib.hasSuffix "-nightly") stableNames;
in
own
// {
# Every check is in the NixOS-stable suite's lists, and the snapshot
# has no nightly pins.
stable-names = pkgs.runCommand "stable-names" { } (
if
unlisted == [ ] && gone == [ ] && snapshotNightly == [ ] && builtins.elem "t3code" stableNames
then
"touch $out"
else
"echo ${lib.escapeShellArg "not in lib/stable-suite.nix: ${toString unlisted}; listed but gone: ${toString gone}; nightly in the stable set: ${toString snapshotNightly}; stable set: ${toString stableNames}"}; exit 1"
);
}
);
# `nix flake init -t github:boltflake/t3code-nix`: a NixOS flake with
# the module (templates/default; checked by `template`).
templates.default = {
path = ./templates/default;
description = "A NixOS system with T3 Code from t3code-nix";
welcomeText = ''
Wrote flake.nix: a NixOS system with T3 Code. It imports your
./configuration.nix. Check its nixpkgs line (see the comment
there), then run:
```
sudo nixos-rebuild switch --flake /etc/nixos#nixos
```
'';
};
# `nix flake init -t github:boltflake/t3code-nix#home-manager`: a
# standalone Home Manager flake with the module (templates/home-manager;
# checked by `hm-template`).
templates.home-manager = {
path = ./templates/home-manager;
description = "Home Manager with T3 Code from t3code-nix, on NixOS or another Linux";
welcomeText = ''
Wrote flake.nix: Home Manager with T3 Code. Set your user name,
home folder and system in it (the lines marked), then run this,
with YOUR_USERNAME replaced by that user name:
```
nix run github:nix-community/home-manager/master -- switch --flake '.#YOUR_USERNAME'
```
'';
};
# Too heavy for `checks` (they need KVM); see lib/vm-test.nix.
legacyPackages = forAllSystems (system: {
vmTests.server = import ./lib/vm-test.nix {
inherit self;
pkgs = pkgsFor system;
};
vmTests.homeManager = import ./lib/vm-test-home-manager.nix {
inherit self;
pkgs = pkgsFor system;
homeManager = homeManagerSrc;
};
# NixOS stable (programs.t3code.nixpkgs = "stable"). Not evaluated by
# `nix flake show` or `nix flake check`, so nothing fetches the stable
# nixpkgs unless it's used.
stable = removeAttrs (stableFor system) [ "default" ];
# Internal: the stable-next set, for the stable-next checks.
stableNext = removeAttrs (stableNextFor system) [ "default" ];
# The NixOS-stable suites, evaluated and built apart from `checks` (by
# scripts/ci/stable.ts), so nothing about NixOS stable can fail or delay
# the default checks.
stableChecks = suiteFor system "stable-" (stableFor system) ./versions/stable;
stableNextChecks = suiteFor system "stable-next-" (stableNextFor system) ./versions;
# The stable runner smokes' tools (scripts/ci/stable.ts), from the
# nixpkgs-stable pin like the rest of the stable harness.
stableSmokeTools = {
inherit (stablePkgsFor system)
xvfb-run
dbus
xdotool
util-linux
;
};
});
# `nix fmt` formats every .nix file (the nix-format check's nixfmt).
formatter = forAllSystems (system: nixpkgs.legacyPackages.${system}.nixfmt-tree);
};
}