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

lib.packagesFromDirectoryRecursive: refactor (v2) #361424

Merged
merged 2 commits into from
Dec 28, 2024

Conversation

nbraud
Copy link
Contributor

@nbraud nbraud commented Dec 3, 2024

Second go at #359941

An assertion was too restrictive and broke the installer's tests, due to directory being a symlink.

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • Tested, as applicable:
    • NixOS test installer
    • nix-instantiate --eval --strict lib/tests/misc.nix
    • nix-build lib/tests/release.nix
  • 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
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

@github-actions github-actions bot added the 6.topic: lib The Nixpkgs function library label Dec 3, 2024
@nbraud
Copy link
Contributor Author

nbraud commented Dec 3, 2024

@ofborg test installer

@nix-owners nix-owners bot requested a review from infinisil December 3, 2024 11:19
@nbraud
Copy link
Contributor Author

nbraud commented Dec 3, 2024

nixpkgs-review result

Generated using nixpkgs-review.

Command: nixpkgs-review pr 361424


aarch64-darwin

✅ 1 package built:
  • nixpkgs-manual

@nbraud
Copy link
Contributor Author

nbraud commented Dec 3, 2024

nixpkgs-review result

Generated using nixpkgs-review.

Command: nixpkgs-review pr 361424


x86_64-linux

⏩ 1 package blacklisted:
  • nixos-install-tools
✅ 1 package built:
  • nixpkgs-manual

@nbraud
Copy link
Contributor Author

nbraud commented Dec 3, 2024

Successfully built nixosTests.installer locally (on NixOS x86-64)

PS: ofBorg seems to have bailed out without completing the test (no error in the log, it just stops partway through), possibly due to a timeout or such? I had noticed the test was running very slowly (based on the live log output)

@nbraud nbraud requested a review from K900 December 3, 2024 12:32
@nbraud
Copy link
Contributor Author

nbraud commented Dec 3, 2024

@K900 I requested your review so you'd have a chance to confirm whether this cause issues with the installer, as I am unsure whether nixosTests.installer covers everything necessary.

nbraud pushed a commit to nbraud/nixpkgs that referenced this pull request Dec 3, 2024
@K900
Copy link
Contributor

K900 commented Dec 3, 2024

Ofborg's lib tests can help here.

@nbraud
Copy link
Contributor Author

nbraud commented Dec 3, 2024

Ofborg's lib tests can help here.

I already ran the lib tests locally (see PR checklist) but they didn't catch the issue in the previous PR either.

@K900
Copy link
Contributor

K900 commented Dec 3, 2024

You want to run lib/tests/release.nix.

@nbraud
Copy link
Contributor Author

nbraud commented Dec 3, 2024

You want to run lib/tests/release.nix.

Thanks for the pointer, and that passes too.

@nbraud
Copy link
Contributor Author

nbraud commented Dec 4, 2024

@infinisil @K900, could one of you OK this (and potentially merge) ?

This is blocking other work on lib.packageFromDirectoryRecursive :3

@nbraud nbraud added 1.severity: blocker This is preventing another PR or issue from being completed needs_reviewer (old Marvin label, do not use) labels Dec 4, 2024
@K900 K900 removed the 1.severity: blocker This is preventing another PR or issue from being completed label Dec 4, 2024
@nbraud
Copy link
Contributor Author

nbraud commented Dec 4, 2024

@K900 Is “severity: blocker” not the appropriate label here? Given that #359984 is stuck in draft mode until this is completed, it fits the description:

This is preventing another PR or issue from being completed.

@K900
Copy link
Contributor

K900 commented Dec 5, 2024

"Blocker" generally refers to things that are blocking major changes, not feature additions.

@nbraud
Copy link
Contributor Author

nbraud commented Dec 5, 2024

"Blocker" generally refers to things that are blocking major changes, not feature additions.

OK, then the label description should be updated to reflect that.

@nbraud
Copy link
Contributor Author

nbraud commented Dec 5, 2024

@Gabriella439, as you reviewed the o.g. PR, would you be willing to review this?
The only difference is the removal of assert pathIsDirectory directory;

Copy link
Member

@infinisil infinisil left a comment

Choose a reason for hiding this comment

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

Didn't have the chance to review this the first time, so here's a late one. Just minor things though, looking good overall :)

lib/filesystem.nix Outdated Show resolved Hide resolved
if pathIsRegularFile defaultPath then
# if `${directory}/package.nix` exists, call it directly
callPackage defaultPath {}
else lib.concatMapAttrs (name: type:
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
else lib.concatMapAttrs (name: type:
else concatMapAttrs (name: type:

And add concatMapAttrs to the import list at the top. A bit annoying, but this is the standard to keep lib more performant.

Copy link
Contributor Author

@nbraud nbraud Dec 12, 2024

Choose a reason for hiding this comment

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

That implies pretty silly things about the (C++) implementation, and seems like a very-premature optimization, especially considering that the filesystem access should be much slower

... but I'm not opposed to doing it either (as well as for lib.removeSuffix) 😅

@nbraud nbraud requested a review from infinisil December 12, 2024 18:08
nbraud added a commit to nbraud/nixpkgs that referenced this pull request Dec 12, 2024
@nbraud
Copy link
Contributor Author

nbraud commented Dec 12, 2024

@infinisil Thanks for catching those, and done!

nbraud and others added 2 commits December 12, 2024 18:48
This is a second take on NixOS#359941, which was reverted by
  940db57.

Co-authored-by: Silvan Mosberger <[email protected]>
Copy link
Member

@infinisil infinisil left a comment

Choose a reason for hiding this comment

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

LGTM! Did you want to squash yourself? Feel free to merge yourself as you wish :)

Comment on lines +367 to +368
inherit (lib) concatMapAttrs removeSuffix;
inherit (lib.path) append;
Copy link
Member

@infinisil infinisil Dec 12, 2024

Choose a reason for hiding this comment

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

Usually this would be added to the very top of this file, but after thinking about it, the performance benefit is also there if you do it here. In any case, that's a tiny detail and not worth nitpicking over further :)

@wegank wegank added the 12.approvals: 1 This PR was reviewed and approved by one reputable person label Dec 15, 2024
@nbraud
Copy link
Contributor Author

nbraud commented Dec 28, 2024

Squashed fixup! commit, no diff (so previous review and CI results remain valid)

@nbraud nbraud force-pushed the lib/fs/packagesFromDir-refactor branch from 6b8521e to 065b480 Compare December 28, 2024 21:10
@nbraud nbraud merged commit f91fbd1 into NixOS:master Dec 28, 2024
18 of 19 checks passed
@nbraud
Copy link
Contributor Author

nbraud commented Dec 28, 2024

Thanks again for the reviews, @infinisil <3

@nbraud nbraud deleted the lib/fs/packagesFromDir-refactor branch December 28, 2024 21:11
khaneliman pushed a commit to khaneliman/nixpkgs that referenced this pull request Dec 28, 2024
github-actions bot pushed a commit to nix-community/nixpkgs.lib that referenced this pull request Dec 29, 2024
(packageDirectoryEntries path);
inherit (lib) concatMapAttrs removeSuffix;
inherit (lib.path) append;
defaultPath = append directory "package.nix";
Copy link
Member

@phanirithvij phanirithvij Jan 4, 2025

Choose a reason for hiding this comment

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

Previously directory could be a string but this forces it to be a path.
But I guess this change is heading in the right direction and users should adapt?

for e.g. https://github.com/9999years/git-prole/blob/68b4ba943a4bbb3d8452c67bbf50b0ba3f58956a/nix/makePackages.nix#L12

thought I could do append /. "string-dir" and pass it as the directory, but it is not allowed either.

Copy link
Contributor Author

@nbraud nbraud Jan 12, 2025

Choose a reason for hiding this comment

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

Oof, good point, that wasn't an intended regression; if it was, at the very least it should be documented as such.

On the one hand, pushing for more-structured path handling makes sense. On the other, breaking an API present in stable releases (esp. in a relatively-subtle way) is not how I'd prefer to push that forward.

I'll shortly prepare a PR to fix this, thanks a lot for the report.
PS: “shortly” might take longer than expected, everything hurts today 😬

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
6.topic: lib The Nixpkgs function library 10.rebuild-darwin: 1-10 10.rebuild-linux: 1-10 12.approvals: 1 This PR was reviewed and approved by one reputable person needs_reviewer (old Marvin label, do not use)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants