diff --git a/README.md b/README.md
index b7d41a14..e7cf5b6f 100644
--- a/README.md
+++ b/README.md
@@ -82,8 +82,8 @@ for a home-manager installation, `inputs.nixvim.nixosModules.nixvim`, for NixOS,
and `inputs.nixvim.nixDarwinModules.nixvim` for nix-darwin.
## Usage
-NixVim can be used in four ways: through the home-manager, nix-darwin, and NixOS modules,
-and through the `makeNixvim` function. To use the modules, just import the
+NixVim can be used in four ways: through the home-manager, nix-darwin, NixOS modules,
+and standalone through the `makeNixvim` function. To use the modules, just import the
`nixvim.homeManagerModules.nixvim`, `nixvim.nixDarwinModules.nixvim`, and
`nixvim.nixosModules.nixvim` modules, depending on which system
you're using.
@@ -100,9 +100,18 @@ If you want to use it standalone, you can use the `makeNixvim` function:
}
```
+To get started with a standalone configuration you can use the template by running the following command in an empty directory (recommended):
+
+```
+nix flake init --template github:pta2002/nixvim
+```
+
Alternatively if you want a minimal flake to allow building a custom neovim you
can use the following:
+
+ Minimal flake configuration
+
```nix
{
description = "A very basic flake";
@@ -132,6 +141,8 @@ can use the following:
}
```
+
+
You can then run neovim using `nix run .# -- `. This can be useful to test
config changes easily.
diff --git a/flake.nix b/flake.nix
index df441ca5..8c6be371 100644
--- a/flake.nix
+++ b/flake.nix
@@ -107,6 +107,11 @@
};
};
formatter = pkgs.alejandra;
+
+ lib = import ./lib {
+ inherit pkgs;
+ inherit (pkgs) lib;
+ };
});
in
flakeOutput
@@ -114,5 +119,14 @@
nixosModules.nixvim = import ./wrappers/nixos.nix modules;
homeManagerModules.nixvim = import ./wrappers/hm.nix modules;
nixDarwinModules.nixvim = import ./wrappers/darwin.nix modules;
+
+ templates = let
+ simple = {
+ path = ./templates/simple;
+ description = "A simple nix flake template for getting started with nixvim";
+ };
+ in {
+ default = simple;
+ };
};
}
diff --git a/lib/check.nix b/lib/check.nix
new file mode 100644
index 00000000..34bed49f
--- /dev/null
+++ b/lib/check.nix
@@ -0,0 +1,30 @@
+{pkgs, ...}: {
+ checkNvim = {
+ name,
+ nvim,
+ ...
+ }:
+ pkgs.stdenv.mkDerivation {
+ name = name;
+
+ nativeBuildInputs = [nvim];
+
+ dontUnpack = true;
+ # We need to set HOME because neovim will try to create some files
+ #
+ # Because neovim does not return an exitcode when quitting we need to check if there are
+ # errors on stderr
+ buildPhase = ''
+ output=$(HOME=$(realpath .) nvim -mn --headless "+q" 2>&1 >/dev/null)
+ if [[ -n $output ]]; then
+ echo "ERROR: $output"
+ exit 1
+ fi
+ '';
+
+ # If we don't do this nix is not happy
+ installPhase = ''
+ mkdir $out
+ '';
+ };
+}
diff --git a/lib/default.nix b/lib/default.nix
new file mode 100644
index 00000000..015775f2
--- /dev/null
+++ b/lib/default.nix
@@ -0,0 +1,6 @@
+# Args probably only needs pkgs and lib
+args: {
+ # Add all exported modules here
+ check = import ./check.nix args;
+ helpers = import ./helpers.nix args;
+}
diff --git a/templates/simple/README.md b/templates/simple/README.md
new file mode 100644
index 00000000..610d78d4
--- /dev/null
+++ b/templates/simple/README.md
@@ -0,0 +1,16 @@
+# Nixvim template
+
+This template gives you a good starting point for configuring nixvim standalone.
+
+## Configuring
+
+To start configuring, just add or modify the nix files in `./config`. If you add a new configuration file, remember to add it to the [`congig/default.nix`](./config/default.nix) file
+
+## Testing your new configuration
+
+To test your configuration simply run the following command
+
+```
+nix run .
+```
+
diff --git a/templates/simple/config/bufferline.nix b/templates/simple/config/bufferline.nix
new file mode 100644
index 00000000..fe5cf058
--- /dev/null
+++ b/templates/simple/config/bufferline.nix
@@ -0,0 +1,5 @@
+{
+ plugins.bufferline = {
+ enable = true;
+ };
+}
diff --git a/templates/simple/config/default.nix b/templates/simple/config/default.nix
new file mode 100644
index 00000000..f9a64549
--- /dev/null
+++ b/templates/simple/config/default.nix
@@ -0,0 +1,6 @@
+{
+ # Import all your configuration modules here
+ imports = [
+ ./bufferline.nix
+ ];
+}
diff --git a/templates/simple/flake.nix b/templates/simple/flake.nix
new file mode 100644
index 00000000..55aa8557
--- /dev/null
+++ b/templates/simple/flake.nix
@@ -0,0 +1,39 @@
+{
+ description = "A nixvim configuration";
+
+ inputs = {
+ nixvim.url = "github:pta2002/nixvim";
+ flake-utils.url = "github:numtide/flake-utils";
+ };
+
+ outputs = {
+ nixpkgs,
+ nixvim,
+ flake-utils,
+ ...
+ } @ inputs: let
+ nixvimLib = nixvim.lib;
+ config = import ./config; # import the module directly
+ in
+ flake-utils.lib.eachDefaultSystem (system: let
+ pkgs = import nixpkgs {inherit system;};
+ nixvim' = nixvim.legacyPackages.${system};
+ nvim = nixvim'.makeNixvimWithModule {
+ inherit pkgs;
+ module = config;
+ };
+ in {
+ checks = {
+ # Run `nix check .` to verify that your config is not broken
+ default = nixvim.lib.${system}.check.checkNvim {
+ inherit nvim;
+ name = "A nixvim configuration";
+ };
+ };
+
+ packages = {
+ # Lets you run `nix run .` to start nixvim
+ default = nvim;
+ };
+ });
+}
diff --git a/tests/checks.nix b/tests/checks.nix
index 3c127d7a..72b33c19 100644
--- a/tests/checks.nix
+++ b/tests/checks.nix
@@ -1,36 +1,16 @@
{
makeNixvim,
pkgs,
-}: let
+} @ args: let
tests = import ./plugins {inherit (pkgs) lib;};
+ check = import ../lib/check.nix args;
+ checkConfig = check.checkNvim;
in
# We attempt to build & execute all configurations
builtins.mapAttrs (
name: config: let
nvim = makeNixvim config;
in
- pkgs.stdenv.mkDerivation {
- name = name;
-
- nativeBuildInputs = [nvim];
-
- dontUnpack = true;
- # We need to set HOME because neovim will try to create some files
- #
- # Because neovim does not return an exitcode when quitting we need to check if there are
- # errors on stderr
- buildPhase = ''
- output=$(HOME=$(realpath .) nvim -mn --headless "+q" 2>&1 >/dev/null)
- if [[ -n $output ]]; then
- echo "ERROR: $output"
- exit 1
- fi
- '';
-
- # If we don't do this nix is not happy
- installPhase = ''
- mkdir $out
- '';
- }
+ checkConfig {inherit name nvim;}
)
tests