diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 55474335..42de5265 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -12,3 +12,4 @@ jobs: with: github_access_token: ${{ secrets.GITHUB_TOKEN }} - run: nix flake check + - run: nix flake check ./templates/_wrapper/simple diff --git a/flake.nix b/flake.nix index fb5758e9..909009c5 100644 --- a/flake.nix +++ b/flake.nix @@ -163,6 +163,7 @@ lib = import ./lib { inherit pkgs; inherit (pkgs) lib; + makeNixvim = self.legacyPackages."${system}".makeNixvim; }; }); in diff --git a/lib/default.nix b/lib/default.nix index 015775f2..b5713a32 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -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; } diff --git a/templates/_wrapper/README.md b/templates/_wrapper/README.md new file mode 100644 index 00000000..854df5b1 --- /dev/null +++ b/templates/_wrapper/README.md @@ -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. diff --git a/templates/_wrapper/simple/flake.nix b/templates/_wrapper/simple/flake.nix new file mode 100644 index 00000000..b31fc60c --- /dev/null +++ b/templates/_wrapper/simple/flake.nix @@ -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; +} diff --git a/templates/simple/flake.nix b/templates/simple/flake.nix index 55aa8557..69729aec 100644 --- a/templates/simple/flake.nix +++ b/templates/simple/flake.nix @@ -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 { @@ -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"; }; diff --git a/tests/default.nix b/tests/default.nix index 2f406d4f..f98ec6ee 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -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 { diff --git a/tests/test-derivation.nix b/tests/test-derivation.nix index fc9ac949..c43ac897 100644 --- a/tests/test-derivation.nix +++ b/tests/test-derivation.nix @@ -7,7 +7,7 @@ mkTestDerivationFromNvim = { name, nvim, - dontRun, + dontRun ? false, ... }: pkgs.stdenv.mkDerivation { @@ -55,5 +55,6 @@ inherit name nvim; inherit (testAttributes) dontRun; }; -in - mkTestDerivation +in { + inherit mkTestDerivation mkTestDerivationFromNvim; +}