nix-community / nixvim

Configure Neovim with Nix! [maintainer=@GaetanLepage, @traxys, @mattsturgeon]
https://nix-community.github.io/nixvim
MIT License
1.39k stars 209 forks source link

modules/misc: nixpkgs module #1784

Open MattSturgeon opened 1 week ago

MattSturgeon commented 1 week ago

NixOS^1, home-manager^2 and nix-darwin^3 all have a nixpkkgs module where the pkgs passed to modules can be configured or overridden.

This is mainly used for cross-compiliation (by setting hostPlatform and buildPlatform) and also for adding overlays.

Currently this is not possible in standalone nixvim builds, instead pkgs must be configured before passing it to makeNixvimWithModule.

Adding this would also make it easier to add extensions to pkgs.lib via an overlay, such as merging our maintainers into lib.maintainers or making nixvim's helper lib available as (e.g.) lib.nixvim.\ EDIT: we can still do this, but it has to be done as a specialArg because lib is passed in by lib.evalModules.

MattSturgeon commented 4 days ago

Originally commented on https://github.com/nix-community/nixvim/pull/1800#issuecomment-2205696343

Looks like the way home-manager handles the "default" pkgs is to set the pkgsPath special arg, and use that to construct pkgs: defaultPkgs = import pkgsPath config.nixpkgs.

Meaning they use a fresh instance, with its own config/overlays, but matching the same locked channel.

Unless these nixos module options are used:

home-manager.useGlobalPkgs

Whether to enable using the system configuration’s pkgs argument in Home Manager. This disables the Home Manager options nixpkgs.*.

home-manager.useUserPackages

Whether to enable installation of user packages through the users.users.<name>.packages option.

I believe when home-manager is used standalone, it sets pkgsPath to <nixpkgs> when not using flakes or home-manager's inputs.nixpkgs otherwise.

It might do the same thing when it's a NixOS module, or it might use pkgs.path (I'm not sure).