mirror of
https://github.com/NixOS/nixpkgs.git
synced 2026-07-06 17:13:24 -05:00
nixpkgs: pass lib to config function
Nixpkgs config, for defining things like which licenses are
permitted, can either be an attrset or a function that is passed a
`pkgs` argument. Evaluating that `pkgs` argument requires computing the
Nixpkgs fixpoint, which requires checking whether the derivations used
in the Nixpkgs bootstrap have valid licenses. This works provided
nothing tries to use Nixpkgs functions to validate or merge anything
included in the configuration.
f5deefd463 (config: add and document {allow,block}listedLicenses,
2025-08-31), in #437723, added type checking and merging to the lists of
permitted/forbidden licenses. That resulted in a recursion loop if a
list of licenses included, say, `pkgs.lib.licenses.bsd0`.
To allow licenses to be specified from Nixpkgs' library, pass `lib` as
well as `pkgs` to any config function. Computing `lib` doesn't require
working out the full Nixpkgs fixpoint. The change in #437723 will still
break things for some people, but it at least provides a sensible route
to getting the config working again.
Fixes #456994.
This commit is contained in:
parent
85caf37a9a
commit
8e94561d62
3 changed files with 29 additions and 3 deletions
|
|
@ -9,6 +9,32 @@
|
|||
- Node.js default version has been updated from 22 LTS to 24 LTS.
|
||||
This introduces some breaking changes; Refer to the [upstream migration article](https://nodejs.org/en/blog/migrations/v22-to-v24) for details.
|
||||
|
||||
- Nixpkgs configuration, specified for NixOS using `nixpkgs.config`, or using the `config` argument when importing nixpkgs, has learned to accept a `lib` argument as well as `pkgs`, which allows the configuration to be computed without depending on the `pkgs` fixed point. If you are referencing licenses in `lib.licenses` by having this configuration be a function taking a `pkgs` arg, you may wish to change to using `lib` for faster computation and to avoid infinite recursion errors if pkgs depends on parts of the computed configuration in future.
|
||||
|
||||
For example, if you currently have configuration that looks like this:
|
||||
|
||||
{ pkgs, ... }:
|
||||
{
|
||||
allowlistedLicenses = [ pkgs.lib.licenses.nasa13 ];
|
||||
blocklistedLicenses = with pkgs.lib.licenses; [ gpl3Only gpl3Plus ];
|
||||
}
|
||||
|
||||
You may wish to update it to something like this:
|
||||
|
||||
{ lib, ... }:
|
||||
{
|
||||
allowlistedLicenses = [ lib.licenses.nasa13 ];
|
||||
blocklistedLicenses = with lib.licenses; [ gpl3Only gpl3Plus ];
|
||||
}
|
||||
|
||||
Or, if you need configuration that works with both 26.05 and 25.11:
|
||||
|
||||
{ pkgs, lib ? pkgs.lib, ... }:
|
||||
{
|
||||
allowlistedLicenses = [ lib.licenses.nasa13 ];
|
||||
blocklistedLicenses = with lib.licenses; [ gpl3Only gpl3Plus ];
|
||||
}
|
||||
|
||||
## Backward Incompatibilities {#sec-nixpkgs-release-26.05-incompatibilities}
|
||||
|
||||
<!-- To avoid merge conflicts, consider adding your item at an arbitrary place in the list instead. -->
|
||||
|
|
|
|||
|
|
@ -16,8 +16,8 @@ let
|
|||
mergeConfig =
|
||||
lhs_: rhs_:
|
||||
let
|
||||
lhs = optCall lhs_ { inherit pkgs; };
|
||||
rhs = optCall rhs_ { inherit pkgs; };
|
||||
lhs = optCall lhs_ { inherit lib pkgs; };
|
||||
rhs = optCall rhs_ { inherit lib pkgs; };
|
||||
in
|
||||
lib.recursiveUpdate lhs rhs
|
||||
// lib.optionalAttrs (lhs ? packageOverrides) {
|
||||
|
|
|
|||
|
|
@ -109,7 +109,7 @@ let
|
|||
# Allow both:
|
||||
# { /* the config */ } and
|
||||
# { pkgs, ... } : { /* the config */ }
|
||||
config1 = if lib.isFunction config0 then config0 { inherit pkgs; } else config0;
|
||||
config1 = if lib.isFunction config0 then config0 { inherit lib pkgs; } else config0;
|
||||
|
||||
configEval = lib.evalModules {
|
||||
modules = [
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue