Skip to content

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

Closed

Description

@me-and

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:

# Allow both:
# { /* the config */ } and
# { pkgs, ... } : { /* the config */ }
config1 = if lib.isFunction config0 then config0 { inherit pkgs; } else config0;

Tagging @ConnorBaker.

Activity

  1. added
    0.kind: bug
    0.kind: regression
    on Oct 30, 2025
  2. me-and commented on Oct 30, 2025

    @me-and
    MemberAuthor

    Possibly I'm being unfair in asserting that this was the intent of making config a function, or at least in the implication that this usage is entirely broken. In particular, pkgs.lib.getName seems to still work just fine in the definition of allowUnfreePredicate. It's just my use case with referencing a license from pkgs.lib.licenses in allowlistedLicenses that's not working.

  3. ConnorBaker commented on Oct 30, 2025

    @ConnorBaker
    Contributor

    I thought I had fixed this...

    From what I remember, setting the type to types.raw instead of types.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.raw in the interim (which is what it would be without an option; see the freeformType attribute in pkgs/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?

  4. ConnorBaker commented on Oct 30, 2025

    @ConnorBaker
    Contributor

    @me-and would you test #457038?

  5. ConnorBaker commented on Oct 31, 2025

    @ConnorBaker
    Contributor

    Closed by #457338.

    @me-and I do like the PR you have to provide lib as 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!

  6. added a commit that references this issue on Jan 5, 2026
    8e94561
  7. added 7 commits that reference this issue on Jan 8, 2026
    3d3a314
    121f115
    01f6674
    ee6bd72
    4b60417
    83e2730
    315c19e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    0.kind: bug0.kind: regression

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions