Skip to content

lib.licenses: add compound licenses - #468378

Merged
lassulus merged 3 commits into
NixOS:masterfrom
jopejoe1:compound-licenses
Apr 19, 2026
Merged

lassulus merged 3 commits into
NixOS:masterfrom
jopejoe1:compound-licenses

Conversation

@jopejoe1

@jopejoe1 jopejoe1 commented Dec 6, 2025

Copy link
Copy Markdown
Member

This adds support for expressing more complex licenses in nixpkgs by adding functions for the SPDX operators so that we can express AND, OR and WITH in our licenses.

This also adds some helper functions to work with these in check-check meta.

cc: @emilazy @alyssais (for being codeowners of lib.licenses)
cc: @Atemu (for having some discussion over this with me and #283706)

Note that this probably still needs some work, as I did not really get much feedback on this yet.

Things done

  • Built on platform:
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • Tested, as applicable:
  • Ran nixpkgs-review on this PR. See nixpkgs-review usage.
  • Tested basic functionality of all binary files, usually in ./result/bin/.
  • Nixpkgs Release Notes
    • Package update: when the change is major or breaking.
  • NixOS Release Notes
    • Module addition: when adding a new NixOS module.
    • Module update: when the change is significant.
  • Fits CONTRIBUTING.md, pkgs/README.md, maintainers/README.md and other READMEs.

Add a 👍 reaction to pull requests you find important.

@nixpkgs-ci nixpkgs-ci Bot added 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-darwin: 1 This PR causes 1 package to rebuild on Darwin. 6.topic: stdenv Standard environment 6.topic: lib The Nixpkgs function library 6.topic: llvm/clang Issues related to llvmPackages, clangStdenv and related labels Dec 6, 2025
@Aleksanaa

Aleksanaa commented Dec 6, 2025 •

Copy link
Copy Markdown
Member

Might evaluate performance impact, for example intepreting all lists as AND/OR, and see how much more time we will spend on eval?

@Atemu

Atemu commented Dec 6, 2025

Copy link
Copy Markdown
Member

#348238 should be quite similar to this in terms of perf impact and I couldn't find any.

@Atemu Atemu left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is great work, thank you for doing this! :)

Some details I have opinions on but I'm in full support of the core idea.

Comment thread lib/licenses/licenses.nix Resolved
Comment thread lib/licenses/helpers.nix Resolved
Comment thread lib/licenses/operators.nix Outdated
# Arguments

- [base] Possible license to chose from
- [mod] Other possible license to chose from

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nit: I'd prefer a more descriptive name be used for this parameter and attribute name

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

These should now be way better now that it switched. To using lists

Comment thread lib/licenses/helpers.nix Resolved
Comment thread lib/licenses/helpers.nix Resolved
Comment thread lib/licenses/helpers.nix Resolved
Comment thread lib/licenses/helpers.nix Resolved
asl20
llvm-exception
];
# Contributions after June 1st, 2024 are only licensed under asl20 and

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Tangential but this comment was and is very misleading. The relevant info is that, since 19, there is asl20-only code, requiring acceptance of both licenses. Which one of those applies for new contributions is irrelevant.

Comment thread lib/licenses/helpers.nix Resolved
Comment thread lib/licenses/helpers.nix Outdated
# Example

```nix
isRedistributable lib.licenses.mit

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Given that these functions are capable of dealing with composite license expressions, it'd make sense to have examples for those too. (Applies to all of these helpers.)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Added the one from llvm

@Pandapip1 Pandapip1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is there any way to make all the licenses functors so that you could use infix operators (e.g. with lib.licenses; mit OR asl20 would be valid)

@jopejoe1

jopejoe1 commented Dec 6, 2025

Copy link
Copy Markdown
Member Author

@Atemu applied some of your review comments. Some more I still need to work my way through.

@sternenseemann

Copy link
Copy Markdown
Member

Does this include any breaking changes? The pure additions should be backported to 25.11 so expressions can be portable across Nixpkgs versions.

@jopejoe1

jopejoe1 commented Apr 20, 2026 •

Copy link
Copy Markdown
Member Author

Does this include any breaking changes? The pure additions should be backported to 25.11 so expressions can be portable across Nixpkgs versions.

It should not, but it would probably be good if someone did a double-check on this to make sure I did not miss anything regarding that.

Edit: Maybe if some did some weird mapping on lib.licenses?

@jopejoe1 jopejoe1 linked an issue Apr 20, 2026 that may be closed by this pull request
siraben pushed a commit to siraben/nixpkgs that referenced this pull request Apr 20, 2026
With compound licenses[1] recently merged, we can now properly represent
dual licensed packages without affecting its non-free status.

See NixOS#392710 (comment)
[1]: NixOS#468378
aiwao pushed a commit to aiwao/nixpkgs that referenced this pull request Apr 23, 2026
With compound licenses[1] recently merged, we can now properly represent
dual licensed packages without affecting its non-free status.

See NixOS#392710 (comment)
[1]: NixOS#468378
xddxdd added a commit to xddxdd/firefox-addons-nix that referenced this pull request Apr 24, 2026
@eclairevoyant

eclairevoyant commented Apr 25, 2026 •

Copy link
Copy Markdown
Contributor

This is definitely breaking for anyone who uses lib.licenses directly.

KiaraGrouwstra added a commit to NixOS/nixos-search that referenced this pull request Apr 25, 2026
Nixpkgs is introducing compound license expressions (AND, OR, WITH,
PLUS) via NixOS/nixpkgs#468378.  This extends the `License` enum to
deserialize the new `licenseType`-tagged structures, recursively
flattens them into leaf licenses for the search index, and exposes a
`package_license_expression` field carrying the SPDX-style expression
string when compound licenses are present.

Bump import index version to 47 for the new field.
KiaraGrouwstra added a commit to NixOS/nixos-search that referenced this pull request Apr 25, 2026
Nixpkgs is introducing compound license expressions (AND, OR, WITH,
PLUS) via NixOS/nixpkgs#468378.  This extends the `License` enum to
deserialize the new `licenseType`-tagged structures, recursively
flattens them into leaf licenses for the search index, and exposes a
`package_license_expression` field carrying the SPDX-style expression
string when compound licenses are present.

Bump import index version to 47 for the new field.
KiaraGrouwstra added a commit to NixOS/nixos-search that referenced this pull request Apr 25, 2026
Nixpkgs is introducing compound license expressions (AND, OR, WITH,
PLUS) via NixOS/nixpkgs#468378.  This extends the `License` enum to
deserialize the new `licenseType`-tagged structures, recursively
flattens them into leaf licenses for the search index, and exposes a
`package_license_expression` field carrying the SPDX-style expression
string when compound licenses are present.

Bump import index version to 47 for the new field.
KiaraGrouwstra added a commit to NixOS/nixos-search that referenced this pull request May 3, 2026
Nixpkgs is introducing compound license expressions (AND, OR, WITH,
PLUS) via NixOS/nixpkgs#468378.  This extends the `License` enum to
deserialize the new `licenseType`-tagged structures, recursively
flattens them into leaf licenses for the search index, and exposes a
`package_license_expression` field carrying the SPDX-style expression
string when compound licenses are present.

Bump import index version to 47 for the new field.
KiaraGrouwstra added a commit to NixOS/nixos-search that referenced this pull request May 3, 2026
Nixpkgs is introducing compound license expressions (AND, OR, WITH,
PLUS) via NixOS/nixpkgs#468378.  This extends the `License` enum to
deserialize the new `licenseType`-tagged structures, recursively
flattens them into leaf licenses for the search index, and exposes a
`package_license_expression` field carrying the SPDX-style expression
string when compound licenses are present.

Bump import index version to 47 for the new field.
KiaraGrouwstra added a commit to NixOS/nixos-search that referenced this pull request May 3, 2026
Nixpkgs is introducing compound license expressions (AND, OR, WITH,
PLUS) via NixOS/nixpkgs#468378.  This extends the `License` enum to
deserialize the new `licenseType`-tagged structures, recursively
flattens them into leaf licenses for the search index, and exposes a
`package_license_expression` field carrying the SPDX-style expression
string when compound licenses are present.

Bump import index version to 47 for the new field.
KiaraGrouwstra added a commit to NixOS/nixos-search that referenced this pull request May 3, 2026
Nixpkgs is introducing compound license expressions (AND, OR, WITH,
PLUS) via NixOS/nixpkgs#468378.  This extends the `License` enum to
deserialize the new `licenseType`-tagged structures, recursively
flattens them into leaf licenses for the search index, and exposes a
`package_license_expression` field carrying the SPDX-style expression
string when compound licenses are present.

Bump import index version to 47 for the new field.
raboof pushed a commit to NixOS/nixos-search that referenced this pull request May 4, 2026
Nixpkgs is introducing compound license expressions (AND, OR, WITH,
PLUS) via NixOS/nixpkgs#468378.  This extends the `License` enum to
deserialize the new `licenseType`-tagged structures, recursively
flattens them into leaf licenses for the search index, and exposes a
`package_license_expression` field carrying the SPDX-style expression
string when compound licenses are present.

Bump import index version to 47 for the new field.
xddxdd added a commit to xddxdd/firefox-addons-nix that referenced this pull request May 13, 2026
@nixos-discourse

Copy link
Copy Markdown

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/compound-licenses/78532/2

@SomeoneSerge

SomeoneSerge commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Hi! Moving the allowUnfreePredicate function signature convo from #550208 (comment) to over here.

I believe there's a case to be made that:

  • ...prior to this PR, allowUnfreePredicate had a fairly well established signature (String|License | [String|License]) -> Bool, where License includes, at the least, the outputs of mkLicense;
  • that this PR narrows the signature;
  • trivially, this PR is a breaking change, but that's besides the point.

Questions:

  • what's the arrangement for the Nixpkgs User to communicate, in case of an OR license, which one (if any) they choose to opt into?
    • do we plan to ship a SAT solver for copyright, if not for semver?
  • I'm looking from outside and didn't read the diff, but my guess is the allowUnfreePredicate should remain a "visitor" with the old signature, and so check-meta should call it from within some kind of a license-tree-traversal boilerplate. Wbu @jopejoe1?

PS Can't resist pointing out the obvious irony of shipping a more elaborate copyright management logic at the same time as legalizing LLM outputs in the core project 🙃

@jopejoe1

jopejoe1 commented Sep 7, 2026

Copy link
Copy Markdown
Member Author

...prior to this PR, allowUnfreePredicate had a fairly well established signature (String|License | [String|License]) -> Bool, where License includes, at the least, the outputs of mkLicense;
that this PR narrows the signature;
trivially, this PR is a breaking change, but that's besides the point.

That was mostly the case but not always as I started working on this and #451424 (which introduced the enforcement of valid check-meta), but even that only check if it's an (String|Attr | [String|Attr]), I think I removed most cases where that was not the case, but could be that there were some I missed.

what's the arrangement for the Nixpkgs User to communicate, in case of an OR license, which one (if any) they choose to opt into?

They don't, if they accepted one of the license in it that gets used.

do we plan to ship a SAT solver for copyright, if not for semver?

I'm not planing to ship anything more complicated than what was included in this pr.

I'm looking from outside and didn't read the diff, but my guess is the allowUnfreePredicate should remain a "visitor" with the old signature, and so check-meta should call it from within some kind of a license-tree-traversal boilerplate. Wbu @jopejoe1?

allowUnfreePredicate and all the other license checks should be moved to meta.problems

PS Can't resist pointing out the obvious irony of shipping a more elaborate copyright management logic at the same time as legalizing LLM outputs in the core project 🙃

Was working on this longer that that was such a prevalent topic in nixpkgs and TBH all these AI-contributes kinda take a way my fun on reviewing and writing prs. (NixOS is a hobby for me)

@SomeoneSerge

Copy link
Copy Markdown
Contributor

"They don't" and "if they accepted one [...], that gets used" are mutually exclusive as I understand them? In particular, I think (finding and) using the "one that they accepted" is a form of SAT, albeit with a greedy solution...

allowUnfreePredicate and all the other license checks should be moved to meta.problems

I don't think we have a machinery for that ready, do we?
In any case, I'm of the opinion that we should do something about the signature issue before the release, and reverting good work like this is barely an option...

...all these AI-contributes kinda take a way my fun on reviewing and writing prs. (NixOS is a hobby for me)

I can relate...

@diogotcorreia diogotcorreia mentioned this pull request Sep 9, 2026
2 of 13 tasks
@gepbird gepbird mentioned this pull request Sep 23, 2026
13 tasks
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 6.topic: llvm/clang Issues related to llvmPackages, clangStdenv and related 6.topic: stdenv Standard environment 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. 12.approvals: 3+ This PR was reviewed and approved by three or more persons.

Projects

Status: Done
Status: Done

Development

Successfully merging this pull request may close these issues.

licenses: composite licenses