lib.packagesFromDirectoryRecursive: reject unknown arguments

see [discussion](https://github.com/NixOS/nixpkgs/pull/270537#discussion_r1862458435)
This commit is contained in:
nicoo 2024-12-03 16:27:30 +00:00 committed by Paul Meyer
parent 6cc285d613
commit 93d76b7344
2 changed files with 14 additions and 24 deletions

View file

@ -69,6 +69,9 @@
- The `virtualisation.hypervGuest.videoMode` option has been removed. Standard tooling can now be used to configure display modes for Hyper-V VMs.
- [`lib.packagesFromDirectoryRecursive`] now rejects unknown arguments.
[`lib.packagesFromDirectoryRecursive`]: https://nixos.org/manual/nixpkgs/stable/#function-library-lib.filesystem.packagesFromDirectoryRecursive
### Deprecations {#sec-nixpkgs-release-25.05-lib-deprecations}
- `functor` is an implementation detail and should not be relied upon, but since its status wasn't clear and it has had some use cases without alternatives, changes are being handled as gracefully as possible. Deprecations within functor:
@ -85,6 +88,6 @@
- `rustPlatform.buildRustPackage` stops handling the deprecated argument `cargoSha256`. Out-of-tree packages that haven't migrated from `cargoSha256` to `cargoHash` now receive errors.
### Other notable changes {#sec-release-25.05-lib-notable-changes}
### Additions and Improvements {#sec-nixpkgs-release-25.05-lib-additions-improvements}
- `lib.packagesFromDirectoryRecursive` can now construct nested scopes matching the directory tree passed as input.
- [`lib.packagesFromDirectoryRecursive`] can now construct nested scopes matching the directory tree passed as input.

View file

@ -311,7 +311,7 @@ in
newScope? :: AttrSet -> scope,
directory :: Path,
recurseIntoDirectory? :: (args -> AttrSet) -> args -> AttrSet,
...
recurseArgs? :: Any
}) -> AttrSet
```
@ -349,6 +349,9 @@ in
```
:::
`recurseArgs`
: Optional argument, which can be hold data used by `recurseIntoDirectory`
# Examples
:::{.example}
## Basic use of `lib.packagesFromDirectoryRecursive`
@ -438,28 +441,12 @@ in
in
{
callPackage,
newScope ? throw "lib.packagesFromDirectoryRecursive: newScope wasn't passed in args",
directory,
# recurseIntoDirectory can modify the function used when processing directory entries; see nixdoc above
recurseIntoDirectory ?
if args ? newScope then
# `processDir` is the same function as defined above
# `args` are the arguments passed to (this recursive call of) `packagesFromDirectoryRecursive`
processDir: { newScope, ... }@args:
# Create a new scope and mark it `recurseForDerivations`.
# This lets the packages refer to each other.
# See:
# [lib.makeScope](https://nixos.org/manual/nixpkgs/unstable/#function-library-lib.customisation.makeScope) and
# [lib.recurseIntoAttrs](https://nixos.org/manual/nixpkgs/unstable/#function-library-lib.customisation.makeScope)
recurseIntoAttrs (makeScope newScope (self:
# generate the attrset representing the directory, using the new scope's `callPackage` and `newScope`
processDir (args // {
inherit (self) callPackage newScope;
})
))
else
# otherwise, no modification is necessary
id,
...
# recurseIntoDirectory can modify the function used when processing directory entries
# and recurseArgs can (optionally) hold data for its use ; see function documentation
recurseArgs ? throw "lib.packagesFromDirectoryRecursive: recurseArgs wasn't passed in args",
recurseIntoDirectory ? defaultRecurse,
}@args:
let
defaultPath = append directory "package.nix";