nixvim icon indicating copy to clipboard operation
nixvim copied to clipboard

modules/misc: nixpkgs module

Open MattSturgeon opened this issue 1 year ago • 6 comments
trafficstars

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 can be used to specify a specific lock or channel, and it can be used to define overlays and config such as enableUnfree. Configuring pkgs is also useful for cross-compiliation (by setting hostPlatform and buildPlatform).

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

This would also make it possible to have nixvim's pkgs be different to that used by the host modules; currently many users are forced to use the standalone build just to use a different nixpkgs channel to their NixOS/home-manager configs.

~~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: done in #1963, but it has to be done as a specialArg because lib is passed in by lib.evalModules.

MattSturgeon avatar Jun 30 '24 20:06 MattSturgeon

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).

MattSturgeon avatar Jul 03 '24 12:07 MattSturgeon

I think this is the reason why it won't build successfully for me in my configuration tied to nix-darwin, nixos, home-manager. Everytime I try to build it complains. Even when I remove everything from my nixvim config, it complains about something I haven't touched and have no control over. currently, it complains over nvim-cmp-ai

aspauldingcode avatar Oct 03 '24 16:10 aspauldingcode

Everytime I try to build it complains. Even when I remove everything from my nixvim config, it complains about something I haven't touched and have no control over. currently, it complains over nvim-cmp-ai

It's hard to know exactly what you're saying without seeing the error messages you're referencing, but if you're saying that you've been having mismatched nixpkgs issues on your nix-darwin + nixvim setup I have some good news:

The initial stages of this feature were recently merged, you can now define programs.nixvim.nixpkgs.pkgs and assign a compatible pkgs instance from the nixos-unstable channel.

In the future we'd like to have more options for constructing a pkgs instance internally, and perhaps even defaulting to the channel lock from our flake inputs instead of our current behaviour of defaulting to the pkgs argument from the host module configuration.

MattSturgeon avatar Oct 03 '24 16:10 MattSturgeon

The initial stages of this feature were recently merged, you can now define programs.nixvim.nixpkgs.pkgs and assign a compatible pkgs instance from the nixos-unstable channel.

Wait so does that mean I can specify:

inputs.nixvim = {
      url = "github:nix-community/nixvim";
      inputs.nixpkgs.follows = "nixpkgs"; # Use the stable channel for nixvim
};

now?

aspauldingcode avatar Oct 03 '24 17:10 aspauldingcode

No, that can't be supported as we rely on packages present in unstable nixpkgs on our master. You still need to use nixvim's stable branch if you want to use a stable nixpkgs. This change mostly allows to use an unstable nixpkgs for nixvim on a stable system, or a stable nixpkgs on an unstable system, but the pkgs used must match nixvim's branch

traxys avatar Oct 03 '24 18:10 traxys

The initial stages of this feature were recently merged, you can now define programs.nixvim.nixpkgs.pkgs and assign a compatible pkgs instance from the nixos-unstable channel.

Awesome.

Nixvim now builds with my stable system, using unstable packages for nixvim. 👏👏

aspauldingcode avatar Oct 03 '24 19:10 aspauldingcode

FYI

For anyone wanting to use an unstable nixvim on a stable system, you can now set the following instead of explicitly supplying a compatible programs.nixvim.nixpkgs.pkgs.

programs.nixvim.nixpkgs.useGlobalPackages = false

(docs)

In the future this will be the default, so that mismatched installs work out-of-the-box (see #2839). We haven't made it the default yet because that's technically a breaking change.

MattSturgeon avatar Jan 17 '25 10:01 MattSturgeon