Closed misumisumi closed 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.
````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
````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
+```nix +{
-# NixOS and home-manager +## Common Q&A
flake.nix
, configuration.nix
and nvimdots.nix
.
-Relogin to shell after nixos-rebuild switch --flake <flake-url>
.flake.nix
+### `mason.nvim` cannot build some of the packages or execute those installed binaries
-- 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.
{
programs.nix-ld.enable = true;
}
+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`
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.
{
programs.neovim.nvimdots = {
enable = true;
setBuildEnv = true;
withBuildTools = true;
}; +```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
).
}
-### 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.
+}
+```
-- nvimdots.nix
+### How to check for the list of required dependencies
nixpkgs.rPackages
.nixpkgs.haskellPackages
.lib
, include
, and pkgconfig
.
+- For binaries, `patchelf --print-needed <binary>` will list the required packages.
+- You can also check the information used by `ldd` in this package and/or dynamiclib with `ldd <binary>`.
+- 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`:
-### 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 by
mason.nvimbut supported by
nvim-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>
.
flake.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 +{
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
{
programs.neovim.nvimdots = {
enable = true;
nix
.};
}
+```nix
+{
programs.neovim.nvimdots = {
enable = true;
nix
.}; +} +```
-## 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; };
};
};
}
configuration.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
.mason.nvim
and nvim-treesitter
can work as expected.neovim
and won't affect other sessions.{
programs.neovim.nvimdots = {
enable = true;
setBuildEnv = true;
withBuildTools = true;
};
}
mason.nvim
cannot build some of the packages or execute those installed binariesThis 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.
nvimdots.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`).
}
}
patchelf --print-needed <binary>
will list the required packages.ldd
in this package and/or dynamiclib with ldd <binary>
.mason.nvim
's UI).nixpkgs
, you may be able to find the package you need by looking at the *.nix
sources.mason-registry
: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
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
home-manager
on operating systems other than NixOSUnlike 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>
.
flake.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
{
programs.neovim.nvimdots = {
enable = true;
# Comment out the following two lines if you're resolving dependencies via `nix`.
# setBuildEnv = true;
# withBuildTools = true;
};
}
Have a look at default.nix (selection) for more information.
use-nvimdots
may give a wrong impression to new Nix users, change it to "username@hostname"
, as this is Home Manager configurations.
All the homeConfigurations
are not inside outputs
(they should be so as usual, IMO).
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.
Argee the first point as @vollowx said, but others LGTM.
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.
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.
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>
.
flake.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
{
# 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
.setBuildEnv
and withBuildTools
is only required on NixOS. Q&A for this detailsmason.nvim
and nvim-treesitter
can work as expected.neovim
and won't affect other sessions.{
programs.neovim.nvimdots = {
enable = true;
setBuildEnv = true; # Only need for NixOS
withBuildTools = true; # Only need for NixOS
};
}
dotnet
installation and environment variablesThis 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.
};
}
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).
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.
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.
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.
mason.nvim
cannot build some of the packages or execute those installed binariesThis 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.
nvimdots.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`).
}
}
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
];
};
}
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 |
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 ?
mason.nvim
cannot build packages or run installed binariesmason.nvim
.home-manager
on non-NixOSPreview
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 --flakeNixOS 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
andnvimdots.nix
.Relogin to shell after
nixos-rebuild switch --flake <flake-url>
.flake.nix
configuration.nix
nvimdots.nix
setBuildEnv
providesCPATH
,CPLUG_INCLUDE_PATH
,LD_LIBLARY_PATH
,LIBRARY_PATH
,NIX_LD_LIBRARY_PATH
,PKG_CONFIG_PATH
.withBuildTools
provides basic build tools such asgcc
andpkg-config
.These are required for
mason.nvim
andnvim-treesitter
to work properly.Also, they are only provided to
neovim
and do not affect the entire session.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.nvimdots.nix
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-NixOSUnlike 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 withinneovim
.Add the following to your
flake.nix
andnvimdots.nix
. Relogin to shell afterhome-manager switch --flake <flake-url>
.flake.nix
nvimdots.nix
Module Options
Please see https://github.com/misumisumi/nvimdots/blob/36d0b3d920f6e4e5397646ddb522f8c8aa43af93/nixos/neovim/default.nix#L11C1-L135C5
Additional information
No response