Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

flake/templates: propagate the template's checks to the main flake's #902

Merged
merged 3 commits into from
Jan 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,3 @@ jobs:
name: nix-community
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
- run: nix flake check --all-systems --builders ""
- run: nix flake check --all-systems --builders "" ./templates/_wrapper/simple --no-write-lock-file
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;
};
}
2 changes: 1 addition & 1 deletion templates/simple/config/default.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{self, ...}: {
{
# Import all your configuration modules here
imports = [
./bufferline.nix
Expand Down
3 changes: 1 addition & 2 deletions templates/simple/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
};

outputs = {
self,
nixvim,
flake-parts,
...
Expand All @@ -35,7 +34,7 @@
module = config;
# You can use `extraSpecialArgs` to pass additional arguments to your module files
extraSpecialArgs = {
inherit self;
# inherit (inputs) foo;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why leave this as a comment? It's to show how to pass something?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is just to show that it can be done.

};
};
in {
Expand Down