Nice, lib.packagesFromDirectoryRecursive now supports nested scopes!

packagesFromDirectoryRecursive transforms a directory tree of packages into a nested attribute set of derivations. You can use it to manage a package set in a similar way to by-name in nixpkgs (without the sharding part). The package files in tree must be suitable for callPackage.

Subdirectories in the tree result in nested attribute sets. In the following example, packages d, e and f will be in a nested attribute set called my-namespace.

my-packages
├── a.nix
├── b.nix
├── c
│ ├── my-extra-feature.patch
│ ├── package.nix
│ └── support-definitions.nix
└── my-namespace
├── d.nix
├── e.nix
└── f
└── package.nix

Previously, this would only use one scope (my-packages), so e could only depend on d as my-packages.d. With the introduction of nested scopes, e can refer to d within the same scope directly.

PR: https://github.com/NixOS/nixpkgs/pull/392800

function doc on noogle (which isn't yet updated for the new behavior): https://noogle.dev/f/lib/packagesFromDirectoryRecursive

#Nix #NixOS #nixpkgs

lib.packagesFromDirectoryRecursive: use explicit recursion, support nested scopes by katexochen · Pull Request #392800 · NixOS/nixpkgs

Supersedes #359984, as the author isn't responding. I squashed in the fixup commits (had to split them up as they wouldn't apply) and resolved merge conflicts with master. Original PR descr...

GitHub
@katexochen Great ! I wonder if I will have to update my project based on this change, if you have some tips, let me know !
PR: https://github.com/drupol/pkgs-by-name-for-flake-parts/pull/2
feat: Refer to other packages from same `pkgsDirectory` by xieve · Pull Request #2 · drupol/pkgs-by-name-for-flake-parts

Closes #1. Refactored the flattening function to be a lot simpler Moved the packagesFromDirectoryRecursive call into the makeScope call, thereby allowing the definition of interdependent packages ...

GitHub
@Pol The only breaking change is that the func will now reject unknown arguments/files. Checkout the updated function documentation in the PR. I don't expect this to affect your project, but let me know it it does.
@katexochen I will check tomorrow. I also want to know if what is implemented in my project can perhaps now be removed in favor of what you did.

@katexochen oooh love this! Import logic is what I waste the bulk of my time doing in most of my Nix repos.

Is there similar for generic imports?

Would love for a lib that lets me call whatever function instead of `callPackage` on the same tree structure. Would make so many external scaffolding projects largely redundant.

If not, I might have to make one.

@Lehmanator I don't think there is such a func in nixpkgs.lib, but if you look at the packagesFromDirectory recursive implementation, it shouldn't be too hard to write your own to do so. :)
@katexochen That's probably what I'll end up doing then! I have written so many half-assed versions of this, would be nice to consolidate them around something I can upstream into nixpkgs.
dotfiles/nixos/flake.nix at master · xieve/dotfiles

Contribute to xieve/dotfiles development by creating an account on GitHub.

GitHub
@xieve bookmarking for later. this looks like a cleaner version of what I'm currently doing