Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modules/misc: nixpkgs module #1784

Open
MattSturgeon opened this issue Jun 30, 2024 · 6 comments · May be fixed by #2022
Open

modules/misc: nixpkgs module #1784

MattSturgeon opened this issue Jun 30, 2024 · 6 comments · May be fixed by #2022
Assignees
Labels
enhancement New feature or request tech debt Related to technical debt and/or refactoring

Comments

@MattSturgeon
Copy link
Member

MattSturgeon commented Jun 30, 2024

NixOS1, home-manager2 and nix-darwin3 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.

Footnotes

  1. https://github.com/NixOS/nixpkgs/blob/master/nixos/modules/misc/nixpkgs.nix

  2. https://github.com/nix-community/home-manager/blob/master/modules/misc/nixpkgs.nix

  3. https://github.com/LnL7/nix-darwin/blob/master/modules/nix/nixpkgs.nix

@MattSturgeon
Copy link
Member Author

Originally commented on #1800 (comment)

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 MattSturgeon changed the title standalone: nixpkgs module modules/misc: nixpkgs module Jul 4, 2024
@MattSturgeon MattSturgeon added the enhancement New feature or request label Aug 11, 2024
@MattSturgeon MattSturgeon self-assigned this Aug 11, 2024
@MattSturgeon MattSturgeon added the tech debt Related to technical debt and/or refactoring label Sep 14, 2024
@MattSturgeon MattSturgeon linked a pull request Sep 14, 2024 that will close this issue
11 tasks
@aspauldingcode
Copy link

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

@MattSturgeon
Copy link
Member Author

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.

@aspauldingcode
Copy link

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?

@traxys
Copy link
Member

traxys commented Oct 3, 2024

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

@aspauldingcode
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request tech debt Related to technical debt and/or refactoring
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants