Skip to content

top-level/stage: abort lazily in internallyDisallowedAttrPathsOverlay - #537799

Merged
llakala merged 1 commit into
NixOS:masterfrom
MattSturgeon:ci/eval/abort-on-instantiate
Sep 2, 2026
Merged

top-level/stage: abort lazily in internallyDisallowedAttrPathsOverlay#537799
llakala merged 1 commit into
NixOS:masterfrom
MattSturgeon:ci/eval/abort-on-instantiate

Conversation

@MattSturgeon

@MattSturgeon MattSturgeon commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Followup to #533376 (comment), I noticed in #522364 that inheriting a problematic package's version was enough to trigger the abort.

There's a debate to be had about what kinda relationships should require re-declaring dependencies' problems. My view is that depending on derivation outputs requires declaring a problem, while inheriting metadata from a problem-package could easily be inlined if/when that package is removed, so should not require declaring a problem.


Instead of replacing internally disallowed attrs entirely with an abort, we now lazily abort on access while preserving a small allowlist of metadata attributes. EDIT: After discussion around the intended semantics of lib.warnOnInstantiate, I've changed the implementation to take a different approach.

Instead of replacing internally disallowed attrs with an immediate abort, we now abort lazily when a derivation (or one of its outputs) is instantiated. This preserves access to metadata and helper attributes while still preventing dependencies on the derivation's outputs.

Unlike lib.warnOnInstantiate, this only intercepts instantiation (i.e. evaluation of drvPath, outPath, shellPath, or an output's corresponding paths), rather than warning on most interactions with the derivation.

I also refactored the abort message to use lib.showAttrPath instead of concatStringsSep ".", which correctly formats attrpaths containing non-identifier segments.

Previous implementation

The original version of this PR preserved access to a small allowlist of attributes (version, meta, passthru, etc.) by wrapping derivations in a similar fashion to lib.warnOnInstantiate.

The current implementation instead preserves the entire derivation object and only aborts at instantiation time, which better matches the intended policy.


Tested in the repl:

nix-repl> pkgs = import ./. { config.attrPathsDisallowedForInternalUse = [ { attrPath = ["hello"]; reason = "hi!"; } ]; }

nix-repl> pkgs.mold-unwrapped.tests.wrapped
error:
       … while calling the 'derivationStrict' builtin
         at «nix-internal»/derivation-internal.nix:37:12:
           36|
           37|   strict = derivationStrict drvAttrs;
             |            ^
           38|

       … while evaluating derivation 'mold-wrapped-test'
         whose name attribute is located at /home/matt/nixpkgs/ci/pkgs/stdenv/generic/make-derivation.nix:651:11while evaluating attribute 'buildCommand' of derivation 'mold-wrapped-test'
         at /home/matt/nixpkgs/ci/pkgs/build-support/trivial-builders/default.nix:81:17:
           80|         enableParallelBuilding = true;
           81|         inherit buildCommand name;
             |                 ^
           82|         passAsFile = [ "buildCommand" ] ++ (derivationArgs.passAsFile or [ ]);

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

       error: evaluation aborted with the following error message: 'hello is disallowed from being used within Nixpkgs, because hi!'

nix-repl> pkgs.hello
error: attribute 'hello' missing
       at «string»:1:1:
            1| pkgs.hello
             | ^
       Did you mean one of jello, _3llo, bella, cell or delly?

nix-repl> pkgs.jello
«derivation /nix/store/0kvlydnamlcvxby6i2rmavl8xax37hbv-python3.13-jello-1.6.1.drv»

Things done

@MattSturgeon
MattSturgeon requested a review from infinisil July 2, 2026 13:23
@nixpkgs-ci
nixpkgs-ci Bot requested a review from Ericson2314 July 2, 2026 13:28
@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. labels Jul 2, 2026

@infinisil infinisil left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Makes sense, especially also because meta.problems only trigger on instantiate!

Comment thread pkgs/top-level/stage.nix Outdated
@nixpkgs-ci nixpkgs-ci Bot added the 12.approvals: 1 This PR was reviewed and approved by one person. label Jul 3, 2026
@nixpkgs-ci nixpkgs-ci Bot added 12.approvals: 2 This PR was reviewed and approved by two persons. and removed 12.approvals: 1 This PR was reviewed and approved by one person. labels Jul 3, 2026
Instead of replacing internally disallowed attrs entirely with an abort,
we now abort lazily on instantiation.

This allows evaluating and/or reusing metadata and utilities from
problematic packages while still blocking dependencies on their outputs.

Not to be confused with `lib.warnOnInstantiate`, which actually warns on
almost all usage, not just instantiation.

Also: refactored abort message to use `lib.showAttrPath`.
@MattSturgeon
MattSturgeon force-pushed the ci/eval/abort-on-instantiate branch from 2a18efe to beefc61 Compare July 5, 2026 14:57
@MattSturgeon

MattSturgeon commented Jul 5, 2026

Copy link
Copy Markdown
Contributor Author

Following the discussion around lib.warnOnInstantiate, I've pushed an outputs-based approach and updated the PR description.

@infinisil and @llakala, it'd be great if you're able to take another look.

@MattSturgeon

Copy link
Copy Markdown
Contributor Author

I'd like to land this if there are no objections, but I'm conscious that the implementation has changed since it was reviewed and performance could be better optimised (although performance only affects CI).

@MattSturgeon
MattSturgeon requested a review from philiptaron July 14, 2026 08:27
@MattSturgeon

Copy link
Copy Markdown
Contributor Author

Friendly bump; would be great to get some eyeballs on the revised approach!

@MattSturgeon

Copy link
Copy Markdown
Contributor Author

I'll merge this soon unless anyone objects 🙂

@llakala

llakala commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Sorry for missing this.

I'm fine to merge this. To be honest, I disagree with the design behind meta.problems only being allowed for leaf packages - @whispersofthedawn has convinced me that it should be allowed everywhere. But this is a fine incremental improvement.

@llakala
llakala added this pull request to the merge queue Sep 2, 2026
Merged via the queue into NixOS:master with commit 5865c0f Sep 2, 2026
31 of 33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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: 2 This PR was reviewed and approved by two persons.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants