docs: Introduce an user guide (#1121)

This commit is contained in:
traxys 2024-02-18 15:56:18 +01:00 committed by GitHub
parent d656834e3d
commit ad8aa72490
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 117 additions and 6 deletions

26
docs/user-guide/faq.md Normal file
View file

@ -0,0 +1,26 @@
# Frequently Asked Questions
## How do I use a plugin not implemented in nixvim
Using a plugin not supported by nixvim, but packaged in nixpkgs is straightforward:
- Register the plugin through `extraPlugins`: `extraPlugins = [pkgs.vimPlugins."<plugin name>"]`.
- Configure the plugin through `extraConfigLua`: `extraConfigLua = "require('my-plugin').setup({foo = "bar"})";`
## How do I use a plugin not packaged in nixpkgs
This is straightforward too, you can add the following to `extraPlugins` for a plugin hosted on GitHub:
```nix
extraPlugins = [(pkgs.vimUtils.buildVimPlugin {
name = "my-plugin";
src = pkgs.fetchFromGitHub {
owner = "<owner>";
repo = "<repo>";
rev = "<commit hash>";
hash = "<nix NAR hash>";
};
})];
```
The [nixpkgs manual](https://nixos.org/manual/nixpkgs/stable/#managing-plugins-with-vim-packages) has more information on this.

View file

@ -0,0 +1,42 @@
# Helpers
Regardless of the way NixVim is used (as a home-manager module, a nixos module, or as a standalone module),
helpers can be included in the same way.
You can simply use:
```nix
{
helpers,
...
}: {
# Your config
}
```
A certain number of helpers are defined that can be useful:
- `helpers.emptyTable`: An empty lua table `{}` that will be included in the final lua configuration.
This is equivalent to `{__empty = {};}`. This form can allow to do `option.__empty = {}`.
- `helpers.mkRaw str`: Write the string `str` as raw lua in the final lua configuration.
This is equivalent to `{__raw = "lua code";}`. This form can allow to do `option.__raw = "lua code"`.
- `helpers.toLuaObject obj`: Create a string representation of the Nix object. Useful to define your own plugins.
- `helpers.listToUnkeyedAttrs list`: Transforms a list to an "unkeyed" attribute set.
This allows to define mixed table/list in lua:
```nix
(listToUnkeyedAttrs ["a", "b"]) // {foo = "bar";}
```
Resulting in the following lua:
```lua
{"a", "b", [foo] = "bar"}
```
- `helpers.enableExceptInTests`: Evaluates to `true`, except in `mkTestDerivationFromNixvimModule`
where it evaluates to `false`. This allows to skip instantiating plugins that can't be run in tests.

View file

@ -0,0 +1,73 @@
# Installation
You must use a `nixpkgs` version compatible with the nixvim version you choose.
The `master` branch requires to use a _very recent_ version of nixpkgs unstable.
In order to guarantee the compatibility between nixvim & nixpkgs it is recommended to always update both at the same time.
When using a `stable` version you must use the corresponding nixvim branch, for example `nixos-23.11` when using NixOS 23.11.
Failure to use the correct branch, or an old revision of nixpkgs will likely result in errors of the form `vimPlugins.<name> attribute not found`.
NixVim can be used in four ways:
- As a NixOS module
- As a Home-Manager module
- As a nix-darwin module
- As a standalone derivation
NixVim is also available for nix flakes, or directly through an import.
## Accessing nixvim
For a direct import you can add nixvim to your configuration as follows:
```nix
let
nixvim = import (builtins.fetchGit {
url = "https://github.com/nix-community/nixvim";
# When using a different channel you can use `ref = "nixos-<version>"` to set it here
});
in
```
When using flakes you can simply add `nixvim` to the inputs:
```nix
{
inputs.nixvim = {
url = "github:nix-community/nixvim";
# If using a stable channel you can use `url = "github:nix-community/nixvim/nixos-<version>"`
inputs.nixpkgs.follows = "nixpkgs";
};
# outputs...
}
```
## Usage as a module (NixOS, Home-Manager, nix-darwin)
When using NixVim as a module you must import the NixVim module into your module system.
The three imports are:
- `<nixvim>.homeManagerModules.nixvim`
- `<nixvim>.nixosModules.nixvim`
- `<nixvim>.nixDarwinModules.nixvim`
`<nixvim>` refers to the way to access nixvim, depending on how you fetched nixvim as described in the previous section.
The imports can be added as a `imports = [ <nixvim_import> ]` in a configuration file.
You will then be able to enable nixvim through `programs.nixvim.enable = true`, and configure the
options as `programs.nixvim.<path>.<to>.<option> = <value>`.
## Standalone usage
When using nixvim as a standalone derivation you can use the following functions, located in `<nixvim>.legacyPackages.${system}`:
- `makeNixvim`: This function takes an attribute set of options values as arguments
- `makeNixvimWithModule`: This function takes an attribute set of the form: `{pkgs, extraSpecialArgs, module}`.
The only required argument is `module`, being a NixOS module. This gives access to the `imports`, `options`, `config` variables, and using functions like `{config, ...}: { ... }`.
There are also some helper functions in `<nixvim>.lib.${system}` like:
- `check.mkTestDerivationFromNixvimModule`, taking the same arguments as `makeNixvimWithModule` and generates a check derivation.
- `check.mkTestDerivationFromNvim`, taking an attribute set of the form `{name = "<derivation name>"; nvim = <nvim derivation>}`. The `nvim` is the standalone derivation provided by NixVim.
The nixvim derivation can then be used like any other package!
For more information you can look at the [nixvim standalone flake template](https://github.com/nix-community/nixvim/blob/main/templates/simple/flake.nix).