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/nixpkgs: complete the MVP #2738

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

MattSturgeon
Copy link
Member

@MattSturgeon MattSturgeon commented Dec 23, 2024

  • modules/nixpkgs: add config option
  • modules/nixpkgs: add hostPlatform & buildPlatform options
  • modules/nixpkgs: construct an instance of nixpkgs.source
  • modules/nixpkgs: add useGlobalPackages option
  • lib/modules: allow specifying system as an evalNixvim arg
  • wrappers/standalone: make pkgs arg optional, allow specifying system

This PR finally gets the nixpkgs module to a fully functional state. If nixpkgs.pkgs is not defined, then an instance of nixpkgs is constructed from nixpkgs.source.

Constructing nixpkgs also requires knowing which system to target, so the hostPlatform and buildPlatform options are included.

I also included the nixpkgs.config option. This could just be attrsOf anything, but the upstream otpion-type is a bit more complex because it allows definitions to be either attrs or functions-to-attrs.

Directly based on https://github.com/NixOS/nixpkgs/blob/master/nixos/modules/misc/nixpkgs.nix

Follow up to #2670, #2430, and #2301

Closes #2022
Closes #2437
Fixes #1784

Marking as a draft for now, still need to:

  • add some test cases
  • proof-read all nixpkgs.* option docs, new & existing

Future work

This will allow us to have a non-per-system replacement for makeNixvimWithModule and somewhat simplify the standalone template

In the future we will also be able to change the default value of nixpkgs.useGlobalPackages. I'm not 100% sure I know a good way to warn about that planned transition though.

There's also a bunch of assertions in the upstream module that I have not ported over yet.

@MattSturgeon MattSturgeon marked this pull request as ready for review December 23, 2024 16:19
@MattSturgeon MattSturgeon requested a review from a team December 23, 2024 16:39
@MattSturgeon MattSturgeon force-pushed the nixpkgs_complete branch 4 times, most recently from e32c022 to 737ff93 Compare December 23, 2024 17:16
@MattSturgeon MattSturgeon requested a review from a team December 23, 2024 17:37
Comment on lines +43 to +44
# FIXME: what priority should this have?
# If the user has set it as an evalNixvim arg _and_ a module option what behaviour would they expect?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the implemented behaviour is the correct one, as the module options seems the best place to implement dynamic behaviour, whereas evalNixvim would likely be quite static. In that sense I would say that the more dynamic way should override the more static one if that makes sens

@@ -30,7 +29,8 @@ let
mkTestDerivationFromNixvimModule =
{
name ? null,
pkgs ? defaultPkgs,
pkgs ? null,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do we keep the pkgs argument? For backwards compatibility? You should be able to do the same thing by setting nixpkgs.pkgs right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, for backwards compatibility. I've tried to make this a non-breaking change.

IMO rather than deprecating specific args, it makes more sense to deprecate all functions in lib/tests.nix and wrappers/standalone.nix. That way they can be replaced by functions that have no baggage, do not need to be per-system in the flake output, and can more closely wrap the underlying evalNixvim.

I'm not ready to do that in this PR, and it's already large enough as it is. Before deprecating the per-system functions, I think we should move the "standalone package" into the module configuration; modules/top-level/output.nix.

Comment on lines -50 to -51
# TODO: Only do this when `args?pkgs`
# Consider deprecating the `pkgs` arg too...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's a good idea to deprecate that :D

nixpkgs = {
# Use global packages by default in nixvim's submodule
# FIXME: probably doesn't need to be mkForce
# What should happen if the user configures both `nixpkgs.pkgs` and `nixpkgs.useGlobalPackages` ?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that we should either raise a warning and ignore one of them (I don't know which ...) or raise an error

Comment on lines -24 to -26
> [!CAUTION]
> This default will be removed in a future version of nixvim
'';
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably move this admonition to the useGlobalPackages option.

Comment on lines +31 to +33
nixpkgs.config = {
allowUnfree = true;
};
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In a future PR, this should be moved to whichever tests actually require it.

Comment on lines +78 to +79
# Test that a nixpkgs revision can be specified using `nixpkgs.source`
source =
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's also test that config has an effect

Comment on lines +13 to +15

> [!TIP]
> The host configuration is usually home-manager, nixos, or nix-darwin.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of a generic "tip", this could actually use a context option to dynamically produce platform-specific docs. This is possible because we actually show the per-platform options separately.

Probably out of scope for this PR though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

modules/misc: nixpkgs module
3 participants