Skip to content

Commit 08e98cb

Browse files
committed
flake/templates: propagate the template's checks to the main flake's
1 parent 033449f commit 08e98cb

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

flake-modules/templates.nix

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,60 @@
11
{
2+
self,
3+
inputs,
4+
...
5+
}: {
26
flake.templates = {
37
default = {
48
path = ../templates/simple;
59
description = "A simple nix flake template for getting started with nixvim";
610
};
711
};
12+
13+
# The following adds the template flake's checks to the main (current) flake's checks.
14+
# It ensures that the template's own checks are successful.
15+
perSystem = {
16+
pkgs,
17+
system,
18+
lib,
19+
...
20+
}: {
21+
checks = let
22+
# Approximates https://github.com/NixOS/nix/blob/7cd08ae379746749506f2e33c3baeb49b58299b8/src/libexpr/flake/call-flake.nix#L46
23+
# s/flake.outputs/args.outputs/
24+
callFlake = args @ {
25+
inputs,
26+
outputs,
27+
sourceInfo,
28+
}: let
29+
outputs = args.outputs (inputs // {self = result;});
30+
result =
31+
outputs
32+
// sourceInfo
33+
// {
34+
inherit inputs outputs sourceInfo;
35+
_type = "flake";
36+
};
37+
in
38+
result;
39+
40+
templateFlakeOuputs = callFlake {
41+
inputs = {
42+
inherit (inputs) flake-parts nixpkgs;
43+
nixvim = self;
44+
};
45+
# Import and read the `outputs` field of the template flake.
46+
inherit (import ../templates/simple/flake.nix) outputs;
47+
sourceInfo = {};
48+
};
49+
50+
templateChecks = templateFlakeOuputs.checks.${system};
51+
in
52+
lib.concatMapAttrs
53+
(
54+
checkName: check: {
55+
"template-${checkName}" = check;
56+
}
57+
)
58+
templateChecks;
59+
};
860
}

0 commit comments

Comments
 (0)