Skip to content

nixpkgs: pass lib to config function#457120

Merged
ConnorBaker merged 1 commit intoNixOS:masterfrom
me-and:nixpkgs-config-lib
Jan 6, 2026
Merged

nixpkgs: pass lib to config function#457120
ConnorBaker merged 1 commit intoNixOS:masterfrom
me-and:nixpkgs-config-lib

Conversation

@me-and
Copy link
Member

@me-and me-and commented Oct 30, 2025

Nixpkgs config, for defining things like which licenses are permitted, can either be an attrset or a function that is passed a pkgs argument. Evaluating that pkgs argument requires computing the Nixpkgs fixpoint, which requires checking whether the derivations used in the Nixpkgs bootstrap have valid licenses. This works provided nothing tries to use Nixpkgs functions to validate or merge anything included in the configuration.

f5deefd (config: add and document {allow,block}listedLicenses, 2025-08-31), in #437723, added type checking and merging to the lists of permitted/forbidden licenses. That resulted in a recursion loop if a list of licenses included, say, pkgs.lib.licenses.bsd0.

To allow licenses to be specified from Nixpkgs' library, pass lib as well as pkgs to any config function. Computing lib doesn't require working out the full Nixpkgs fixpoint. The change in #437723 will still break things for some people, but it at least provides a sensible route to getting the config working again.

Fixes #456994.

Things done


Add a 👍 reaction to pull requests you find important.

@me-and
Copy link
Member Author

me-and commented Oct 30, 2025

Tagging @infinisil and @ConnorBaker: this is a completely different -- and somewhat more scary -- fix for #456994 than the one @ConnorBaker proposed in #457038.

I expect this change is likely to break even more folks' configurations, e.g. if they've defined a config function like { pkgs }: ... rather than { pkgs, ... }: ....

@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: changelog This PR adds or changes release notes 8.has: module (update) This PR changes an existing module in `nixos/` 8.has: documentation This PR adds or changes documentation labels Oct 30, 2025
@nix-owners nix-owners bot requested a review from Ericson2314 October 30, 2025 23:30
@nixpkgs-ci nixpkgs-ci bot added the 9.needs: reviewer This PR currently has no reviewers requested and needs attention. label Oct 30, 2025
@me-and me-and force-pushed the nixpkgs-config-lib branch from ad6d64c to 4faedbf Compare October 30, 2025 23:39
@nixpkgs-ci nixpkgs-ci bot removed the 9.needs: reviewer This PR currently has no reviewers requested and needs attention. label Oct 30, 2025
@ConnorBaker
Copy link
Contributor

Evaluating that pkgs argument requires computing the Nixpkgs fixpoint, which requires checking whether the derivations used in the Nixpkgs bootstrap have valid licenses.

Do you know where that happens specifically? I've got a suspicion that the infinite recursion is caused by the fact that attribute sets are strict in their keys and somewhere along the way during bootstrapping the presence or absence of a value depends on something that it shouldn't.

@me-and
Copy link
Member Author

me-and commented Oct 31, 2025

Evaluating that pkgs argument requires computing the Nixpkgs fixpoint, which requires checking whether the derivations used in the Nixpkgs bootstrap have valid licenses.

Do you know where that happens specifically? I've got a suspicion that the infinite recursion is caused by the fact that attribute sets are strict in their keys and somewhere along the way during bootstrapping the presence or absence of a value depends on something that it shouldn't.

I think it's more fundamental and difficult to fix than that :(

Evaluating pkgs starts here:

boot = import ../stdenv/booter.nix { inherit lib allPackages; };
stages = stdenvStages {
inherit
lib
localSystem
crossSystem
config
overlays
crossOverlays
;
};
pkgs = boot stages;

Based on the --show-stack output when I hit the recursion error, the package evaluation that is getting its licensed checked and triggering the infinite recursion is this one – checking binutils from stage1 of the bootstrap at the start of stage2.

assert isBuiltByBootstrapFilesCompiler prevStage.binutils-unwrapped;

I agree evaluating the keys in pkgs is the problem. I imagine having things set up so that we can work out all the names in pkgs without evaluating the bootstrap cycle would be very difficult to achieve, and I think it's correct that we check the licenses when evaluating the bootstrap cycle.

I have the impression the reason NixOS modules get passed lib as well as pkgs is for essentially this same reason: the lib that gets passed is one that doesn't require the Nixpkgs bootstrap being evaluated. And therefore I strongly expect there's no fix here that just skips evaluating something that doesn't need to be evaluated.

@me-and
Copy link
Member Author

me-and commented Oct 31, 2025

nixpkgs-review result

Generated using nixpkgs-review.

Command: nixpkgs-review pr 457120
Commit: 4faedbf5e1a4954e4a995be9c8eda0777912a479


x86_64-linux

⏩ 2 packages blacklisted:
  • nixos-install-tools
  • tests.nixos-functions.nixos-test
✅ 1 package built:
  • nixpkgs-manual

@me-and me-and force-pushed the nixpkgs-config-lib branch from 4faedbf to ea9052a Compare October 31, 2025 10:38
@me-and
Copy link
Member Author

me-and commented Oct 31, 2025

I've just updated the PR to document an alternative configuration change in the release notes that will work with both 25.05 and 25.11, with thanks to @emilazy for prompting me to think about how to make that possible.

ConnorBaker added a commit to ConnorBaker/nixpkgs that referenced this pull request Oct 31, 2025
This reverts commit f5deefd.

See:

- NixOS#437723 (introduced commit)
- NixOS#456994 (reported breakage)
- NixOS#457038 (attempted fix, closed in favor of this revert)
- NixOS#457120 (fix which would require more breaking changes)
@me-and me-and force-pushed the nixpkgs-config-lib branch from ea9052a to 17dd85b Compare November 2, 2025 18:16
@me-and
Copy link
Member Author

me-and commented Nov 2, 2025

I'm going to mark this as a draft for now. I think it's probably a sensible change even now the proximate need for it has been backed out (#457338), but not for 25.11.

@me-and me-and marked this pull request as draft November 2, 2025 18:18
@me-and me-and marked this pull request as ready for review November 26, 2025 09:28
@me-and
Copy link
Member Author

me-and commented Nov 26, 2025

And re-opening now this can be merged into (presumably) master for 26.05.

@me-and me-and force-pushed the nixpkgs-config-lib branch from 17dd85b to 0d9e216 Compare November 26, 2025 09:38
@me-and
Copy link
Member Author

me-and commented Nov 26, 2025

...except now with updated documentation for targeting 26.05.

@me-and
Copy link
Member Author

me-and commented Dec 22, 2025

@ConnorBaker At #456994 (comment) you said you'd like to see this PR merged. I think all the feedback has now been merged, and I'd rather get it in before there can be any merge conflicts. Are you able and willing to press the magic buttons?

Nixpkgs config, for defining things like which licenses are
permitted, can either be an attrset or a function that is passed a
`pkgs` argument.  Evaluating that `pkgs` argument requires computing the
Nixpkgs fixpoint, which requires checking whether the derivations used
in the Nixpkgs bootstrap have valid licenses.  This works provided
nothing tries to use Nixpkgs functions to validate or merge anything
included in the configuration.

f5deefd (config: add and document {allow,block}listedLicenses,
2025-08-31), in NixOS#437723, added type checking and merging to the lists of
permitted/forbidden licenses.  That resulted in a recursion loop if a
list of licenses included, say, `pkgs.lib.licenses.bsd0`.

To allow licenses to be specified from Nixpkgs' library, pass `lib` as
well as `pkgs` to any config function.  Computing `lib` doesn't require
working out the full Nixpkgs fixpoint.  The change in NixOS#437723 will still
break things for some people, but it at least provides a sensible route
to getting the config working again.

Fixes NixOS#456994.
@me-and me-and force-pushed the nixpkgs-config-lib branch from 0d9e216 to 8e94561 Compare January 5, 2026 21:36
@ConnorBaker
Copy link
Contributor

Apologies for the delay!

@ConnorBaker ConnorBaker added this pull request to the merge queue Jan 6, 2026
@nixpkgs-ci nixpkgs-ci bot added the 12.approvals: 1 This PR was reviewed and approved by one person. label Jan 6, 2026
Merged via the queue into NixOS:master with commit 746df1b Jan 6, 2026
30 of 32 checks passed
@me-and me-and deleted the nixpkgs-config-lib branch January 27, 2026 19:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: changelog This PR adds or changes release notes 8.has: documentation This PR adds or changes documentation 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: 1 This PR was reviewed and approved by one person.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Regression: infinite recursion when passing a function to nixpkgs' config arg

3 participants