Skip to content

nixos/nixpkgs.config: make use of the module defined in config.nix#489889

Open
jopejoe1 wants to merge 3 commits intoNixOS:masterfrom
jopejoe1:nixpkgs-config
Open

nixos/nixpkgs.config: make use of the module defined in config.nix#489889
jopejoe1 wants to merge 3 commits intoNixOS:masterfrom
jopejoe1:nixpkgs-config

Conversation

@jopejoe1
Copy link
Member

@jopejoe1 jopejoe1 commented Feb 12, 2026

This makes it so that the nixpkgs.config options can be merged with the module system

It also makes the defined options show up in search and the manual.

closes #368051
closes #468647
closes #356739
closes #330627

Things done

  • Built on platform:
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • Tested, as applicable:
  • Ran nixpkgs-review on this PR. See nixpkgs-review usage.
  • Tested basic functionality of all binary files, usually in ./result/bin/.
  • Nixpkgs Release Notes
    • Package update: when the change is major or breaking.
  • NixOS Release Notes
    • Module addition: when adding a new NixOS module.
    • Module update: when the change is significant.
  • Fits CONTRIBUTING.md, pkgs/README.md, maintainers/README.md and other READMEs.

These are handled in the NixOS modules for `nixpkgs.config` as special merges; add them here.
@jopejoe1 jopejoe1 marked this pull request as draft February 12, 2026 19:22
Makes it possible to render it in the NixOS manual,
as that one does not contain the Nixpkgs manual specific ones.
This makes it so that the `nixpkgs.config` options can be merged with the module system

It also makes the defined options show up in search and the manual.
@nixpkgs-ci nixpkgs-ci bot added 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-darwin: 1 This PR causes 1 package to rebuild on Darwin. 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: module (update) This PR changes an existing module in `nixos/` labels Feb 12, 2026
@jopejoe1 jopejoe1 marked this pull request as ready for review February 12, 2026 20:31
@nixpkgs-ci nixpkgs-ci bot added the 9.needs: reviewer This PR currently has no reviewers requested and needs attention. label Feb 12, 2026
@nixpkgs-ci nixpkgs-ci bot removed the 9.needs: reviewer This PR currently has no reviewers requested and needs attention. label Feb 12, 2026
}@args:

let
docPrefix = args.docPrefix or "";
Copy link
Member Author

Choose a reason for hiding this comment

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

Not happy about all the docPrefix, but it works if someone has a better idea please let me know.

Copy link
Member

Choose a reason for hiding this comment

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

You can't do . or or ? on module arguments directly, because they're generated from the individual module's functionArgs. (otherwise a { ... }: function is by definition strict, ie not lazy like it needs to be)
This should work though:

Suggested change
docPrefix = args.docPrefix or "";
docPrefix = config._module.args.docPrefix or "";

@wolfgangwalther
Copy link
Contributor

Love the direction of this PR; I just hit the inability to merge nixpkgs config entries earlier this weeks. Won't have time to review this, though.

@wolfgangwalther wolfgangwalther removed their request for review February 13, 2026 13:20
@dwt dwt self-requested a review February 14, 2026 08:38
@dwt
Copy link
Contributor

dwt commented Feb 14, 2026

This is super interesting. I briefly tried this and didn't get very far with my last pull request touching this area. My work did include some tests because I didn't particularly trust myself with the intricacies of this code. Did they happen to survive this change intact? (I'll look into this later, but quite busy, so no definite timescale given)

@dwt
Copy link
Contributor

dwt commented Feb 14, 2026

As far as I can tell my tests still work.

This brings me to the next question: Do you have any idea why this was not done in the first place? I always assumed that this might have something to do with importing multiple nixpkgs versions, but sharing the config object between them, and that for that reason it needed to be dumb and not part of the module system.

But I did not find any documentation or comments that clarified this.

@jopejoe1
Copy link
Member Author

As far as I can tell, the nixpkgs.config was added before config was made into a module, so I think no one came around to ever changing it to make use of this module. Maybe someone like @roberth who has more insight into the module system, would know.

@dwt dwt requested a review from roberth February 17, 2026 17:22
@jopejoe1 jopejoe1 requested a review from philiptaron February 19, 2026 13:47
@SuperSandro2000
Copy link
Member

noice! Looking forward to this being merged!

Copy link
Contributor

@philiptaron philiptaron left a comment

Choose a reason for hiding this comment

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

Diff looks good to me; every time we have tried to add an option in this way, we've had to do a tree wide to find every user of it and adapt them from the or null pattern. I do expect that because this allows setting the default, there's going to be a set of places that need updating in that way. The second thing that's been run into with similar PRs is that there are many doors into Nixpkgs, and not everyone has this logic.

@nixpkgs-ci nixpkgs-ci bot added the 12.approvals: 1 This PR was reviewed and approved by one person. label Feb 21, 2026
@dwt
Copy link
Contributor

dwt commented Feb 22, 2026

Diff looks good to me; every time we have tried to add an option in this way, we've had to do a tree wide to find every user of it and adapt them from the or null pattern. I do expect that because this allows setting the default, there's going to be a set of places that need updating in that way. The second thing that's been run into with similar PRs is that there are many doors into Nixpkgs, and not everyone has this logic.

Do you have any links / examples for this, so we can understand how this breaks or would break existing configurations?

@philiptaron
Copy link
Contributor

I'm on mobile so search is hard. I think this is my last comment on the matter.

#479234 (comment)

@jopejoe1
Copy link
Member Author

jopejoe1 commented Feb 22, 2026

The 2 options added here match the previous default values of x: {} used in:

overrides ? config.perlPackageOverrides or (p: { }), # TODO: (self: super: {}) like in python

and

lib.optionalAttrs allowCustomOverrides ((config.packageOverrides or (super: { })) super);

If there are anyother usages of thees options they are missusing this config option.

@dwt
Copy link
Contributor

dwt commented Feb 23, 2026

@philiptaron @jopejoe1: do I get this right that options like nixpkgs.config.perlPackageOverrides or (p: {}) would be affected, and that this should be a non issue, because the default now becomes part of nixpkgs.config?

If that is all I'm inclined to vote merge. I'm not approving this pull request yet, as I really do not feel that I understand the internals of nixpkgs well enough to confidently make that vote. (sorry @jopejoe1)

@philiptaron
Copy link
Contributor

I'm only not merging since I can't monitor for regressions. I think from a conceptual standpoint this is good to go. At worst we will roll it back having learned something and can refer back to it.

Copy link
Contributor

@dwt dwt left a comment

Choose a reason for hiding this comment

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

Approving to see what this will break, as I think this is the right direction to go for nixpkgs

@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/prs-already-reviewed/2617/2824

@nixpkgs-ci nixpkgs-ci bot added 12.approvals: 2 This PR was reviewed and approved by two persons. and removed 12.approvals: 1 This PR was reviewed and approved by one person. labels Feb 23, 2026
Copy link
Member

@roberth roberth left a comment

Choose a reason for hiding this comment

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

This doubles the module evaluation, leading to double the type checking, even in packageOverrides etc calls, as well as those unfree / insecure predicate functions.

I would prefer to let Nixpkgs to the module evaluation, by forwarding the definitions and putting apply = _nativeMergeIgnored: pkgs.config; in the option.
That way we have better a better separation of concerns, and the types are only applied once, which might matter in some corner cases.

The Nixpkgs function doesn't support accepting raw options.config.definitionsWithLocations (or similar) definitions yet.
So that would have to be added. I'd have to look into the exact details; maybe the new mkDefinition is also helpful.

}@args:

let
docPrefix = args.docPrefix or "";
Copy link
Member

Choose a reason for hiding this comment

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

You can't do . or or ? on module arguments directly, because they're generated from the individual module's functionArgs. (otherwise a { ... }: function is by definition strict, ie not lazy like it needs to be)
This should work though:

Suggested change
docPrefix = args.docPrefix or "";
docPrefix = config._module.args.docPrefix or "";

@nixpkgs-ci nixpkgs-ci bot added the 2.status: merge conflict This PR has merge conflicts with the target branch label Feb 24, 2026
@dwt
Copy link
Contributor

dwt commented Feb 26, 2026

@roberth Would you mind explaining a little bit more why this would lead to a double nixpkgs module evaluation? Do you mean of just this module, or of all modules? (Sorry for being the noob in the room)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2.status: merge conflict This PR has merge conflicts with the target branch 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: module (update) This PR changes an existing module in `nixos/` 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-darwin: 1 This PR causes 1 package to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. 12.approvals: 2 This PR was reviewed and approved by two persons.

Projects

None yet

7 participants