Skip to content

nix/review_shell.nix: use ignoreSingleFileOutputs whenever available#427

Merged
Mic92 merged 1 commit intoMic92:masterfrom
ShamrockLee:ignore-file-outputs
Aug 29, 2025
Merged

nix/review_shell.nix: use ignoreSingleFileOutputs whenever available#427
Mic92 merged 1 commit intoMic92:masterfrom
ShamrockLee:ignore-file-outputs

Conversation

@ShamrockLee
Copy link
Contributor

@ShamrockLee ShamrockLee commented Nov 5, 2024

This PR depends on NixOS/nixpkgs#353752 and fixes #408 partially.

Cc: @corngood

Summary by CodeRabbit

  • New Features
    • Optimized dev shell handling for large dependency sets to improve startup and selection behavior.
    • Improved compatibility across Nix versions by conditionally enabling newer environment options when supported.
    • More predictable local builds: prefer local compilation, disable substitutes, and avoid wrapping Qt apps.

@Mic92
Copy link
Owner

Mic92 commented Nov 5, 2024

Thanks. Looks good.

@ShamrockLee
Copy link
Contributor Author

Considering that the single-file-output error is a potential way to enforce the correctness of meta.outputsToInstall, we may want to preserve such behavior while proving options to ignore those single-file outputs.

I prepared the implementation to support nixpkgs-review --ignore-single-file-outputs locally. I could push it up if we agree that this should be supported through a flag.

@Mic92, what do you think?

Copy link
Contributor

@corngood corngood left a comment

Choose a reason for hiding this comment

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

I'm not sure if it's something to do with the change in evaluation methods, but lately I'm getting a lot more file conflicts due to "test.*" being included in attrs.nix, so it would be nice to get this in.

ignoreCollisions = true;
};
env =
local-pkgs.buildEnv {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this needs parens around the attrset update, so ignoreSingleFileOutputs makes it into buildEnv.

It does seem to work okay once that's changed.

@ShamrockLee
Copy link
Contributor Author

@corngood Thank you for rewiewing!

Do you think it's preferred to have ignoreSingleFileOutputs = true by default (the current implementation), or provide a flag --ignore-single-file-outputs to opt in explicitly?

@corngood
Copy link
Contributor

Do you think it's preferred to have ignoreSingleFileOutputs = true by default (the current implementation), or provide a flag --ignore-single-file-outputs to opt in explicitly?

My gut feeling is that it should be a default, because people often run nixpkgs-review without knowledge of what's actually going to be built, and there are a bunch of things in nixpkgs that will break if they do happen to be built as part of a review. For example, I hit this on every update to dotnet-sdk, because of things in tests.dotnet.

However, you did mention this:

Considering that the single-file-output error is a potential way to enforce the correctness of meta.outputsToInstall

and I don't really understand what you mean by it. Maybe you can give an example?

@ShamrockLee
Copy link
Contributor Author

However, you did mention this:

Considering that the single-file-output error is a potential way to enforce the correctness of meta.outputsToInstall

and I don't really understand what you mean by it. Maybe you can give an example?

$ nix build --impure --expr "let pkgs = import ./. { }; in pkgs.buildEnv { name = ''empty-file-env''; paths = [ (pkgs.emptyFile.overrideAttrs (previousAttrs: { meta = previousAttrs.meta or { } // { outputsToInstall = [ ]; }; })) ]; }"

$ nix build --impure --expr "let pkgs = import ./. { }; in pkgs.buildEnv { name = ''empty-file-env''; paths = [ (pkgs.emptyFile.overrideAttrs (previousAttrs: { meta = removeAttrs previousAttrs.meta or { } [ ''outputsToInstall'' ]; })) ]; }"
error: builder for '/nix/store/2g6w6l2gc2inj96gji5fnaycyjc15rfb-empty-file-env.drv' failed with exit code 255;
       last 1 log lines:
       > error: The store path /nix/store/ij3gw72f4n5z4dz6nnzl1731p9kmjbwr-empty-file is a file and can't be merged into an environment using pkgs.buildEnv! at /nix/store/qrwjx5798fsp5yxaawrf5aklh1hp2xba-builder.pl line 115.
       For full logs, run 'nix log /nix/store/2g6w6l2gc2inj96gji5fnaycyjc15rfb-empty-file-env.drv'.

@ShamrockLee
Copy link
Contributor Author

but lately I'm getting a lot more file conflicts due to "test.*" being included in attrs.nix

Is it the default behavior now? I thought it would be opt-in.

@corngood
Copy link
Contributor

Is it the default behavior now? I thought it would be opt-in.

It's the top level tests attribute, not e.g. passthru.tests. It seems to be something to do with the github eval. See this review run:

NixOS/nixpkgs#389338 (comment)

  • tests.dotnet.final-attrs.check-output
  • tests.dotnet.final-attrs.output-matches-const
  • tests.dotnet.final-attrs.override-has-no-effect

etc

That one was done with github eval. Below that I posted a darwin review, which used local eval, and it didn't build anything in tests.

@ShamrockLee ShamrockLee changed the title nix/review_shell.nix: use ignoreFileOutputs whenever available nix/review_shell.nix: use ignoreSingleFileOutputs whenever available Mar 20, 2025
@corngood
Copy link
Contributor

That one was done with github eval. Below that I posted a darwin review, which used local eval, and it didn't build anything in tests.

I looked into this a bit, and I think it's just the difference between local eval using nix-env -qaP and the eval action using release-attrpaths-superset.nix.

I didn't realise they were so drastically different (essentially opt-in vs opt-out).

@corngood
Copy link
Contributor

corngood commented Aug 7, 2025

@ShamrockLee I've been running this locally (with the params change I mentioned above) for quite a while. What do you think about getting this in? I can make my own PR if you prefer.

@ShamrockLee
Copy link
Contributor Author

Thank you for pinging. This PR slipped under my radar.

Considering the default behavior of nixpkgs-review to evaluate pkgs.tests, let's set ignoreSingleFileOutputs = true by default.

I'm adding --check-single-file-outputs to allow ignoreSingleFileOutputs.

@ShamrockLee ShamrockLee force-pushed the ignore-file-outputs branch 2 times, most recently from 2a78291 to f186900 Compare August 12, 2025 00:07
@ShamrockLee
Copy link
Contributor Author

@corngood I made ignoreSingleFileOutputs = true by default when available and added an optional --check-single-file-outputs. Could you help me test this change?

@corngood
Copy link
Contributor

corngood commented Aug 12, 2025

This is enough to reproduce it when run from nixpkgs/master:

nix run github:Mic92/nixpkgs-review -- rev HEAD -p dotnet-sdk -p tests.dotnet -p dotnet-sdk.tests -p dotnet-sdk_9.tests

I needed to get it to find more than 50 attributes, due to packages = if builtins.length attrs > 50 then [ env ] else attrs;.

With <= 50 attributes it works even with single files when they are passed directly into mkShell. Because of that I think maybe it's not worth adding --check-single-file-outputs.

I tried running this PR branch:

nix run github:Mic92/nixpkgs-review\?ref=pull/427/head -- rev HEAD -p dotnet-sdk -p tests.dotnet -p dotnet-sdk.tests -p dotnet-sdk_9.tests

But it results in some test failures:

       > =========================== short test summary info ============================
       > FAILED tests/test_wip.py::test_wip_command_without_nom - RuntimeError: nixpkgs=/build/tmpnn4d93hp/cache/nixpkgs-review/rev-feed7400c...
       > FAILED tests/test_rev.py::test_rev_only_packages_does_not_trigger_an_eval - RuntimeError: nixpkgs=/build/tmpppz6853c/cache/nixpkgs-review/rev-328382046...
       > FAILED tests/test_pr.py::test_pr_only_packages_does_not_trigger_an_eval - RuntimeError: nixpkgs=/build/tmp2_bpt7o6/cache/nixpkgs-review/pr-363128/nix...
       > FAILED tests/test_wip.py::test_wip_only_packages_does_not_trigger_an_eval - RuntimeError: nixpkgs=/build/tmpz6rtxksp/cache/nixpkgs-review/rev-aa0f56062...
       > FAILED tests/test_pr.py::test_pr_local_eval_without_nom - RuntimeError: nixpkgs=/build/tmpvbkx1sgw/cache/nixpkgs-review/pr-1/nixpkgs ...
       > FAILED tests/test_pr.py::test_pr_github_action_eval - RuntimeError: nixpkgs=/build/tmpabhmn9t8/cache/nixpkgs-review/pr-363128/nix...
       > FAILED tests/test_pr.py::test_pr_local_eval_missing_nom - RuntimeError: nixpkgs=/build/tmpn9wrootx/cache/nixpkgs-review/pr-1/nixpkgs ...
       > FAILED tests/test_pr.py::test_pr_ofborg_eval - RuntimeError: nixpkgs=/build/tmp1dzokicc/cache/nixpkgs-review/pr-37200/nixp...
       > FAILED tests/test_rev.py::test_rev_command_without_nom - RuntimeError: nixpkgs=/build/tmpl4eujknx/cache/nixpkgs-review/rev-5a71b3c3e...
       > !!!!!!!!!!!!!!!!!!!!!!!!!! stopping after 9 failures !!!!!!!!!!!!!!!!!!!!!!!!!!!
       > !!!!!!!!!!!! xdist.dsession.Interrupted: stopping after 1 failures !!!!!!!!!!!!!
       > =================== 9 failed, 5 passed, 4 skipped in 10.93s ====================

@corngood
Copy link
Contributor

Because of that I think maybe it's not worth adding --check-single-file-outputs.

To clarify, this flag would only have an effect if there are more than 50 attributes in attrs.nix, which would be very confusing for users. Just setting ignoreSingleFileOutputs unconditionally makes the behaviour more consistent with the existing behaviour with <= 50 attributes.

@ShamrockLee ShamrockLee marked this pull request as ready for review August 12, 2025 18:40
@ShamrockLee
Copy link
Contributor Author

I needed to get it to find more than 50 attributes, due to packages = if builtins.length attrs > 50 then [ env ] else attrs;.

With <= 50 attributes it works even with single files when they are passed directly into mkShell. Because of that I think maybe it's not worth adding --check-single-file-outputs.

Thank you for finding out this isssue. I fixed the condition by using [ env ] whenever ignoreSingleFileOutputs is false.

@ShamrockLee
Copy link
Contributor Author

I tried running this PR branch:

nix run github:Mic92/nixpkgs-review\?ref=pull/427/head -- rev HEAD -p dotnet-sdk -p tests.dotnet -p dotnet-sdk.tests -p dotnet-sdk_9.tests

I'm a bit worry about the use of nix_build() and nix_shell() with a bunch of positional arguments. They are error-prone when adding new parameters.

@ShamrockLee
Copy link
Contributor Author

Just updated to call nix_build() and nix_shell() with keyword arguments instead.

@ShamrockLee ShamrockLee marked this pull request as draft August 12, 2025 19:17
@philiptaron
Copy link

I would like to see this PR merged because it would help me with such PRs as:

How can I help get this to mergeable status?

@corngood
Copy link
Contributor

Personally I think we should just set ignoreSingleFileOutputs unconditionally and remove --check-single-file-outputs. The flag was added out of an abundance of caution to maintain the old behaviour:

Considering that the single-file-output error is a potential way to enforce the correctness of meta.outputsToInstall, we may want to preserve such behavior while proving options to ignore those single-file outputs.

However the old behaviour was dependent on the number of packages being built relative to that undocumented magic threshold (50), so nobody could really depend on it anyway. At least that's how I understand it.

@ShamrockLee what do you think about that? If you'd prefer I can make a separate PR with what I'm suggesting, but it's really just going back to how this PR started.

@ShamrockLee
Copy link
Contributor Author

I changed my mind. It's so hard to get the command-line flag to pass the tests.

I'll reset the feature branch to specify ignoreSingleFileOutputs whenever available.

@coderabbitai
Copy link

coderabbitai bot commented Aug 29, 2025

Walkthrough

Refactors buildEnv usage to conditionally add ignoreSingleFileOutputs when supported, expands mkShell invocation with preferLocalBuild, allowSubstitutes, dontWrapQtApps, and changes packages to use a single env when attrs exceed 50 items.

Changes

Cohort / File(s) Summary
Review shell changes
nixpkgs_review/nix/review-shell.nix
Detects whether local-pkgs.buildEnv accepts ignoreSingleFileOutputs and merges that attr when available; constructs env via a two-part attr set. Extends mkShell with preferLocalBuild = true, allowSubstitutes = false, dontWrapQtApps = true, and sets packages = if builtins.length attrs > 50 then [ env ] else attrs.

Sequence Diagram(s)

sequenceDiagram
    participant Caller as Caller
    participant Nix as Nix Evaluator
    participant Lib as lib
    participant Pkgs as local-pkgs

    Caller->>Nix: import review-shell.nix (attrs)
    Nix->>Lib: check (lib.functionArgs local-pkgs.buildEnv) ? ignoreSingleFileOutputs
    alt supports ignoreSingleFileOutputs
        Nix->>Pkgs: buildEnv({name, paths=attrs, ignoreCollisions} // {ignoreSingleFileOutputs = true})
    else
        Nix->>Pkgs: buildEnv({name, paths=attrs, ignoreCollisions})
    end
    Note over Nix,Pkgs: env constructed
    Nix->>Nix: packages = if length(attrs) > 50 then [env] else attrs
    Nix->>Caller: mkShell{ preferLocalBuild, allowSubstitutes, dontWrapQtApps, packages }
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Assessment against linked issues

Objective Addressed Explanation
Handle single-file outputs in review shell (#408)

Assessment against linked issues: Out-of-scope changes

Code Change Explanation
Add preferLocalBuild = true (nixpkgs_review/nix/review-shell.nix) Not required by #408; unrelated to handling single-file outputs.
Add allowSubstitutes = false (nixpkgs_review/nix/review-shell.nix) Affects substitute behavior, not single-file vs directory env merging.
Add dontWrapQtApps = true (nixpkgs_review/nix/review-shell.nix) Concerns Qt app wrapping; not part of #408's objective.
Use single [ env ] when attrs > 50 (nixpkgs_review/nix/review-shell.nix) Performance/packaging optimization not specified in #408.

Poem

I nibbled through derivations, neat and small,
A single file? No problem at all!
With optional attrs I hop and weave,
The shell now builds — no need to grieve.
Pack paths in a basket when they’re many—
Hippity hop, green checks aplenty! 🐇✨

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.


📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 4a6e0eb and e757223.

📒 Files selected for processing (1)
  • nixpkgs_review/nix/review-shell.nix (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • nixpkgs_review/nix/review-shell.nix
✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbit in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbit in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbit gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbit read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbit help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbit ignore or @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbit summary or @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbit or @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@ShamrockLee ShamrockLee marked this pull request as ready for review August 29, 2025 08:46
@ShamrockLee ShamrockLee requested a review from corngood August 29, 2025 08:47
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
nixpkgs_review/nix/review-shell.nix (2)

29-38: Tiny readability tweak: bind the predicate once

Bind the support check in a let to avoid re-reading functionArgs and improve clarity.

-env = local-pkgs.buildEnv (
-  {
-    name = "env";
-    paths = attrs;
-    ignoreCollisions = true;
-  }
-  // lib.optionalAttrs ((lib.functionArgs local-pkgs.buildEnv) ? ignoreSingleFileOutputs) {
-    ignoreSingleFileOutputs = true;
-  }
-);
+env = local-pkgs.buildEnv (let supportsIgnoreSingleFileOutputs =
+  ((lib.functionArgs local-pkgs.buildEnv) ? ignoreSingleFileOutputs);
+in
+  {
+    name = "env";
+    paths = attrs;
+    ignoreCollisions = true;
+  }
+  // lib.optionalAttrs supportsIgnoreSingleFileOutputs {
+    ignoreSingleFileOutputs = true;
+  }
+);

40-46: Use local-pkgs.mkShell to guarantee consistent system/config and avoid re-import

This avoids a second nixpkgs import and ensures mkShell matches local-system and the provided config.

-(import nixpkgs-path { }).mkShell {
+local-pkgs.mkShell {
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 8115e78 and 4a6e0eb.

📒 Files selected for processing (1)
  • nixpkgs_review/nix/review-shell.nix (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
nixpkgs_review/nix/review-shell.nix (2)
nixpkgs_review/nix.py (3)
  • build_shell_file_args (370-400)
  • nix_build (303-367)
  • nix_shell (60-95)
nixpkgs_review/buildenv.py (1)
  • Buildenv (23-76)
🔇 Additional comments (1)
nixpkgs_review/nix/review-shell.nix (1)

29-38: ignoreSingleFileOutputs gating is correct; parens fix the pass-through bug

Merging the attrsets inside parentheses ensures the flag actually reaches buildEnv; the functionArgs check keeps this backward-compatible. This addresses the earlier review note about missing parens.

Copy link
Contributor

@corngood corngood left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks!

@Mic92 Mic92 merged commit 0715e46 into Mic92:master Aug 29, 2025
3 checks passed
@ShamrockLee ShamrockLee deleted the ignore-file-outputs branch August 30, 2025 16:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Review shell fails when there are single-file inputs.

4 participants