Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

References to pkgs from ~/.config/nixpkgs/config.nix produce infinite recursion #246676

Open
lilyball opened this issue Aug 2, 2023 · 4 comments
Labels
0.kind: bug Something is broken

Comments

@lilyball
Copy link
Member

lilyball commented Aug 2, 2023

Describe the bug

When using ~/.config/nixpkgs/config.nix to configure nixpkgs, this file may optionally be a function that takes a single { pkgs }: parameter. This is necessary when adding configuration for blocklistedLicenses in order to reference the licenses in question. Example usage:

{ pkgs }:

{
  blocklistedLicenses = with pkgs.lib.licenses; [ agpl3Only agpl3Plus ];
}

As of #240433 (darwin.stdenv: Darwin stdenv rework), the reference to pkgs within this file produces an infinite recursion error:

error:
       … <borked>

         at «none»:0: (source not available)

       … while evaluating a branch condition

         at /Users/lily/Dev/Nix/nixpkgs/pkgs/stdenv/booter.nix:99:7:

           98|     thisStage =
           99|       if args.__raw or false
             |       ^
          100|       then args'

       (stack trace truncated; use '--show-trace' to show the full trace)

       error: infinite recursion encountered

       at /Users/lily/.config/nixpkgs/config.nix:4:30:

            3| {
            4|   blocklistedLicenses = with pkgs.lib.licenses; [ agpl3Only agpl3Plus ];
             |                              ^
            5| }

Steps To Reproduce

Steps to reproduce the behavior:

  1. Ensure your nixpkgs contains commit a845397
  2. Ensure the file ~/.config/nixpkgs/config.nix contains the contents listed above and that there is no NIXPKGS_CONFIG env var (or set NIXPKGS_CONFIG to the path of a file containing the above)
  3. Run something like nix-instantiate --eval --expr 'with import ./. {}; hello.version' (if from a nixpkgs checkout, or import <nixpkgs> if appropriate).

Expected behavior

This should run successfully (in this case, printing the version of the hello package).

Additional context

Merely doing something like blocklistedLicenses = assert builtins.isAttrs pkgs; []; is sufficient to cause this issue. Sticking this in some of the other config values (like allowUnfree) doesn't cause a problem, though I didn't test all of them. Looking at the full stack trace I think it's because it's trying to test the validity of ../../build-support/cc-wrapper during bootstrap, so it's likely just the allowlisted/blocklisted licenses that will end up evaluated here.

I really wish the config here was given { lib } instead, but that's a backwards-incompatible change.

Notify maintainers

Folks involved in the relevant PR: @reckenrode @viraptor @veprbl @emilazy @Atemu @tjni @willcohen @siraben @uri-canva

Metadata

Please run nix-shell -p nix-info --run "nix-info -m" and paste the result.

[user@system:~]$ nix run nixpkgs#nix-info -- -m
 - system: `"x86_64-darwin"`
 - host os: `Darwin 22.6.0, macOS 10.16`
 - multi-user?: `no`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.15.1`
 - channels(lily): `"darwin, home-manager"`
 - channels(root): `""`
 - nixpkgs: `/etc/nix/inputs/nixpkgs`
@lilyball lilyball added the 0.kind: bug Something is broken label Aug 2, 2023
@reckenrode
Copy link
Contributor

This also appears broken on Linux.

$ nix run nixpkgs#nix-info -- -m
 - system: `"x86_64-linux"`
 - host os: `Linux 6.1.41, NixOS, 22.11 (Raccoon), 22.11.20230703.ea4c80b`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.11.1`
 - nixpkgs: `/etc/nix/inputs/nixpkgs`
$  git rev-list a845397 -n 1
a845397040d1b85cec4ee41edb8598d8086c3d95
$ NIXPKGS_CONFIG=$(pwd)/../bug/config.nix nix-instantiate --eval --expr 'with import ./. {}; hello.version' --show-trace
error: infinite recursion encountered

       at /home/reckenrode/nixpkgs/../bug/config.nix:4:30:

            3| {
            4|   blocklistedLicenses = with pkgs.lib.licenses; [ agpl3Only agpl3Plus ];
             |                              ^
            5| }

       … while evaluating anonymous lambda

       at /home/reckenrode/nixpkgs/pkgs/stdenv/generic/check-meta.nix:41:40:

           40|   hasBlocklistedLicense = assert areLicenseListsValid; attrs:
           41|     hasLicense attrs && lib.lists.any (l: builtins.elem l blocklist) (lib.lists.toList attrs.meta.license);
             |                                        ^
           42|

       … from call site
# etc

@reckenrode
Copy link
Contributor

The nixos-22.11 channel works, so I’m using that as a known good commit to do a git bisect on Linux.

@reckenrode
Copy link
Contributor

reckenrode commented Aug 2, 2023

git bisect points to d7aad24, which is the logic the Darwin stdenv rework copied. 😫

@wegank wegank changed the title Refactored darwin stdenv breaks references to pkgs from ~/.config/nixpkgs/config.nix References to pkgs from ~/.config/nixpkgs/config.nix produce infinite recursion Aug 2, 2023
@lilyball
Copy link
Member Author

lilyball commented Aug 2, 2023

I'm curious if anyone actually has any use for referencing anything other than lib from pkgs in the config file. In theory we could just hand the config file { pkgs = { inherit lib; }; } and call it a day. Though I'm guessing there's at least one person out there who's actually accessing other things from pkgs for whatever reason (I suppose there's a potential use of e.g. permittedInsecurePackages = [ pkgs.someInsecurePackage.name ]).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0.kind: bug Something is broken
Projects
None yet
Development

No branches or pull requests

2 participants