mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-21 08:35:43 +02:00
misc: added flake template (#219)
* Added simple flake template * Added readme to template * Updated readme to show how to use the template * Formatting * removed unused file from template * Fixed template url and pkgs * Formatting
This commit is contained in:
parent
6e027c40f2
commit
2258eb8df8
9 changed files with 133 additions and 26 deletions
15
README.md
15
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.
|
and `inputs.nixvim.nixDarwinModules.nixvim` for nix-darwin.
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
NixVim can be used in four ways: through the home-manager, nix-darwin, and NixOS modules,
|
NixVim can be used in four ways: through the home-manager, nix-darwin, NixOS modules,
|
||||||
and through the `makeNixvim` function. To use the modules, just import the
|
and standalone through the `makeNixvim` function. To use the modules, just import the
|
||||||
`nixvim.homeManagerModules.nixvim`, `nixvim.nixDarwinModules.nixvim`, and
|
`nixvim.homeManagerModules.nixvim`, `nixvim.nixDarwinModules.nixvim`, and
|
||||||
`nixvim.nixosModules.nixvim` modules, depending on which system
|
`nixvim.nixosModules.nixvim` modules, depending on which system
|
||||||
you're using.
|
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
|
Alternatively if you want a minimal flake to allow building a custom neovim you
|
||||||
can use the following:
|
can use the following:
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>Minimal flake configuration</summary>
|
||||||
|
|
||||||
```nix
|
```nix
|
||||||
{
|
{
|
||||||
description = "A very basic flake";
|
description = "A very basic flake";
|
||||||
|
@ -132,6 +141,8 @@ can use the following:
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
You can then run neovim using `nix run .# -- <file>`. This can be useful to test
|
You can then run neovim using `nix run .# -- <file>`. This can be useful to test
|
||||||
config changes easily.
|
config changes easily.
|
||||||
|
|
||||||
|
|
14
flake.nix
14
flake.nix
|
@ -107,6 +107,11 @@
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
formatter = pkgs.alejandra;
|
formatter = pkgs.alejandra;
|
||||||
|
|
||||||
|
lib = import ./lib {
|
||||||
|
inherit pkgs;
|
||||||
|
inherit (pkgs) lib;
|
||||||
|
};
|
||||||
});
|
});
|
||||||
in
|
in
|
||||||
flakeOutput
|
flakeOutput
|
||||||
|
@ -114,5 +119,14 @@
|
||||||
nixosModules.nixvim = import ./wrappers/nixos.nix modules;
|
nixosModules.nixvim = import ./wrappers/nixos.nix modules;
|
||||||
homeManagerModules.nixvim = import ./wrappers/hm.nix modules;
|
homeManagerModules.nixvim = import ./wrappers/hm.nix modules;
|
||||||
nixDarwinModules.nixvim = import ./wrappers/darwin.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;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
30
lib/check.nix
Normal file
30
lib/check.nix
Normal file
|
@ -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
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
}
|
6
lib/default.nix
Normal file
6
lib/default.nix
Normal file
|
@ -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;
|
||||||
|
}
|
16
templates/simple/README.md
Normal file
16
templates/simple/README.md
Normal file
|
@ -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 .
|
||||||
|
```
|
||||||
|
|
5
templates/simple/config/bufferline.nix
Normal file
5
templates/simple/config/bufferline.nix
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
{
|
||||||
|
plugins.bufferline = {
|
||||||
|
enable = true;
|
||||||
|
};
|
||||||
|
}
|
6
templates/simple/config/default.nix
Normal file
6
templates/simple/config/default.nix
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
{
|
||||||
|
# Import all your configuration modules here
|
||||||
|
imports = [
|
||||||
|
./bufferline.nix
|
||||||
|
];
|
||||||
|
}
|
39
templates/simple/flake.nix
Normal file
39
templates/simple/flake.nix
Normal file
|
@ -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;
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
|
@ -1,36 +1,16 @@
|
||||||
{
|
{
|
||||||
makeNixvim,
|
makeNixvim,
|
||||||
pkgs,
|
pkgs,
|
||||||
}: let
|
} @ args: let
|
||||||
tests = import ./plugins {inherit (pkgs) lib;};
|
tests = import ./plugins {inherit (pkgs) lib;};
|
||||||
|
check = import ../lib/check.nix args;
|
||||||
|
checkConfig = check.checkNvim;
|
||||||
in
|
in
|
||||||
# We attempt to build & execute all configurations
|
# We attempt to build & execute all configurations
|
||||||
builtins.mapAttrs (
|
builtins.mapAttrs (
|
||||||
name: config: let
|
name: config: let
|
||||||
nvim = makeNixvim config;
|
nvim = makeNixvim config;
|
||||||
in
|
in
|
||||||
pkgs.stdenv.mkDerivation {
|
checkConfig {inherit name nvim;}
|
||||||
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
|
|
||||||
'';
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
tests
|
tests
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue