Skip to content

Commit

Permalink
Added test for template and fixed check export for lib (nix-community…
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexnortung authored May 15, 2023
1 parent ecaf80b commit 3600698
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 9 deletions.
1 change: 1 addition & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ jobs:
with:
github_access_token: ${{ secrets.GITHUB_TOKEN }}
- run: nix flake check
- run: nix flake check ./templates/_wrapper/simple
1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@
lib = import ./lib {
inherit pkgs;
inherit (pkgs) lib;
makeNixvim = self.legacyPackages."${system}".makeNixvim;
};
});
in
Expand Down
10 changes: 8 additions & 2 deletions lib/default.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# Args probably only needs pkgs and lib
args: {
{
makeNixvim,
pkgs,
...
} @ args: {
# Add all exported modules here
check = import ./check.nix args;
check = import ../tests/test-derivation.nix {
inherit makeNixvim pkgs;
};
helpers = import ./helpers.nix args;
}
9 changes: 9 additions & 0 deletions templates/_wrapper/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# templates/_wrapper

This directory contains wrapper flakes for the nixvim templates.
The purpose of the wrappers is to be able to run tests on templates deterministically on the branch or PR that is being worked on.
It does this by overwriting the url of nixvim and other dependencies to a path within this repo.

It is also used in the github workflows, so that we can always check if the template is working or not

NOTE: It is important that we do not commit the `flake.lock` files here as that could cause problems with the check once any files are updated outside the wrapper. Also we cannot add `flake.lock` to `.gitignore` since nix will sometimes complain.
12 changes: 12 additions & 0 deletions templates/_wrapper/simple/flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
inputs = {
nixvim.url = "path:../../..";
simple = {
url = "path:../../simple";
inputs.nixvim.follows = "nixvim";
inputs.flake-utils.follows = "nixvim/flake-utils";
};
};

outputs = inputs: inputs.simple;
}
6 changes: 3 additions & 3 deletions templates/simple/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
flake-utils,
...
} @ inputs: let
nixvimLib = nixvim.lib;
config = import ./config; # import the module directly
in
flake-utils.lib.eachDefaultSystem (system: let
nixvimLib = nixvim.lib.${system};
pkgs = import nixpkgs {inherit system;};
nixvim' = nixvim.legacyPackages.${system};
nvim = nixvim'.makeNixvimWithModule {
Expand All @@ -24,8 +24,8 @@
};
in {
checks = {
# Run `nix check .` to verify that your config is not broken
default = nixvim.lib.${system}.check.checkNvim {
# Run `nix flake check .` to verify that your config is not broken
default = nixvimLib.check.mkTestDerivationFromNvim {
inherit nvim;
name = "A nixvim configuration";
};
Expand Down
3 changes: 2 additions & 1 deletion tests/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
pkgs,
}: let
fetchTests = import ./fetch-tests.nix;
mkTestDerivation = import ./test-derivation.nix {inherit pkgs makeNixvim;};
test-derivation = import ./test-derivation.nix {inherit pkgs makeNixvim;};
mkTestDerivation = test-derivation.mkTestDerivation;

# List of files containing configurations
testFiles = fetchTests {
Expand Down
7 changes: 4 additions & 3 deletions tests/test-derivation.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
mkTestDerivationFromNvim = {
name,
nvim,
dontRun,
dontRun ? false,
...
}:
pkgs.stdenv.mkDerivation {
Expand Down Expand Up @@ -55,5 +55,6 @@
inherit name nvim;
inherit (testAttributes) dontRun;
};
in
mkTestDerivation
in {
inherit mkTestDerivation mkTestDerivationFromNvim;
}

0 comments on commit 3600698

Please sign in to comment.