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

by-name-overlay: don't include empty directories #340778

Closed
wants to merge 1 commit into from

Conversation

cafkafk
Copy link
Member

@cafkafk cafkafk commented Sep 9, 2024

Description of changes

Currently, by-name-overlay does not check if the directories are empty. This is
specially problematic because it doesn't matter that git isn't tracking them
when not using nix3 commands.

This adds a check to ensure that any package in a shard that gets included is
actually a package.

I'd love some review on this. I'm not super familiar with nixpkgs internals.

Fixes: #338227
Signed-off-by: Christina Sørensen christina@cafkafk.com

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 24.11 Release Notes (or backporting 23.11 and 24.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

@cafkafk cafkafk marked this pull request as ready for review September 9, 2024 13:20
@ofborg ofborg bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild 10.rebuild-linux: 0 This PR does not cause any packages to rebuild labels Sep 9, 2024
(readDir (baseDirectory + "/${shard}"));
lib.filterAttrs (_: path: builtins.pathExists path) (
mapAttrs (name: _: baseDirectory + "/${shard}/${name}/package.nix") (
readDir (baseDirectory + "/${shard}")
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps this is a use case for lib.pipe?

Copy link
Member

Choose a reason for hiding this comment

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

That's bad for eval perf.

@infinisil
Copy link
Member

Hmm, this is a tricky one, because it increases evaluation time for every Nixpkgs evaluation. Not by much, but measurably:

Command Mean [ms] Min [ms] Max [ms] Relative
Before 149.1 ± 2.7 145.2 156.5 1.00
After 198.5 ± 2.5 193.4 203.8 1.33 ± 0.03

This is by running hyperfine on

nix-instantiate --eval -E 'builtins.seq (import <nixpkgs> {}) null'

The fix for the issue is nice, but it's a tricky call as to whether it's worth it for the evaluation time increase. I'm on the edge!

A future alternative would be to have a builtins.readPackages ./pkgs/by-name to never worry about performance of pkgs/by-name anymore.

@cafkafk
Copy link
Member Author

cafkafk commented Sep 10, 2024

The fix for the issue is nice, but it's a tricky call as to whether it's worth it for the evaluation time increase. I'm on the edge!

On one hand, I think (but haven't tested) that this shouldn't be an issue with nix3 commands, on the other, I feel like nixpkgs already has made compromises to support pre nix3 commands...

Like personally, I lean not making nixpkgs slower here, or perhaps just refactoring this? Alternatively, maybe it's possible to make a fix that instead of doing file IO on all packages in by-name runs some git ls-files to find if there are any empty repositories not tracked by git, that would make the check a one time thing instead of a N time thing?

EDIT: Alternatively, if there is a way to only check folders that aren't empty (i.e. are visible to git) maybe there is a more elegant solution in that directon?

@cafkafk
Copy link
Member Author

cafkafk commented Sep 10, 2024

We probably at least should find a way to warn people affected by #338227, because an empty folder is invisible to e.g. git status so people using nix-build will have no idea why their commands don't work when they "didn't change anything" >_>

fixes:  NixOS#338227

Signed-off-by: Christina Sørensen <christina@cafkafk.com>
@katexochen
Copy link
Contributor

The fix for the issue is nice, but it's a tricky call as to whether it's worth it for the evaluation time increase. I'm on the edge!

Yah, expected that a fix would hit performance...

We probably at least should find a way to warn people affected by #338227, because an empty folder is invisible to e.g. git status so people using nix-build will have no idea why their commands don't work when they "didn't change anything" >_>

Agree, maybe a warning would be enough, especially as more and more people are moving towards nix3, where this isn't an issue.

@philiptaron
Copy link
Contributor

I propose a more targeted fix for maintainers/scripts/build.nix in #341041.

@cafkafk cafkafk marked this pull request as draft September 11, 2024 04:39
@Atemu
Copy link
Member

Atemu commented Sep 15, 2024

I assume this is superseded by #341041?

@cafkafk
Copy link
Member Author

cafkafk commented Sep 15, 2024

I assume this is superseded by #341041?

Essentially, although it would likely make sense to create a more generic fix if possible (without performance regressions)

@Atemu Atemu closed this Sep 15, 2024
@philiptaron
Copy link
Contributor

philiptaron commented Sep 24, 2024

Essentially, although it would likely make sense to create a more generic fix if possible (without performance regressions)

Agreed. This is one of the places where Nix builtins could be highly leveraged, since they're able to make these tests much cheaper in aggregate than is possible in pure Nix. It would take a high degree of coordination across deployed Nix runtimes (Lix, Nix, maybe Tvix) to do that.

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 10.rebuild-linux: 0 This PR does not cause any packages to rebuild
Projects
None yet
Development

Successfully merging this pull request may close these issues.

maintainers/scripts/build.nix isn't ignoring empty dirs in pkg/by-name
7 participants