Repository navigation
Closed
Closed
Copy link
Labels
Description
As of #437723, and in particular f5deefd, it is no longer possible to use a function as the config argument when importing nixpkgs.
As a minimal example, consider the following:
{
pkgs ? import <nixpkgs> {
config =
{ pkgs, ... }:
{
allowlistedLicenses = [ pkgs.lib.licenses.unfree ];
};
},
}:
pkgs.runCommandLocal "demo" { } "touch $out"This builds just fine prior to f5deefd, but from that commit onwards, I see the below output:
$ nix-build -I nixpkgs="$HOME"/vcs/nixpkgs
error:
… while evaluating a branch condition
at /home/adamdinwoodie/vcs/nixpkgs/pkgs/stdenv/booter.nix:107:9:
106| thisStage =
107| if args.__raw or false then
| ^
108| args'
… in the right operand of the update (//) operator
at /home/adamdinwoodie/vcs/nixpkgs/pkgs/stdenv/booter.nix:90:44:
89| # for the final stage.
90| { allowCustomOverrides = index == 1; } // (stageFun prevStage)
| ^
91| ) (lib.lists.reverseList stageFuns);
… while evaluating the option `allowlistedLicenses':
… while evaluating definitions from `nixpkgs.config':
(stack trace truncated; use '--show-trace' to show the full, detailed trace)
error: infinite recursion encountered
at /home/adamdinwoodie/vcs/demo/default.nix:6:33:
5| {
6| allowlistedLicenses = [ pkgs.lib.licenses.unfree ];
| ^
7| };
This use case seems to be the intent of the following code, essentially added at e1c1ecf:
nixpkgs/pkgs/top-level/default.nix
Lines 109 to 112 in 1a19c69
| # Allow both: | |
| # { /* the config */ } and | |
| # { pkgs, ... } : { /* the config */ } | |
| config1 = if lib.isFunction config0 then config0 { inherit pkgs; } else config0; |
Tagging @ConnorBaker.
Activity
me-and commentedon Oct 30, 2025
Possibly I'm being unfair in asserting that this was the intent of making
configa function, or at least in the implication that this usage is entirely broken. In particular,pkgs.lib.getNameseems to still work just fine in the definition ofallowUnfreePredicate. It's just my use case with referencing a license frompkgs.lib.licensesinallowlistedLicensesthat's not working.config.nix: work around NixOS/nixpkgs#456994
ConnorBaker commentedon Oct 30, 2025
I thought I had fixed this...
From what I remember, setting the type to
types.rawinstead oftypes.listOf (types.attrsOf types.anything)allowed evaluation to succeed, as did removing the options entirely.I'll make a PR to change the type back to
types.rawin the interim (which is what it would be without an option; see thefreeformTypeattribute inpkgs/top-level/config.nix.CC @infinisil -- any idea why this would cause infinite recursion? Presence or absence of packages at the top level of the package set shouldn't be conditioned on something like license, right?
ConnorBaker commentedon Oct 30, 2025
@me-and would you test #457038?
Revert "config: add and document {allow,block}listedLicenses"
ConnorBaker commentedon Oct 31, 2025
Closed by #457338.
@me-and I do like the PR you have to provide
libas an argument and would like to see that merged, but I’m closing this issue since the breakage has been addressed through a revert. Thank you for reporting it!nixpkgs: pass `lib` to config function
nixpkgs: pass `lib` to config function
nixpkgs: pass `lib` to config function
nixpkgs: pass `lib` to config function
nixpkgs: pass `lib` to config function
nixpkgs: pass `lib` to config function
nixpkgs: pass `lib` to config function
nixpkgs: pass `lib` to config function
modules/nixpkgs: pass `lib` to config function