Skip to content

stdenv/problems: use generated problems for legacy field values - #557381

Merged
llakala merged 4 commits into
NixOS:masterfrom
andir:check-meta-problem-refactorings
Sep 14, 2026
Merged

llakala merged 4 commits into
NixOS:masterfrom
andir:check-meta-problem-refactorings

Conversation

@andir

@andir andir commented Aug 28, 2026

Copy link
Copy Markdown
Member

Continuing my work on porting RFC127 defined problems from the old attrs.meta world. This is a follow-up to #556367 and lays some groundwork to continue #545234.

The idea is to have the meta attributes in the final derivation always reflect what has been determined (either by automatic problems or by manually setting a field). Right now we have two implementations of meta.broken checks. One of them is in the check-meta.nix file and the other is in the problems.nix implementation. By leaning onto the problems.nix implementation as part of the commonMeta function we can reduce the duplication back to one canonical implementation. IMO this is an approach that should also be taken for further checks that get moved as we don't want a drift in that logic.

While talking through this idea it became apparent that problems.nix should probably only be the data layer for all the problems and the handler code should take care of the escape hatches (e.g. checking env vars).

Opening as a draft for now as this will require some further work and testing before I'm confident.

The other PRs (notably #545234) will be rebased/rewritten to match the outcome of this.

Things done

@llakala

llakala commented Aug 28, 2026 •

Copy link
Copy Markdown
Contributor

Quick diff check: the call to genAutomaticProblems in the first commit could partially apply the filter on problem.condition config, before attrs is passed.

Comment thread pkgs/stdenv/generic/check-meta.nix Resolved
@andir
andir force-pushed the check-meta-problem-refactorings branch from efabfd2 to 28ef688 Compare September 4, 2026 10:48
@nixpkgs-ci nixpkgs-ci Bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux. 6.topic: stdenv Standard environment labels Sep 4, 2026
@andir

andir commented Sep 4, 2026

Copy link
Copy Markdown
Member Author

Quick diff check: the call to genAutomaticProblems in the first commit could partially apply the filter on problem.condition config, before attrs is passed.

How do you mean? Wouldn't that just be wrapping the actual function with yet another thunk? I don't see how we can access problems without passing a concrete attrs instance.

For the sake of completeness I've rebased and pushed a new commit that removes the old meta.broken check from check-meta.nix. So far that seems to do just the right thing.

@andir
andir marked this pull request as ready for review September 4, 2026 11:28
@nixpkgs-ci
nixpkgs-ci Bot requested review from a team, Ericson2314, adisbladis and infinisil September 4, 2026 11:35
@llakala

llakala commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

How do you mean? Wouldn't that just be wrapping the actual function with yet another thunk? I don't see how we can access problems without passing a concrete attrs instance.

I didn't explain myself very well. We can change genAutomaticProblems to partially apply config when it's passed, like so:

diff --git a/pkgs/stdenv/generic/problems.nix b/pkgs/stdenv/generic/problems.nix
index 887242e53684..9ae0b5d7b6d3 100644
--- a/pkgs/stdenv/generic/problems.nix
+++ b/pkgs/stdenv/generic/problems.nix
@@ -149,10 +149,17 @@ rec {
   );
 
   genAutomaticProblems =
-    config: attrs:
+    config:
+    let
+      # only perform the logic that requires config once
+      automaticProblems' = map (
+        problem: problem // { condition = problem.condition config; }
+      ) automaticProblems;
+    in
+    attrs:
     listToAttrs (
       map (problem: lib.nameValuePair problem.kindName problem.value) (
-        filter (problem: problem.condition config attrs) automaticProblems
+        filter (problem: problem.condition attrs) automaticProblems'
       )
     );
 

This is meaningful for automatic problems like broken, where if allowBroken == true, then it can just do attrs: false.

@llakala

llakala commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Running stats diff with pkgs.firefox (I don't trust the CI here, since it's got checkMeta = true):

{
  "attrset": {
    "lookups": "-0.03%",
    "merges": "+0%",
    "mergeCopies": null
  },
  "list": {
    "concats": null
  },
  "parser": {
    "expressions": "+0%"
  },
  "memoryBytes": {
    "envs": "+0.09%",
    "list": "+0.01%",
    "sets": "+0%",
    "symbols": "+0.01%",
    "values": "+0.06%",
    "total": "+0.02%"
  },
  "speed": {
    "primops": "+0.2%",
    "functionCalls": "+0.04%",
    "thunksMade": "+0.12%",
    "thunksAvoided": "+0.07%"
  }
}

I'm surprised by the fact that there's a diff at all. I guess it's caused by the places wherethe final result of meta is forced through something like meta.mainProgram, and therefore we just have more attributes in the names? That's acceptable to me - just making sure this doesn't affect us anywhere else.

@andir

andir commented Sep 4, 2026

Copy link
Copy Markdown
Member Author

I'm surprised by the fact that there's a diff at all. I guess it's caused by the places wherethe final result of meta is forced through something like meta.mainProgram, and therefore we just have more attributes in the names? That's acceptable to me - just making sure this doesn't affect us anywhere else.

I'm almost certain the typechecking for meta is whats causing this. Normally nothing should care about the right hand side of the meta attributes unless used in an expression. Since the typechecking probably does some builtins.typeOf val that will force the value even if it is never really used.

@andir

andir commented Sep 4, 2026

Copy link
Copy Markdown
Member Author

Running stats diff with pkgs.firefox (I don't trust the CI here, since it's got checkMeta = true):

{
  "attrset": {
    "lookups": "-0.03%",
    "merges": "+0%",
    "mergeCopies": null
  },
  "list": {
    "concats": null
  },
  "parser": {
    "expressions": "+0%"
  },
  "memoryBytes": {
    "envs": "+0.09%",
    "list": "+0.01%",
    "sets": "+0%",
    "symbols": "+0.01%",
    "values": "+0.06%",
    "total": "+0.02%"
  },
  "speed": {
    "primops": "+0.2%",
    "functionCalls": "+0.04%",
    "thunksMade": "+0.12%",
    "thunksAvoided": "+0.07%"
  }
}

I'm surprised by the fact that there's a diff at all. I guess it's caused by the places wherethe final result of meta is forced through something like meta.mainProgram, and therefore we just have more attributes in the names? That's acceptable to me - just making sure this doesn't affect us anywhere else.

If you apply this does that change the numbers for you?

index 724e8b8ccac4..4abef94a27cd 100644
--- a/pkgs/stdenv/generic/check-meta.nix
+++ b/pkgs/stdenv/generic/check-meta.nix
@@ -351,7 +351,7 @@ let
     else
     # Check meta attribute types first, to make sure it is always called even when there are other issues
     # Note that this is not a full type check and functions below still need to by careful about their inputs!
-    if checkMeta && !metaType.verify attrs.meta then
+    if checkMeta /* && !metaType.verify attrs.meta */ then
       {
         reason = "unknown-meta";
         msg = "has an invalid meta attrset:${

@llakala

llakala commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

I'm almost certain the typechecking for meta is whats causing this. Normally nothing should care about the right hand side of the meta attributes unless used in an expression. Since the typechecking probably does some builtins.typeOf val that will force the value even if it is never really used.

But checkMeta is false by default for non-CI.

❯ lix repl
Lix 2.95.2
Type :? for help.
Loading 'repl-overlays'...
Added 119 variables.
nix-repl> pkgs.config.checkMeta
false

So that patch wouldn't affect it.

@andir

andir commented Sep 4, 2026

Copy link
Copy Markdown
Member Author

I'm almost certain the typechecking for meta is whats causing this. Normally nothing should care about the right hand side of the meta attributes unless used in an expression. Since the typechecking probably does some builtins.typeOf val that will force the value even if it is never really used.

But checkMeta is false by default for non-CI.

❯ lix repl
Lix 2.95.2
Type :? for help.
Loading 'repl-overlays'...
Added 119 variables.
nix-repl> pkgs.config.checkMeta
false

So that patch wouldn't affect it.

Mhm, forcing an error by passing in a invalid unsupported value instead of hasProblemKind "broken" shows that it is now consumed by the problems.nix code.. so that recursion is there which isn't ideal because that means we are running the machinery twice. Once against the definitions in the package and once against the attributes that commonMeta checks. I had assumed that wasn't the case but that also explains why it does more.

This makes it a bit cheaper to call the completeMetaProblems function
as the automatic problems are only generated once (per `config`
instance).
This is similar to how we use the genCheckProblems function for the
generic problem generation. Accessing multiple `meta.problems` fields
should become slightly cheaper now.
This pulls in the brokenness information from the meta.problems
fields. This decouples the both implementation from each
other (slightly). Whatever the metric for brokenness in meta.problems
is now carries over to old meta.broken attribute.

Right now there is no difference in the value of meta.broken since the
both implementations are almost identical. As future work we could now
drop the logic from `check-meta.nix` and rely solely on the problems
code to do the brokenness detection without abandoning `meta.broken`
as value to query.
For some time we've had the meta.problems automatic problems detect
brokenness of a package (same logic; looking at meta.broken) but also
kept the "legacy" code to propagate the information into the final meta
attrset. Since we already have the problems information as part of the
commonMeta implementation we can make use of that to propagate the
field. We now only have one implementation for the broken attribute.
Yay.
@andir
andir force-pushed the check-meta-problem-refactorings branch from fbd9044 to 2ff9e84 Compare September 11, 2026 10:04
@andir

andir commented Sep 11, 2026

Copy link
Copy Markdown
Member Author

I'm almost certain the typechecking for meta is whats causing this. Normally nothing should care about the right hand side of the meta attributes unless used in an expression. Since the typechecking probably does some builtins.typeOf val that will force the value even if it is never really used.

But checkMeta is false by default for non-CI.

❯ lix repl
Lix 2.95.2
Type :? for help.
Loading 'repl-overlays'...
Added 119 variables.
nix-repl> pkgs.config.checkMeta
false

So that patch wouldn't affect it.

Mhm, forcing an error by passing in a invalid unsupported value instead of hasProblemKind "broken" shows that it is now consumed by the problems.nix code.. so that recursion is there which isn't ideal because that means we are running the machinery twice. Once against the definitions in the package and once against the attributes that commonMeta checks. I had assumed that wasn't the case but that also explains why it does more.

I think I know how to work around that, but it requires a bit more refactoring than I'd really like to do in this PR.

The PR has been rebased again and I'd like to land it as is unless there are still concerns.

@andir andir changed the title stdenv/problems: pre-apply config to genAutomaticProblems stdenv/problems: use generated problems for legacy field values Sep 11, 2026
@andir

andir commented Sep 11, 2026

Copy link
Copy Markdown
Member Author

How do you mean? Wouldn't that just be wrapping the actual function with yet another thunk? I don't see how we can access problems without passing a concrete attrs instance.

I didn't explain myself very well. We can change genAutomaticProblems to partially apply config when it's passed, like so:

diff --git a/pkgs/stdenv/generic/problems.nix b/pkgs/stdenv/generic/problems.nix
index 887242e53684..9ae0b5d7b6d3 100644
--- a/pkgs/stdenv/generic/problems.nix
+++ b/pkgs/stdenv/generic/problems.nix
@@ -149,10 +149,17 @@ rec {
   );
 
   genAutomaticProblems =
-    config: attrs:
+    config:
+    let
+      # only perform the logic that requires config once
+      automaticProblems' = map (
+        problem: problem // { condition = problem.condition config; }
+      ) automaticProblems;
+    in
+    attrs:
     listToAttrs (
       map (problem: lib.nameValuePair problem.kindName problem.value) (
-        filter (problem: problem.condition config attrs) automaticProblems
+        filter (problem: problem.condition attrs) automaticProblems'
       )
     );
 

This is meaningful for automatic problems like broken, where if allowBroken == true, then it can just do attrs: false.

I think that is something I'll do in a follow-up as that'll be inline with the changes required to avoid the double problems eval that we are currently having. It also touches a point that I discussed with @infinisil a few weeks ago: The code filtering / throwing the errors shouldn't be as tangled to the problem gathering as it is now.

@llakala llakala left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that is something I'll do in a follow-up as that'll be inline with the changes required to avoid the double problems eval that we are currently having.

Sounds good. I'll merge this in a day or two if no other committers complain (remind me if I forget).

@nixpkgs-ci nixpkgs-ci Bot added the 12.approvals: 1 This PR was reviewed and approved by one person. label Sep 11, 2026
@andir

andir commented Sep 14, 2026

Copy link
Copy Markdown
Member Author

I think that is something I'll do in a follow-up as that'll be inline with the changes required to avoid the double problems eval that we are currently having.

Sounds good. I'll merge this in a day or two if no other committers complain (remind me if I forget).

Ping :-) I can also hit the merge button if you are fine with that.

@llakala
llakala added this pull request to the merge queue Sep 14, 2026
Merged via the queue into NixOS:master with commit 8a7ef7c Sep 14, 2026
32 of 34 checks passed
@github-project-automation github-project-automation Bot moved this to Done in Stdenv Sep 14, 2026
@andir
andir deleted the check-meta-problem-refactorings branch September 14, 2026 12:42
@sternenseemann

Copy link
Copy Markdown
Member

Somehow, this causes meta.broken = true and problems.broken to disappear with allowBroken = true in the Nixpkgs config. This surely can't be the intention? It's still useful meta data which may be useful to query. In particular, it would be useful to be able to inspect the meta data even when the broken problem is ignored – without tryEval.

maralorn added a commit to maralorn/nixpkgs that referenced this pull request Nov 1, 2026
NixOS#557381 changed the semantics of config.allowBroken in a way which broke our override to ignore brokenness of packages.

It has now two problems:

1. allowBroken now (sometimes) affects the meta.broken flag of a package which breaks our logic.
2. It behaves inconsistent depending on how a package was marked broken.

This commit works around this by not using allowBroken. Instead it overrides the logic which converts broken packages to eval errors thus sidestepping both above problems.
magicquark pushed a commit to magicquark/nixpkgs that referenced this pull request Nov 3, 2026
NixOS#557381 changed the semantics of config.allowBroken in a way which broke our override to ignore brokenness of packages.

It has now two problems:

1. allowBroken now (sometimes) affects the meta.broken flag of a package which breaks our logic.
2. It behaves inconsistent depending on how a package was marked broken.

This commit works around this by not using allowBroken. Instead it overrides the logic which converts broken packages to eval errors thus sidestepping both above problems.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

6.topic: stdenv Standard environment 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux. 12.approvals: 1 This PR was reviewed and approved by one person.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants