Skip to content

Commit

Permalink
flake/templates: propagate the template's checks to the main flake's
Browse files Browse the repository at this point in the history
  • Loading branch information
GaetanLepage committed Jan 6, 2024
1 parent 033449f commit 08e98cb
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions flake-modules/templates.nix
Original file line number Diff line number Diff line change
@@ -1,8 +1,60 @@
{
self,
inputs,
...
}: {
flake.templates = {
default = {
path = ../templates/simple;
description = "A simple nix flake template for getting started with nixvim";
};
};

# The following adds the template flake's checks to the main (current) flake's checks.
# It ensures that the template's own checks are successful.
perSystem = {
pkgs,
system,
lib,
...
}: {
checks = let
# Approximates https://github.com/NixOS/nix/blob/7cd08ae379746749506f2e33c3baeb49b58299b8/src/libexpr/flake/call-flake.nix#L46
# s/flake.outputs/args.outputs/
callFlake = args @ {
inputs,
outputs,
sourceInfo,
}: let
outputs = args.outputs (inputs // {self = result;});
result =
outputs
// sourceInfo
// {
inherit inputs outputs sourceInfo;
_type = "flake";
};
in
result;

templateFlakeOuputs = callFlake {
inputs = {
inherit (inputs) flake-parts nixpkgs;
nixvim = self;
};
# Import and read the `outputs` field of the template flake.
inherit (import ../templates/simple/flake.nix) outputs;
sourceInfo = {};
};

templateChecks = templateFlakeOuputs.checks.${system};
in
lib.concatMapAttrs
(
checkName: check: {
"template-${checkName}" = check;
}
)
templateChecks;
};
}

0 comments on commit 08e98cb

Please sign in to comment.