Skip to content

Commit d5e0a6f

Browse files
committed
Add flake checks
that build various images. Limitation: checks only exist for x86_64-linux and aarch64-linux. Incidental changes: 1. Add nixos-21.11 release as a flake input. 2. Add the function `nixosGenerate'`, which is a generalized version of `nixosGenerate` that takes the additional mandatory argument `system` and the additional optional argument `nixpkgs` (the latter of which should be a nixpkgs *flake*). This function is used for constructing the flake checks; `nixpkgs` needs to be parameterized in order to use both nixpkgs-unstable and nixos-21.11.
1 parent 74b30a0 commit d5e0a6f

File tree

2 files changed

+137
-13
lines changed

2 files changed

+137
-13
lines changed

flake.lock

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 120 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66

77
# Bin dependency
88
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
9+
inputs.nixos.url = "github:NixOS/nixpkgs/nixos-21.11";
910

10-
outputs = { self, nixpkgs, nixlib }:
11+
outputs = { self, nixpkgs, nixos, nixlib }@inputs:
1112

1213
# Library modules (depend on nixlib)
1314
rec {
@@ -18,16 +19,15 @@
1819
value.imports = [ (./formats + "/${file}") ./format-module.nix ];
1920
}) (builtins.readDir ./formats);
2021

21-
# example usage in flakes:
22-
# outputs = { self, nixpkgs, nixos-generators, ...}: {
23-
# vmware = nixos-generators.nixosGenerate {
24-
# pkgs = nixpkgs.legacyPackages.x86_64-linux;
25-
# modules = [./configuration.nix];
26-
# format = "vmware";
27-
# };
28-
# }
29-
nixosGenerate = { pkgs, format, specialArgs ? { }, modules ? [ ] }:
30-
let
22+
nixosGenerate' = {
23+
format
24+
, system
25+
, nixpkgs ? inputs.nixpkgs
26+
, pkgs ? nixpkgs.legacyPackages.${system}
27+
, specialArgs ? { }
28+
, modules ? [ ]
29+
}:
30+
let
3131
formatModule = builtins.getAttr format nixosModules;
3232
image = nixpkgs.lib.nixosSystem {
3333
inherit pkgs specialArgs;
@@ -36,14 +36,26 @@
3636
formatModule
3737
] ++ modules;
3838
};
39-
in
39+
in assert system == pkgs.system;
4040
image.config.system.build.${image.config.formatAttr};
4141

42+
# example usage in flakes:
43+
# outputs = { self, nixpkgs, nixos-generators, ...}: {
44+
# vmware = nixos-generators.nixosGenerate {
45+
# pkgs = nixpkgs.legacyPackages.x86_64-linux;
46+
# modules = [./configuration.nix];
47+
# format = "vmware";
48+
# };
49+
# }
50+
nixosGenerate = { pkgs, format, specialArgs ? { }, modules ? [ ] }:
51+
nixosGenerate' {
52+
system = pkgs.system;
53+
inherit pkgs format specialArgs modules;
54+
};
4255
}
4356

4457
//
4558

46-
4759
# Binary and Devshell outputs (depend on nixpkgs)
4860
(
4961
let
@@ -90,6 +102,101 @@
90102
});
91103

92104
defaultApp = forAllSystems (system: self.apps."${system}".nixos-generate);
105+
106+
checks = let
107+
# No way to limit `nix flake check` to a subset of supported systems;
108+
# see https://github.com/NixOS/nix/issues/6398.
109+
forCheckSystems = nixpkgs.lib.genAttrs [ "x86_64-linux" "aarch64-linux" ];
110+
111+
checksForNixpkgs =
112+
system:
113+
{
114+
input,
115+
id,
116+
modules ? (fetchModules system id)
117+
}:
118+
let
119+
pkgs = input.legacyPackages.${system};
120+
generateFormat = format: self.nixosGenerate' {
121+
inherit format system pkgs;
122+
nixpkgs = input;
123+
};
124+
#formatModules = builtins.removeAttrs self.nixosModules exclude;
125+
in nixlib.lib.mapAttrs' (format: _: let
126+
name = "${format}-${id}";
127+
diag = ''evaluating format "${format}" using nixpkgs input "${id}" on system "${system}"'';
128+
value = nixlib.lib.trace diag (generateFormat format);
129+
in {
130+
inherit name value;
131+
}) modules;
132+
133+
fetchModules = let
134+
excludeCommon = [
135+
# error:
136+
# Failed assertions:
137+
# - Mountpoint '/': 'autoResize = true' is not supported for 'fsType = "auto"': fsType has to be explicitly set and only the ext filesystems and f2fs support it.
138+
"cloudstack"
139+
140+
# error (ignored): error: cannot look up '<nixpkgs/nixos/lib/make-system-tarball.nix>' in pure evaluation mode (use '--impure' to override)
141+
#
142+
# at /nix/store/0b099b46lb9dmhwzyc2zgjk8lp8d9rfq-source/kexec/kexec.nix:42:49:
143+
#
144+
# 41| '';
145+
# 42| system.build.kexec_tarball = pkgs.callPackage <nixpkgs/nixos/lib/make-system-tarball.nix> {
146+
# | ^
147+
# 43| storeContents = [
148+
"kexec"
149+
"kexec-bundle"
150+
];
151+
152+
excludeNixpkgs = [
153+
# error: path '/nix/store/0bsydzh62cn1by07j5cjy28crbnbc5wz-google-guest-configs-20211116.00.drv' is not valid)
154+
"gce"
155+
156+
# Compilation error in some prerequisite or other.
157+
"proxmox"
158+
];
159+
160+
excludeNixos = [
161+
# error: getting status of '/nix/store/<...>/nixos/modules/virtualisation/kubevirt.nix': No such file or directory
162+
"kubevirt"
163+
164+
# error: getting status of '/nix/store/<...>/nixos/modules/virtualisation/proxmox-lxc.nix': No such file or directory
165+
"proxmox-lxc"
166+
];
167+
168+
aarch64Only = [ "sd-aarch64" "sd-aarch64-installer" ];
169+
170+
baseModules = builtins.removeAttrs self.nixosModules excludeCommon;
171+
nixpkgsModules = builtins.removeAttrs baseModules excludeNixpkgs;
172+
nixosModules = builtins.removeAttrs baseModules excludeNixos;
173+
174+
matrix = {
175+
"x86_64-linux" = {
176+
"nixpkgs" = builtins.removeAttrs nixpkgsModules aarch64Only;
177+
"nixos" = builtins.removeAttrs nixosModules aarch64Only;
178+
};
179+
180+
"aarch64-linux" = {
181+
"nixpkgs" = nixlib.lib.getAttrs aarch64Only nixpkgsModules;
182+
"nixos" = nixlib.lib.getAttrs aarch64Only nixosModules;
183+
};
184+
};
185+
in system: id: matrix.${system}.${id};
186+
in
187+
forCheckSystems (system: let
188+
checksForNixpkgs' = checksForNixpkgs system;
189+
190+
nixpkgsChecks = checksForNixpkgs' {
191+
input = nixpkgs;
192+
id = "nixpkgs";
193+
};
194+
195+
nixosChecks = checksForNixpkgs' {
196+
input = nixos;
197+
id = "nixos";
198+
};
199+
in nixpkgsChecks // nixosChecks);
93200
}
94201
);
95202
}

0 commit comments

Comments
 (0)