Skip to content

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

@me-and

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    0.kind: bugSomething is broken0.kind: regressionSomething that worked before working no longer

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions