1with import ../lib;
2
3{
4 nixpkgs ? {
5 outPath = cleanSource ./..;
6 revCount = 708350;
7 shortRev = "gfedcba";
8 },
9 stableBranch ? false,
10 supportedSystems ? [
11 "x86_64-linux"
12 "aarch64-linux"
13 ],
14 configuration ? { },
15
16 # This flag, if set to true, causes the resulting tree of attributes
17 # to *not* have a ".${system}" suffixed upon every job name like Hydra
18 # expects. So far, this is only implemented for `tests`.
19 #
20 # This flag exists mainly for use by ci/eval/attrpaths.nix; see
21 # that file for full details. The exact behavior of this flag
22 # may change; it should be considered an internal implementation
23 # detail of ci/eval.
24 attrNamesOnly ? false,
25}:
26
27with import ../pkgs/top-level/release-lib.nix { inherit supportedSystems; };
28
29let
30
31 version = fileContents ../.version;
32 versionSuffix =
33 (if stableBranch then "." else "pre") + "${toString nixpkgs.revCount}.${nixpkgs.shortRev}";
34
35 # Run the tests for each platform. You can run a test by doing
36 # e.g. ‘nix-build release.nix -A tests.login.x86_64-linux’,
37 # or equivalently, ‘nix-build tests/login.nix’.
38 # See also nixosTests in pkgs/top-level/all-packages.nix
39 allTestsForSystem =
40 system:
41 import ./tests/all-tests.nix {
42 inherit system;
43 pkgs = import ./.. { inherit system; };
44 callTest =
45 config:
46 if attrNamesOnly then
47 hydraJob config.test
48 else
49 {
50 ${system} = hydraJob config.test;
51 };
52 }
53 // {
54 # for typechecking of the scripts and evaluation of
55 # the nodes, without running VMs.
56 allDrivers = import ./tests/all-tests.nix {
57 inherit system;
58 pkgs = import ./.. { inherit system; };
59 callTest =
60 config:
61 if attrNamesOnly then
62 hydraJob config.test
63 else
64 {
65 ${system} = hydraJob config.driver;
66 };
67 };
68 };
69
70 allTests = foldAttrs recursiveUpdate { } (
71 map allTestsForSystem (if attrNamesOnly then [ (head supportedSystems) ] else supportedSystems)
72 );
73
74 pkgs = import ./.. { system = "x86_64-linux"; };
75
76 versionModule =
77 { config, ... }:
78 {
79 system.nixos.versionSuffix = versionSuffix;
80 system.nixos.revision = nixpkgs.rev or nixpkgs.shortRev;
81
82 # At creation time we do not have state yet, so just default to latest.
83 system.stateVersion = config.system.nixos.release;
84 };
85
86 makeModules = module: rest: [
87 configuration
88 versionModule
89 module
90 rest
91 ];
92
93 makeIso =
94 {
95 module,
96 type,
97 system,
98 ...
99 }:
100
101 with import ./.. { inherit system; };
102
103 hydraJob (
104 (import lib/eval-config.nix {
105 inherit system;
106 modules = makeModules module { };
107 }).config.system.build.isoImage
108 );
109
110 makeSdImage =
111 { module, system, ... }:
112
113 with import ./.. { inherit system; };
114
115 hydraJob (
116 (import lib/eval-config.nix {
117 inherit system;
118 modules = makeModules module { };
119 }).config.system.build.sdImage
120 );
121
122 makeSystemTarball =
123 {
124 module,
125 maintainers ? [ "viric" ],
126 system,
127 }:
128
129 with import ./.. { inherit system; };
130
131 let
132
133 config =
134 (import lib/eval-config.nix {
135 inherit system;
136 modules = makeModules module { };
137 }).config;
138
139 tarball = config.system.build.tarball;
140
141 in
142 tarball
143 // {
144 meta = {
145 description = "NixOS system tarball for ${system} - ${stdenv.hostPlatform.linux-kernel.name}";
146 maintainers = map (x: lib.maintainers.${x}) maintainers;
147 };
148 inherit config;
149 };
150
151 makeClosure = module: buildFromConfig module (config: config.system.build.toplevel);
152
153 buildFromConfig =
154 module: sel:
155 forAllSystems (
156 system:
157 hydraJob (
158 sel
159 (import ./lib/eval-config.nix {
160 inherit system;
161 modules = makeModules module (
162 { ... }:
163 {
164 fileSystems."/".device = mkDefault "/dev/sda1";
165 boot.loader.grub.device = mkDefault "/dev/sda";
166 }
167 );
168 }).config
169 )
170 );
171
172 makeNetboot =
173 { module, system, ... }:
174 let
175 configEvaled = import lib/eval-config.nix {
176 inherit system;
177 modules = makeModules module { };
178 };
179 build = configEvaled.config.system.build;
180 kernelTarget = configEvaled.pkgs.stdenv.hostPlatform.linux-kernel.target;
181 in
182 configEvaled.pkgs.symlinkJoin {
183 name = "netboot";
184 paths = [
185 build.netbootRamdisk
186 build.kernel
187 build.netbootIpxeScript
188 ];
189 postBuild = ''
190 mkdir -p $out/nix-support
191 echo "file ${kernelTarget} ${build.kernel}/${kernelTarget}" >> $out/nix-support/hydra-build-products
192 echo "file initrd ${build.netbootRamdisk}/initrd" >> $out/nix-support/hydra-build-products
193 echo "file ipxe ${build.netbootIpxeScript}/netboot.ipxe" >> $out/nix-support/hydra-build-products
194 '';
195 preferLocalBuild = true;
196 };
197
198in
199rec {
200
201 channel = import lib/make-channel.nix {
202 inherit
203 pkgs
204 nixpkgs
205 version
206 versionSuffix
207 ;
208 };
209
210 manualHTML = buildFromConfig ({ ... }: { }) (config: config.system.build.manual.manualHTML);
211 manual = manualHTML; # TODO(@oxij): remove eventually
212 manualEpub = (buildFromConfig ({ ... }: { }) (config: config.system.build.manual.manualEpub));
213 nixos-configuration-reference-manpage = buildFromConfig ({ ... }: { }) (
214 config: config.system.build.manual.nixos-configuration-reference-manpage
215 );
216 options =
217 (buildFromConfig ({ ... }: { }) (config: config.system.build.manual.optionsJSON)).x86_64-linux;
218
219 # Build the initial ramdisk so Hydra can keep track of its size over time.
220 initialRamdisk = buildFromConfig ({ ... }: { }) (config: config.system.build.initialRamdisk);
221
222 kexec = forMatchingSystems supportedSystems (
223 system:
224 (import lib/eval-config.nix {
225 inherit system;
226 modules = [
227 ./modules/installer/netboot/netboot-minimal.nix
228 ];
229 }).config.system.build.kexecTree
230 );
231
232 netboot = forMatchingSystems supportedSystems (
233 system:
234 makeNetboot {
235 module = ./modules/installer/netboot/netboot-minimal.nix;
236 inherit system;
237 }
238 );
239
240 iso_minimal = forAllSystems (
241 system:
242 makeIso {
243 module = ./modules/installer/cd-dvd/installation-cd-minimal-combined.nix;
244 type = "minimal";
245 inherit system;
246 }
247 );
248
249 iso_graphical = forAllSystems (
250 system:
251 makeIso {
252 module = ./modules/installer/cd-dvd/installation-cd-graphical-combined.nix;
253 type = "graphical";
254 inherit system;
255 }
256 );
257
258 sd_image = forMatchingSystems [ "armv6l-linux" "armv7l-linux" "aarch64-linux" ] (
259 system:
260 makeSdImage {
261 module =
262 {
263 armv6l-linux = ./modules/installer/sd-card/sd-image-raspberrypi-installer.nix;
264 armv7l-linux = ./modules/installer/sd-card/sd-image-armv7l-multiplatform-installer.nix;
265 aarch64-linux = ./modules/installer/sd-card/sd-image-aarch64-installer.nix;
266 }
267 .${system};
268 inherit system;
269 }
270 );
271
272 sd_image_new_kernel = forMatchingSystems [ "aarch64-linux" ] (
273 system:
274 makeSdImage {
275 module =
276 {
277 aarch64-linux = ./modules/installer/sd-card/sd-image-aarch64-new-kernel-installer.nix;
278 }
279 .${system};
280 type = "minimal-new-kernel";
281 inherit system;
282 }
283 );
284
285 sd_image_new_kernel_no_zfs = forMatchingSystems [ "aarch64-linux" ] (
286 system:
287 makeSdImage {
288 module =
289 {
290 aarch64-linux = ./modules/installer/sd-card/sd-image-aarch64-new-kernel-no-zfs-installer.nix;
291 }
292 .${system};
293 type = "minimal-new-kernel-no-zfs";
294 inherit system;
295 }
296 );
297
298 # KVM image for proxmox in VMA format
299 proxmoxImage = forMatchingSystems [ "x86_64-linux" ] (
300 system:
301 with import ./.. { inherit system; };
302
303 hydraJob (
304 (import lib/eval-config.nix {
305 inherit system;
306 modules = [
307 ./modules/virtualisation/proxmox-image.nix
308 ];
309 }).config.system.build.VMA
310 )
311 );
312
313 # LXC tarball for proxmox
314 proxmoxLXC = forMatchingSystems [ "x86_64-linux" ] (
315 system:
316 with import ./.. { inherit system; };
317
318 hydraJob (
319 (import lib/eval-config.nix {
320 inherit system;
321 modules = [
322 ./modules/virtualisation/proxmox-lxc.nix
323 ];
324 }).config.system.build.tarball
325 )
326 );
327
328 # A disk image that can be imported to Amazon EC2 and registered as an AMI
329 amazonImage = forMatchingSystems [ "x86_64-linux" "aarch64-linux" ] (
330 system:
331
332 with import ./.. { inherit system; };
333
334 hydraJob (
335 (import lib/eval-config.nix {
336 inherit system;
337 modules = [
338 configuration
339 versionModule
340 ./maintainers/scripts/ec2/amazon-image.nix
341 ];
342 }).config.system.build.amazonImage
343 )
344
345 );
346 amazonImageZfs = forMatchingSystems [ "x86_64-linux" "aarch64-linux" ] (
347 system:
348
349 with import ./.. { inherit system; };
350
351 hydraJob (
352 (import lib/eval-config.nix {
353 inherit system;
354 modules = [
355 configuration
356 versionModule
357 ./maintainers/scripts/ec2/amazon-image-zfs.nix
358 ];
359 }).config.system.build.amazonImage
360 )
361
362 );
363
364 # An image that can be imported into incus and used for container creation
365 incusContainerImage =
366 forMatchingSystems
367 [
368 "x86_64-linux"
369 "aarch64-linux"
370 ]
371 (
372 system:
373 with import ./.. { inherit system; };
374
375 hydraJob (
376 (import lib/eval-config.nix {
377 inherit system;
378 modules = [
379 configuration
380 versionModule
381 ./maintainers/scripts/incus/incus-container-image.nix
382 ];
383 }).config.system.build.squashfs
384 )
385 );
386
387 # Metadata for the incus image
388 incusContainerMeta =
389 forMatchingSystems
390 [
391 "x86_64-linux"
392 "aarch64-linux"
393 ]
394 (
395 system:
396
397 with import ./.. { inherit system; };
398
399 hydraJob (
400 (import lib/eval-config.nix {
401 inherit system;
402 modules = [
403 configuration
404 versionModule
405 ./maintainers/scripts/incus/incus-container-image.nix
406 ];
407 }).config.system.build.metadata
408 )
409 );
410
411 # An image that can be imported into incus and used for container creation
412 incusVirtualMachineImage =
413 forMatchingSystems
414 [
415 "x86_64-linux"
416 "aarch64-linux"
417 ]
418 (
419 system:
420
421 with import ./.. { inherit system; };
422
423 hydraJob (
424 (import lib/eval-config.nix {
425 inherit system;
426 modules = [
427 configuration
428 versionModule
429 ./maintainers/scripts/incus/incus-virtual-machine-image.nix
430 ];
431 }).config.system.build.qemuImage
432 )
433 );
434
435 # Metadata for the incus image
436 incusVirtualMachineImageMeta =
437 forMatchingSystems
438 [
439 "x86_64-linux"
440 "aarch64-linux"
441 ]
442 (
443 system:
444
445 with import ./.. { inherit system; };
446
447 hydraJob (
448 (import lib/eval-config.nix {
449 inherit system;
450 modules = [
451 configuration
452 versionModule
453 ./maintainers/scripts/incus/incus-virtual-machine-image.nix
454 ];
455 }).config.system.build.metadata
456 )
457 );
458
459 # Ensure that all packages used by the minimal NixOS config end up in the channel.
460 dummy = forAllSystems (
461 system:
462 pkgs.runCommand "dummy" {
463 toplevel =
464 (import lib/eval-config.nix {
465 inherit system;
466 modules = singleton (
467 { ... }:
468 {
469 fileSystems."/".device = mkDefault "/dev/sda1";
470 boot.loader.grub.device = mkDefault "/dev/sda";
471 system.stateVersion = mkDefault lib.trivial.release;
472 }
473 );
474 }).config.system.build.toplevel;
475 preferLocalBuild = true;
476 } "mkdir $out; ln -s $toplevel $out/dummy"
477 );
478
479 # Provide container tarball for lxc, libvirt-lxc, docker-lxc, ...
480 containerTarball = forAllSystems (
481 system:
482 makeSystemTarball {
483 module = ./modules/virtualisation/lxc-container.nix;
484 inherit system;
485 }
486 );
487
488 tests = allTests;
489
490 /*
491 Build a bunch of typical closures so that Hydra can keep track of
492 the evolution of closure sizes.
493 */
494
495 closures = {
496
497 smallContainer = makeClosure (
498 { ... }:
499 {
500 boot.isContainer = true;
501 services.openssh.enable = true;
502 }
503 );
504
505 tinyContainer = makeClosure (
506 { ... }:
507 {
508 boot.isContainer = true;
509 imports = [ modules/profiles/minimal.nix ];
510 }
511 );
512
513 ec2 = makeClosure (
514 { ... }:
515 {
516 imports = [ modules/virtualisation/amazon-image.nix ];
517 }
518 );
519
520 kde = makeClosure (
521 { ... }:
522 {
523 services.xserver.enable = true;
524 services.displayManager.sddm.enable = true;
525 services.desktopManager.plasma6.enable = true;
526 }
527 );
528
529 xfce = makeClosure (
530 { ... }:
531 {
532 services.xserver.enable = true;
533 services.xserver.desktopManager.xfce.enable = true;
534 }
535 );
536
537 gnome = makeClosure (
538 { ... }:
539 {
540 services.xserver.enable = true;
541 services.displayManager.gdm.enable = true;
542 services.desktopManager.gnome.enable = true;
543 }
544 );
545
546 pantheon = makeClosure (
547 { ... }:
548 {
549 services.xserver.enable = true;
550 services.desktopManager.pantheon.enable = true;
551 }
552 );
553
554 # Linux/Apache/PostgreSQL/PHP stack.
555 lapp = makeClosure (
556 { pkgs, ... }:
557 {
558 services.httpd.enable = true;
559 services.httpd.adminAddr = "foo@example.org";
560 services.httpd.enablePHP = true;
561 services.postgresql.enable = true;
562 services.postgresql.package = pkgs.postgresql;
563 }
564 );
565 };
566}