ayamir / nvimdots

A well configured and structured Neovim.
BSD 3-Clause "New" or "Revised" License
2.91k stars 458 forks source link

[doc] Add `NixOS and home-manager` entry to wiki #908

Closed misumisumi closed 1 year ago

misumisumi commented 1 year ago

Feature description

I have submitted a PR for NixOS support in #906. I would like to add to the wiki about NixOS support. module options will be replaced with appropriate ones when the PR is merged Please review.

what's inside ?

Preview

raw markdown code # NixOS and home-manager This repository contains the nixosModule for home-manager provided by [flakes](https://nixos.wiki/wiki/Flakes). You can use it right away if you are using [home-manager](https://github.com/nix-community/home-manager) on NixOS as well as non-NixOS. ## Usage for NixOS. Add the following to your `flake.nix`, `configuration.nix` and `nvimdots.nix`. Relogin to shell after `nixos-rebuild switch --flake `. - `flake.nix` ```nix { inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; inputs.nvimdots.url = "github:ayamir/nvimdots"; inputs.home-manager = { url = "github:nix-community/home-manager"; inputs.nixpkgs.follows = "nixpkgs"; }; nixosConfigurations = { use-nvimdots = inputs.nixpkgs.lib.nixosSystem { system = "x86_64-linux"; modules = [ # ... inputs.home-manager.nixosModules.home-manager { home-manager.users."example-user" = { imports = [ inputs.nvimdots.nixosModules.nvimdots (import ./nvimdots.nix) ]; }; home-manager.extraSpecialArgs = { inherit inputs; }; } ./configuration.nix ]; specialArgs = { inherit inputs; }; }; }; }; } ``` - `configuration.nix` ```nix { # ... programs.nix-ld.enable = true; # ... } ``` - `nvimdots.nix` `setBuildEnv` provides `CPATH`, `CPLUG_INCLUDE_PATH`, `LD_LIBLARY_PATH`, `LIBRARY_PATH`, `NIX_LD_LIBRARY_PATH`, `PKG_CONFIG_PATH`. `withBuildTools` provides basic build tools such as `gcc` and `pkg-config`. These are required for `mason.nvim` and `nvim-treesitter` to work properly. Also, they are only provided to `neovim` and do not affect the entire session. ```nix { programs.neovim.nvimdots = { enable = true; setBuildEnv = true; withBuildTools = true; }; } ``` ### `mason.nvim` cannot build packages or run installed binaries. This is because the dependencies are not included. NixOS does not conform to the [Filesystem Hierarchy Standard (FHS)](https://en.wikipedia.org/wiki/Filesystem_Hierarchy_Standard), so some ingenuity is required. This nixosModules provides options to simplify dependency resolution. You can still use `programs.neovim.extraPackages`, `programs.neovim.extraPython3Packages`, `programs.neovim.extraLuaPackages` provided by home-manager. - `nvimdots.nix` ```nix {pkgs, ...}: { programs.neovim.nvimdots = { enable = true; setBuildEnv = true; withBuildTools = true; extraRPackages = rPkgs: []; # need packages for R include `nixpkgs.rPackages`. extraHaskellPackages = hsPkgs: []; # need packages for haskell include `nixpkgs.haskellPackages`. extraDependentPackages = with pkgs; [] # need packages `lib`, `include`, and `pkgconfig`. }; } ``` ### How to check for required dependencies. For binaries, `patchelf --print-needed ` will list the required packages. You can also check the library link status with `ldd `. You can check the dependencies required at build time from the build log from the UI of `mason.nvim` opened with `:Mason`. If it is included in `nixpkgs`, you may be able to find the package you need by looking at the `*.nix` sources. ### What to do if you can't build with `mason.nvim`. If it is provided by `nixpkgs`, you should be able to use it by adding the following settings. https://github.com/ayamir/nvimdots/blob/6de8afe0fc4a6e53a9d64a013327d5482b6dbe99/lua/modules/configs/completion/lsp.lua#L143-L148 ## Usage for `home-manager` on non-NixOS Unlike on NixOS, build tools and dependencies should be provided by the package manager provided by the distribution. Of course, you can let `nix` resolve dependencies as they do for NixOS, but that can be a problem if you run the build command from within `neovim`. Add the following to your `flake.nix` and `nvimdots.nix`. Relogin to shell after `home-manager switch --flake `. - `flake.nix` ```nix { inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; inputs.nvimdots.url = "github:ayamir/nvimdots"; inputs.home-manager = { url = "github:nix-community/home-manager"; inputs.nixpkgs.follows = "nixpkgs"; }; homeConfigurations = { use-nvimdots = inputs.home-manager.lib.homeManagerConfiguration { inherit (inputs) nixpkgs; modules = [ inputs.nvimdots.nixosModules.nvimdots (import ./nvimdots.nix) ]; extraSpecialArgs = { inherit inputs; }; }; }; } ``` - `nvimdots.nix` ```nix { programs.neovim.nvimdots = { enable = true; # Comment out if resolving dependencies on `nix`. # setBuildEnv = true; # withBuildTools = true; }; } ``` ## Module Options Please see https://github.com/misumisumi/nvimdots/blob/36d0b3d920f6e4e5397646ddb522f8c8aa43af93/nixos/neovim/default.nix#L11C1-L135C5

NixOS and home-manager

This repository contains the nixosModule for home-manager provided by flakes.
You can use it right away if you are using home-manager on NixOS as well as non-NixOS.

Usage for NixOS.

Add the following to your flake.nix, configuration.nix and nvimdots.nix.
Relogin to shell after nixos-rebuild switch --flake <flake-url>.

mason.nvim cannot build packages or run installed binaries.

This is because the dependencies are not included.
NixOS does not conform to the Filesystem Hierarchy Standard (FHS), so some ingenuity is required.
This nixosModules provides options to simplify dependency resolution.
You can still use programs.neovim.extraPackages, programs.neovim.extraPython3Packages, programs.neovim.extraLuaPackages provided by home-manager.

How to check for required dependencies.

For binaries, patchelf --print-needed <binary> will list the required packages.
You can also check the library link status with ldd <binary>.
You can check the dependencies required at build time from the build log from the UI of mason.nvim opened with :Mason.
If it is included in nixpkgs, you may be able to find the package you need by looking at the *.nix sources.

What to do if you can't build with mason.nvim.

If it is provided by nixpkgs, you should be able to use it by adding the following settings.

https://github.com/ayamir/nvimdots/blob/6de8afe0fc4a6e53a9d64a013327d5482b6dbe99/lua/modules/configs/completion/lsp.lua#L143-L148

Usage for home-manager on non-NixOS

Unlike on NixOS, build tools and dependencies should be provided by the package manager provided by the distribution.
Of course, you can let nix resolve dependencies as they do for NixOS, but that can be a problem if you run the build command from within neovim.
Add the following to your flake.nix and nvimdots.nix. Relogin to shell after home-manager switch --flake <flake-url>.

Module Options

Please see https://github.com/misumisumi/nvimdots/blob/36d0b3d920f6e4e5397646ddb522f8c8aa43af93/nixos/neovim/default.nix#L11C1-L135C5

Additional information

No response

Jint-lzxy commented 1 year ago

LGTM 🎉 I made some minor modifications, formatted the code, and added a new entry under Common Q&A. @misumisumi I will add this to the Wiki and its title to README.md if the content looks good to u.

Raw markdown code

````markdown # NixOS Support (via home-manager) This repository contains the `nixosModule` for home-manager using [flakes](https://nixos.wiki/wiki/Flakes). You may use this config right away as long as you are using [home-manager](https://github.com/nix-community/home-manager) to manage your environment. ## Prerequisites Add the following snippets to your `flake.nix`, `configuration.nix` and `nvimdots.nix`. Re-login to your shell after executing `nixos-rebuild switch --flake `. - `flake.nix` ```nix { inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; inputs.nvimdots.url = "github:ayamir/nvimdots"; inputs.home-manager = { url = "github:nix-community/home-manager"; inputs.nixpkgs.follows = "nixpkgs"; }; nixosConfigurations = { use-nvimdots = inputs.nixpkgs.lib.nixosSystem { system = "x86_64-linux"; modules = [ # Other contents... inputs.home-manager.nixosModules.home-manager { home-manager.users."example-user" = { imports = [ inputs.nvimdots.nixosModules.nvimdots (import ./nvimdots.nix) ]; }; home-manager.extraSpecialArgs = { inherit inputs; }; } ./configuration.nix ]; specialArgs = { inherit inputs; }; }; }; } ``` - `configuration.nix` ```nix { # Other contents... programs.nix-ld.enable = true; } ``` - `nvimdots.nix` - `setBuildEnv`: If set, automatically configures your `$CPATH`, `$CPLUG_INCLUDE_PATH`, `$LD_LIBLARY_PATH`, `$LIBRARY_PATH`, `$NIX_LD_LIBRARY_PATH`, and `$PKG_CONFIG_PATH`. - `withBuildTools`: If set, automatically installs some build utils such as `gcc` and `pkg-config`. - **Caveats:** - These are required tooling so that `mason.nvim` and `nvim-treesitter` can work as expected. - They bundle with `neovim` and won't affect other sessions. ```nix { programs.neovim.nvimdots = { enable = true; setBuildEnv = true; withBuildTools = true; }; } ``` ## Common Q&A ### `mason.nvim` cannot build some of the packages or execute those installed binaries This is because some dependencies are not distributed along with the system - NixOS does not conform to the [Filesystem Hierarchy Standard (FHS)](https://en.wikipedia.org/wiki/Filesystem_Hierarchy_Standard), so some ingenuity is required. This `nixosModules` provides several options to simplify dependency resolution. Nevertheless, you may still use `programs.neovim.extraPackages`, `programs.neovim.extraPython3Packages`, `programs.neovim.extraLuaPackages` provided by home-manager. - `nvimdots.nix` ```nix {pkgs, ...}: { programs.neovim.nvimdots = { enable = true; setBuildEnv = true; withBuildTools = true; extraRPackages = rPkgs: []; # configure packages for `R` (nixpkgs.rPackages). extraHaskellPackages = hsPkgs: []; # cofigure packages for haskell (nixpkgs.haskellPackages). extraDependentPackages = with pkgs; [] # properly setup directory hierarchy (`lib`, `include`, and `pkgconfig`). } } ``` ### How to check for the list of required dependencies - For binaries, `patchelf --print-needed ` will list the required packages. - You can also check the information used by `ldd` in this package and/or dynamiclib with `ldd `. - You can check the list of dependencies required during build time using the build log (via `mason.nvim`'s UI). - If this dependency is included in `nixpkgs`, you may be able to find the package you need by looking at the `*.nix` sources. - If you want to be on the safe side, here is a list of dependencies for all packages that have already been registered in `mason-registry`: ```console libamd <==> https://github.com/zship/libamd libc <==> https://www.gnu.org/software/libc/ [OR] libc++ <==> https://libcxx.llvm.org/ libevent <==> https://libevent.org/ libiconv <==> https://www.gnu.org/software/libiconv/ libmsgpack <==> http://msgpack.org/ libz <==> https://www.zlib.net/ libzstd <==> https://github.com/facebook/zstd ``` ### What to do if you can't build a package via `mason.nvim` If it is provided by `nixpkgs`, you should be able to use it by adding the following settings. This is the same as setting up other packages that require external installation: ```lua -- Setup lsps that are not supported by `mason.nvim` but supported by `nvim-lspconfig` here. if vim.fn.executable("dart") == 1 then local _opts = require("completion.servers.dartls") local final_opts = vim.tbl_deep_extend("keep", _opts, opts) nvim_lsp.dartls.setup(final_opts) end ``` ## Using `home-manager` on operating systems other than NixOS Unlike NixOS, the package manager that ships with your distribution should have provided those necessary build tools and dependencies. Of course, you may instruct `nix` to resolve those dependencies as they do for NixOS as well, but that can be a problem if you run the build command from within `neovim`. To fix this, add the following snippets to your `flake.nix`, `configuration.nix` and `nvimdots.nix`. Re-login to your shell after executing `nixos-rebuild switch --flake `. - `flake.nix` ```nix { inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; inputs.nvimdots.url = "github:ayamir/nvimdots"; inputs.home-manager = { url = "github:nix-community/home-manager"; inputs.nixpkgs.follows = "nixpkgs"; }; homeConfigurations = { use-nvimdots = inputs.home-manager.lib.homeManagerConfiguration { inherit (inputs) nixpkgs; modules = [ inputs.nvimdots.nixosModules.nvimdots (import ./nvimdots.nix) ]; extraSpecialArgs = { inherit inputs; }; }; }; } ``` - `nvimdots.nix` ```nix { programs.neovim.nvimdots = { enable = true; # Comment out the following two lines if you're resolving dependencies via `nix`. # setBuildEnv = true; # withBuildTools = true; }; } ``` ## Customize your experience Have a look at [default.nix (selection)](https://github.com/misumisumi/nvimdots/blob/36d0b3d920f6e4e5397646ddb522f8c8aa43af93/nixos/neovim/default.nix#L11C1-L135C5) for more information. ````

Diff

````diff diff --git a/91xg_8j9169dydct2k4r7yw80000gn.md b/91xg_8j9169dydct2k4r7yw80000gn.md index 8bd923b..f461911 100644 --- a/91xg_8j9169dydct2k4r7yw80000gn.md +++ b/91xg_8j9169dydct2k4r7yw80000gn.md @@ -1,311 +1,165 @@ -# NixOS and home-manager +# NixOS Support (via home-manager) -This repository contains the nixosModule for home-manager provided by [flakes](https://nixos.wiki/wiki/Flakes). -You can use it right away if you are using [home-manager](https://github.com/nix-community/home-manager) on NixOS as well as non-NixOS. +This repository contains the `nixosModule` for home-manager using [flakes](https://nixos.wiki/wiki/Flakes). You may use this config right away as long as you are using [home-manager](https://github.com/nix-community/home-manager) to manage your environment. -## Usage for NixOS. +## Prerequisites -Add the following to your `flake.nix`, `configuration.nix` and `nvimdots.nix`. -Relogin to shell after `nixos-rebuild switch --flake `. +Add the following snippets to your `flake.nix`, `configuration.nix` and `nvimdots.nix`. +Re-login to your shell after executing `nixos-rebuild switch --flake `. - `flake.nix` - ```nix - { - inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; - inputs.nvimdots.url = "github:ayamir/nvimdots"; - inputs.home-manager = { - url = "github:nix-community/home-manager"; - inputs.nixpkgs.follows = "nixpkgs"; +```nix +{ + inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + inputs.nvimdots.url = "github:ayamir/nvimdots"; + inputs.home-manager = { + url = "github:nix-community/home-manager"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + nixosConfigurations = { + use-nvimdots = inputs.nixpkgs.lib.nixosSystem { + system = "x86_64-linux"; + modules = [ # Other contents... + inputs.home-manager.nixosModules.home-manager + { + home-manager.users."example-user" = { + imports = + [ inputs.nvimdots.nixosModules.nvimdots (import ./nvimdots.nix) ]; + }; + home-manager.extraSpecialArgs = { inherit inputs; }; + } + ./configuration.nix + ]; + specialArgs = { inherit inputs; }; }; - nixosConfigurations = { - use-nvimdots = inputs.nixpkgs.lib.nixosSystem { - system = "x86_64-linux"; - modules = - [ # ... - inputs.home-manager.nixosModules.home-manager { - home-manager.users."example-user" = { - imports = - [ - inputs.nvimdots.nixosModules.nvimdots - (import ./nvimdots.nix) - ]; - }; - home-manager.extraSpecialArgs = { inherit inputs; }; - } - ./configuration.nix - ]; - specialArgs = { inherit inputs; }; - }; - }; - }; - } - ``` + }; +} +``` - `configuration.nix` - ```nix - { - # ... - programs.nix-ld.enable = true; - # ... - } - ``` - -- `nvimdots.nix` - - `setBuildEnv` provides `CPATH`, `CPLUG_INCLUDE_PATH`, `LD_LIBLARY_PATH`, `LIBRARY_PATH`, `NIX_LD_LIBRARY_PATH`, `PKG_CONFIG_PATH`. - `withBuildTools` provides basic build tools such as `gcc` and `pkg-config`. - These are required for `mason.nvim` and `nvim-treesitter` to work properly. - Also, they are only provided to `neovim` and do not affect the entire session. - - ```nix - { - programs.neovim.nvimdots = { - enable = true; - setBuildEnv = true; - withBuildTools = true; - }; - } - ``` - -### `mason.nvim` cannot build packages or run installed binaries. - -This is because the dependencies are not included. -NixOS does not conform to the [Filesystem Hierarchy Standard (FHS)](https://en.wikipedia.org/wiki/Filesystem_Hierarchy_Standard), so some ingenuity is required. -This nixosModules provides options to simplify dependency resolution. -You can still use `programs.neovim.extraPackages`, `programs.neovim.extraPython3Packages`, `programs.neovim.extraLuaPackages` provided by home-manager. - -- `nvimdots.nix` - - ```nix - {pkgs, ...}: - { - programs.neovim.nvimdots = { - enable = true; - setBuildEnv = true; - withBuildTools = true; - extraRPackages = rPkgs: []; # need packages for R include `nixpkgs.rPackages`. - extraHaskellPackages = hsPkgs: []; # need packages for haskell include `nixpkgs.haskellPackages`. - extraDependentPackages = with pkgs; [] # need packages `lib`, `include`, and `pkgconfig`. - }; - } - ``` - -### How to check for required dependencies. - -For binaries, `patchelf --print-needed ` will list the required packages. -You can also check the library link status with `ldd `. -You can check the dependencies required at build time from the build log from the UI of `mason.nvim` opened with `:Mason`. -If it is included in `nixpkgs`, you may be able to find the package you need by looking at the `*.nix` sources. - -### What to do if you can't build with `mason.nvim`. - -If it is provided by `nixpkgs`, you should be able to use it by adding the following settings. - -https://github.com/ayamir/nvimdots/blob/6de8afe0fc4a6e53a9d64a013327d5482b6dbe99/lua/modules/configs/completion/lsp.lua#L143-L148 - -## Usage for `home-manager` on non-NixOS - -Unlike on NixOS, build tools and dependencies should be provided by the package manager provided by the distribution. -Of course, you can let `nix` resolve dependencies as they do for NixOS, but that can be a problem if you run the build command from within `neovim`. -Add the following to your `flake.nix` and `nvimdots.nix`. -Relogin to shell after `home-manager switch --flake `. - -- `flake.nix` - - ```nix - { - inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; - inputs.nvimdots.url = "github:ayamir/nvimdots"; - inputs.home-manager = { - url = "github:nix-community/home-manager"; - inputs.nixpkgs.follows = "nixpkgs"; - }; - homeConfigurations = { - use-nvimdots = inputs.home-manager.lib.homeManagerConfiguration { - inherit (inputs) nixpkgs; - modules = [ - inputs.nvimdots.nixosModules.nvimdots - (import ./nvimdots.nix) - ]; - extraSpecialArgs = { inherit inputs; }; - }; - }; - } - ``` +```nix +{ + # Other contents... + programs.nix-ld.enable = true; +} +``` - `nvimdots.nix` + - `setBuildEnv`: If set, automatically configures your `$CPATH`, `$CPLUG_INCLUDE_PATH`, `$LD_LIBLARY_PATH`, `$LIBRARY_PATH`, `$NIX_LD_LIBRARY_PATH`, and `$PKG_CONFIG_PATH`. + - `withBuildTools`: If set, automatically installs some build utils such as `gcc` and `pkg-config`. + - **Caveats:** + - These are required tooling so that `mason.nvim` and `nvim-treesitter` can work as expected. + - They bundle with `neovim` and won't affect other sessions. - ```nix - { - programs.neovim.nvimdots = { - enable = true; - # Comment out if resolving dependencies on `nix`. - # setBuildEnv = true; - # withBuildTools = true; - }; - } - ``` - -## Module Options - -Please see https://github.com/misumisumi/nvimdots/blob/36d0b3d920f6e4e5397646ddb522f8c8aa43af93/nixos/neovim/default.nix#L11C1-L135C5 - -

-

+```nix +{

-# NixOS and home-manager +## Common Q&A

-This repository contains the nixosModule for home-manager provided by flakes. -You can use it right away if you are using home-manager on NixOS as well as non-NixOS.

-## Usage for NixOS.

-Add the following to your flake.nix, configuration.nix and nvimdots.nix. -Relogin to shell after nixos-rebuild switch --flake <flake-url>.

-- flake.nix

-- configuration.nix +This is because some dependencies are not distributed along with the system - NixOS does not conform to the Filesystem Hierarchy Standard (FHS), so some ingenuity is required.

-- nvimdots.nix +### How to check for the list of required dependencies

-### How to check for required dependencies. +```console +libamd <==> https://github.com/zship/libamd +libc <==> https://www.gnu.org/software/libc/

-For binaries, patchelf --print-needed <binary> will list the required packages. -You can also check the library link status with ldd <binary>. -You can check the dependencies required at build time from the build log from the UI of mason.nvim opened with :Mason. -If it is included in nixpkgs, you may be able to find the package you need by looking at the *.nix sources. +### What to do if you can't build a package via mason.nvim

-### What to do if you can't build with mason.nvim. +If it is provided by nixpkgs, you should be able to use it by adding the following settings. This is the same as setting up other packages that require external installation:

-If it is provided by nixpkgs, you should be able to use it by adding the following settings. +``lua +-- Setup lsps that are not supported bymason.nvimbut supported bynvim-lspconfig` here. +if vim.fn.executable("dart") == 1 then

-https://github.com/ayamir/nvimdots/blob/6de8afe0fc4a6e53a9d64a013327d5482b6dbe99/lua/modules/configs/completion/lsp.lua#L143-L148 +## Using home-manager on operating systems other than NixOS

-## Usage for home-manager on non-NixOS +Unlike NixOS, the package manager that ships with your distribution should have provided those necessary build tools and dependencies. Of course, you may instruct nix to resolve those dependencies as they do for NixOS as well, but that can be a problem if you run the build command from within neovim.

-Unlike on NixOS, build tools and dependencies should be provided by the package manager provided by the distribution. -Of course, you can let nix resolve dependencies as they do for NixOS, but that can be a problem if you run the build command from within neovim. -Add the following to your flake.nix and nvimdots.nix. -Relogin to shell after home-manager switch --flake <flake-url>. +To fix this, add the following snippets to your flake.nix, configuration.nix and nvimdots.nix. +Re-login to your shell after executing nixos-rebuild switch --flake <flake-url>.

-## Module Options +## Customize your experience

-Please see https://github.com/misumisumi/nvimdots/blob/36d0b3d920f6e4e5397646ddb522f8c8aa43af93/nixos/neovim/default.nix#L11C1-L135C5 +Have a look at default.nix (selection) for more information.


</details>

---

# NixOS Support (via home-manager)

This repository contains the `nixosModule` for home-manager using [flakes](https://nixos.wiki/wiki/Flakes). You may use this config right away as long as you are using [home-manager](https://github.com/nix-community/home-manager) to manage your environment.

## Prerequisites

Add the following snippets to your `flake.nix`, `configuration.nix` and `nvimdots.nix`.
Re-login to your shell after executing `nixos-rebuild switch --flake <flake-url>`.

- `flake.nix`

```nix
{
  inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
  inputs.nvimdots.url = "github:ayamir/nvimdots";
  inputs.home-manager = {
    url = "github:nix-community/home-manager";
    inputs.nixpkgs.follows = "nixpkgs";
  };
  nixosConfigurations = {
    use-nvimdots = inputs.nixpkgs.lib.nixosSystem {
      system = "x86_64-linux";
      modules = [ # Other contents...
        inputs.home-manager.nixosModules.home-manager
        {
          home-manager.users."example-user" = {
            imports =
              [ inputs.nvimdots.nixosModules.nvimdots (import ./nvimdots.nix) ];
          };
          home-manager.extraSpecialArgs = { inherit inputs; };
        }
        ./configuration.nix
      ];
      specialArgs = { inherit inputs; };
    };
  };
}
{
  # Other contents...
  programs.nix-ld.enable = true;
}
{
  programs.neovim.nvimdots = {
    enable = true;
    setBuildEnv = true;
    withBuildTools = true;
  };
}

Common Q&A

mason.nvim cannot build some of the packages or execute those installed binaries

This is because some dependencies are not distributed along with the system - NixOS does not conform to the Filesystem Hierarchy Standard (FHS), so some ingenuity is required.

This nixosModules provides several options to simplify dependency resolution. Nevertheless, you may still use programs.neovim.extraPackages, programs.neovim.extraPython3Packages, programs.neovim.extraLuaPackages provided by home-manager.

{pkgs, ...}:
{
  programs.neovim.nvimdots = {
    enable = true;
    setBuildEnv = true;
    withBuildTools = true;
    extraRPackages = rPkgs: []; # configure packages for `R` (nixpkgs.rPackages).
    extraHaskellPackages = hsPkgs: []; # cofigure packages for haskell (nixpkgs.haskellPackages).
    extraDependentPackages = with pkgs; [] # properly setup directory hierarchy (`lib`, `include`, and `pkgconfig`).
  }
}

How to check for the list of required dependencies

libamd     <==> https://github.com/zship/libamd
libc       <==> https://www.gnu.org/software/libc/
  [OR] libc++ <==> https://libcxx.llvm.org/
libevent   <==> https://libevent.org/
libiconv   <==> https://www.gnu.org/software/libiconv/
libmsgpack <==> http://msgpack.org/
libz       <==> https://www.zlib.net/
libzstd    <==> https://github.com/facebook/zstd

What to do if you can't build a package via mason.nvim

If it is provided by nixpkgs, you should be able to use it by adding the following settings. This is the same as setting up other packages that require external installation:

-- Setup lsps that are not supported by `mason.nvim` but supported by `nvim-lspconfig` here.
if vim.fn.executable("dart") == 1 then
    local _opts = require("completion.servers.dartls")
    local final_opts = vim.tbl_deep_extend("keep", _opts, opts)
    nvim_lsp.dartls.setup(final_opts)
end

Using home-manager on operating systems other than NixOS

Unlike NixOS, the package manager that ships with your distribution should have provided those necessary build tools and dependencies. Of course, you may instruct nix to resolve those dependencies as they do for NixOS as well, but that can be a problem if you run the build command from within neovim.

To fix this, add the following snippets to your flake.nix, configuration.nix and nvimdots.nix. Re-login to your shell after executing nixos-rebuild switch --flake <flake-url>.

{
  inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
  inputs.nvimdots.url = "github:ayamir/nvimdots";
  inputs.home-manager = {
    url = "github:nix-community/home-manager";
    inputs.nixpkgs.follows = "nixpkgs";
  };
  homeConfigurations = {
    use-nvimdots = inputs.home-manager.lib.homeManagerConfiguration {
      inherit (inputs) nixpkgs;
      modules =
        [ inputs.nvimdots.nixosModules.nvimdots (import ./nvimdots.nix) ];
      extraSpecialArgs = { inherit inputs; };
    };
  };
}
{
  programs.neovim.nvimdots = {
    enable = true;
    # Comment out the following two lines if you're resolving dependencies via `nix`.
    # setBuildEnv = true;
    # withBuildTools = true;
  };
}

Customize your experience

Have a look at default.nix (selection) for more information.

vollowx commented 1 year ago
  1. use-nvimdots may give a wrong impression to new Nix users, change it to "username@hostname", as this is Home Manager configurations.

  2. All the homeConfigurations are not inside outputs (they should be so as usual, IMO).

  3. Maybe we don't need to provide such a rich configuration example as this may make user more confused, the Nix configurations are changeable and flexible, there are many ways to achieve the same result, but the core is the same. Just write 'You have to install Home Manager first, then add these to flake.nix'

    {
    # ...
    inputs = {
    # ...
    nvimdots.url = "github:ayamir/nvimdots";
    # ...
    };
    # ...
    }

    and something others separately.

ayamir commented 1 year ago

Argee the first point as @vollowx said, but others LGTM.

misumisumi commented 1 year ago

Sorry for the late reply. @Jint-lzxy Thank you for the correction.

@vollowx Explanation I may have been a little overprotective. I forgot outputs.

Maybe we don't need to provide such a rich configuration example as this may make user more confused,..

Delete the section Using home-manager on operating systems other than NixOS, change flake.nix in NixOS Support (via home-manager) as you suggested and add a little explanation. The Q&A should be fine as is.

I forgot to mention the dotnet module, so I will add it.

Raw markdown code (NixOS Support)
````markdown # NixOS Support (via home-manager) This repository contains the `nixosModule` for [home-manager](https://github.com/nix-community/home-manager) using [flakes](https://nixos.wiki/wiki/Flakes). Whether NixOS or Non-NixOS, you can use this configuration out of the box, as long as you use home-manager to manage your environment. ## Prerequisites Add URL `home-manager` and `nvimdots` to `inputs` in your `flake.nix`. Next, add the following snippets to your `configuration.nix` and `nvimdots.nix`. Re-login to your shell after executing `nixos-rebuild switch --flake ` or `home-manager switch --flake `. - `flake.nix` ```nix { inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; nvimdots.url = "github:ayamir/nvimdots"; home-manager = { url = "github:nix-community/home-manager"; nixpkgs.follows = "nixpkgs"; }; ... }; ... } ``` - `configuration.nix` - This is only required on NixOS. [Q&A for this details](#mason.nvim-cannot-build-some-of-the-packages-or-execute-those-installed-binaries) ```nix { # Other contents... programs.nix-ld.enable = true; ... } ``` - `nvimdots.nix` - `setBuildEnv`: If set, automatically configures your `$CPATH`, `$CPLUG_INCLUDE_PATH`, `$LD_LIBLARY_PATH`, `$LIBRARY_PATH`, `$NIX_LD_LIBRARY_PATH`, and `$PKG_CONFIG_PATH`. - `withBuildTools`: If set, automatically installs some build utils such as `gcc` and `pkg-config`. - **Caveats:** - `setBuildEnv` and `withBuildTools` is only required on NixOS. [Q&A for this details](#mason.nvim-cannot-build-some-of-the-packages-or-execute-those-installed-binaries) - These are required tooling so that `mason.nvim` and `nvim-treesitter` can work as expected. - They bundle with `neovim` and won't affect other sessions. ```nix { programs.neovim.nvimdots = { enable = true; setBuildEnv = true; # Only need for NixOS withBuildTools = true; # Only need for NixOS }; } ``` ````
Raw markdown code (dotnet)
````markdown This repository provides `programs.dotnet.dev` to manage `dotnet` installation and environment variables inspired by `programs.java` in `home-manager`. See [dotnet/default.nix](https://github.com/misumisumi/nvimdots/blob/nixos-support-using-mason/nixos/dotnet/default.nix) for options. ```nix programs.dotnet.dev = { enabled = true; environmentVariables = { DOTNET_SYSTEM_GLOBALIZATION_INVARIANT = "0"; # set environmetn variable for DotNET. }; } ``` ````

NixOS Support (via home-manager)

This repository contains the nixosModule for home-manager using flakes. Whether NixOS or Non-NixOS, you can use this configuration out of the box, as long as you use home-manager to manage your environment.

Prerequisites

Add URL home-manager and nvimdots to inputs in your flake.nix. Next, add the following snippets to your configuration.nix and nvimdots.nix. Re-login to your shell after executing nixos-rebuild switch --flake <flake-url> or home-manager switch --flake <flake-url>.

{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
    nvimdots.url = "github:ayamir/nvimdots";
    home-manager = {
      url = "github:nix-community/home-manager";
      nixpkgs.follows = "nixpkgs";
    };
    ...
  };
  ...
}
{
  # Other contents...
  programs.nix-ld.enable = true;
  ...
}
{
  programs.neovim.nvimdots = {
    enable = true;
    setBuildEnv = true;  # Only need for NixOS
    withBuildTools = true; # Only need for NixOS
  };
}

dotnet installation and environment variables

This repository provides programs.dotnet.dev to manage dotnet installation and environment variables inspired by programs.java in home-manager. See dotnet/default.nix for options.

programs.dotnet.dev = {
  enabled = true;
  environmentVariables = {
    DOTNET_SYSTEM_GLOBALIZATION_INVARIANT = "0";  # set environmetn variable for DotNET.
  };
}
vollowx commented 1 year ago

Thanks for all your effort, that's much better.

I still have a idea in my mind, maybe we can have a h3 section "If you are new to Nix", and we can give a more detailed example configuration, links of related stuffs' documents and some dotfiles using this, for the purpose of letting them know the structure. (Real dotfiles are better than pure document for new people to realize).

misumisumi commented 1 year ago

Real dotfiles are better than pure document for new people to realize

Totally agree. It is difficult to understand intuitively with only documentation. IMO, flake.nix can contain a bare-bones home-manager configuration to get nvimdots working. It might be a bit of a departure from the point of view of providing nvimdots, though.

vollowx commented 1 year ago

Yes, I mean, some links to somebody who is using the flakes. Or a whole example.nix. As for myself (also as a new one to Nix), the first thing I do is to find a usable and nice structure to put and manager the configurations, which spent me weeks, and in this time my mind is in a mind-storm :joy_cat:

So we can look this as a ref, it's pretty clear.

misumisumi commented 1 year ago

Starting with this review, language support has been limited to Haskell. So I added an explanation on how to add dependencies to the Q&A.

Raw markdown code
````markdown ### `mason.nvim` cannot build some of the packages or execute those installed binaries This is because some dependencies are not distributed along with the system - NixOS does not conform to the [Filesystem Hierarchy Standard (FHS)](https://en.wikipedia.org/wiki/Filesystem_Hierarchy_Standard), so some ingenuity is required. This `nixosModules` provides several options to simplify dependency resolution. Nevertheless, you may still use `programs.neovim.extraPackages`, `programs.neovim.extraPython3Packages`, `programs.neovim.extraLuaPackages` provided by home-manager. - `nvimdots.nix` ```nix {pkgs, ...}: { programs.neovim.nvimdots = { enable = true; setBuildEnv = true; withBuildTools = true; withHaskell = true; # if use Haskell. extraHaskellPackages = hsPkgs: []; # cofigure packages for haskell (nixpkgs.haskellPackages). extraDependentPackages = with pkgs; [] # properly setup directory hierarchy (`lib`, `include`, and `pkgconfig`). } } ``` ### How do you add dependencies? You include the necessary packages for building, including `include`, `lib`, and `pkgconfig` requirements, in the `programs.neovim.extraDependentPackages`. Such as the runtime dependencies, you add package to `home.packages` or `programs.neovim.extraPackages`. `home.packages` is user scope and `programs.neovim.extraPackages` is neovim scope. Some languages may use wrapper. ```nix { pkgs, ... }: { # Install to user env. home.packages = with pkgs; [ go ]; programs.neovim = { # Packages are only accessed from neovim nvimdots = { # Packages that require `include`, `lib`, `pkgconfig` extraDependentPackages = with pkgs; [ icu ]; # Haskell packages can be easily installed with `nvimdots` options. extraHaskellPackages = hs: with hs; [ ghcup ]; }; extraPackages = with pkgs; [ go # Some languages require the use of wrapper. rWrapper.override { packages = with pkgs.rPackages; [ xml2 lintr roxygen2 ]; } ]; # Python and Lua packages can be easily installed with `home-manager` options. extraPython3Packages = ps: with ps; [ numpy ]; }; } ``` ### Required packages for building `mason.nvim` package of each languages (as of 2023/08/13) Not all `mason.nvim` packages are researched and tracked. These are in flux. | Language | extraPackages | extraDependentPackages | | -------- | -------------------------------------------------------------------------------- | ---------------------- | | Go | - | `hunspell` | | PHP | `php phpPackages.composer` | - | | R | `rWrapper.override { packages = with pkgs.rPackages; [ xml2 lintr roxygen2 ]; }` | - | | Vala | `meson` `vala` | `vala` `jsonrpc-glib` | ````

mason.nvim cannot build some of the packages or execute those installed binaries

This is because some dependencies are not distributed along with the system - NixOS does not conform to the Filesystem Hierarchy Standard (FHS), so some ingenuity is required.

This nixosModules provides several options to simplify dependency resolution. Nevertheless, you may still use programs.neovim.extraPackages, programs.neovim.extraPython3Packages, programs.neovim.extraLuaPackages provided by home-manager.

{pkgs, ...}:
{
  programs.neovim.nvimdots = {
    enable = true;
    setBuildEnv = true;
    withBuildTools = true;
    withHaskell = true; # if use Haskell.
    extraHaskellPackages = hsPkgs: []; # cofigure packages for haskell (nixpkgs.haskellPackages).
    extraDependentPackages = with pkgs; [] # properly setup directory hierarchy (`lib`, `include`, and `pkgconfig`).
  }
}

How do you add dependencies?

You include the necessary packages for building, including include, lib, and pkgconfig requirements, in the programs.neovim.extraDependentPackages. Such as the runtime dependencies, you add package to home.packages or programs.neovim.extraPackages. home.packages is user scope and programs.neovim.extraPackages is neovim scope. Some languages may use wrapper.

{ pkgs, ... }:
{
  # Install to user env.
  home.packages = with pkgs; [
    go
  ];
  programs.neovim = {
    # Packages are only accessed from neovim
    nvimdots = {
      # Packages that require `include`, `lib`, `pkgconfig`
      extraDependentPackages = with pkgs; [ icu ];
      # Haskell packages can be easily installed with `nvimdots` options.
      extraHaskellPackages = hs: with hs; [ ghcup ];
    };
    extraPackages = with pkgs; [
      go

      # Some languages require the use of wrapper.
      rWrapper.override
      {
        packages = with pkgs.rPackages;
          [ xml2 lintr roxygen2 ];
      }
    ];
    # Python and Lua packages can be easily installed with `home-manager` options.
    extraPython3Packages = ps: with ps; [
      numpy
    ];
  };
}

Required packages for building mason.nvim package of each languages (as of 2023/08/13)

Not all mason.nvim packages are researched and tracked. These are in flux.

Language extraPackages extraDependentPackages
Go - hunspell
PHP php phpPackages.composer -
R rWrapper.override { packages = with pkgs.rPackages; [ xml2 lintr roxygen2 ]; } -
Vala meson vala vala jsonrpc-glib