-
-
Notifications
You must be signed in to change notification settings - Fork 13.8k
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.meta.licensesSpdx: mapping from SPDX ID to compatible licenses #333953
Conversation
Would the recently-merged |
Not sure how I missed that, but it's super useful! It'll work for the current PR I'm working on that needed this, so I'm perfectly fine with closing, although I do think it's useful to expose nonetheless (though I do realise the quality of this PR, so it'd have to be a different one regardless) :) But perhaps the |
If we could go back in time, I might prefer @infinisil Is there an idiomatic approach in Nixpkgs when referencing an attribute set mapping? |
Honestly I think they both have their uses. What do you think about changing this to something like I doubt it really matters for a function like this (simple task; so few licenses; and afaik the thunk should be cached anyway).... but does the implementation matter much? I'm not sure which of the two implementations are more performant here — and regardless it seems like premature optimization, but nix isn't exactly known to be performant, so better safe than sorry? # getLicenseFromSpdxIdOr
lib.mapAttrs
(id: ls: assert lib.length ls == 1; builtins.head ls)
# why the groupBy? when would there be duplicate licenses? (if this is a general concern, maybe it should be added as an assert to licenses itself?)
(lib.groupBy
(l: lib.toLower l.spdxId)
(lib.filter (l: l ? spdxId)
(lib.attrValues lib.licenses)))
# this PR
lib.attrsets.mapAttrs'
(_key: license: {
name = license.spdxId;
value = license;
})
(lib.attrsets.filterAttrs (_key: license: license ? spdxId) lib.licenses) Regardless, I'll rework this PR to what I mentioned, if anything just to experiment a bit! :) |
a014ea9
to
947058c
Compare
947058c
to
d04697a
Compare
@ShamrockLee check out this version :) I think this is significantly better. Not sure if it's worth exposing |
Nice, that's a good idea! |
This reminds me that we deliberately eliminate case differences during SPDX ID matching in A function like |
- Expose `lib.licensesSpdx` - Create bindings for the needed internal functions - Mention that some SPDX licenses might be missing (in the future I hope we can autogenerate the Nixpkgs license list from some SPDX endpoint
Tbh we shouldn't add symbols/functions when other functions already work, but in this case I do agree with both of you that just exposing the SPDX ID mapping would've been the better design from the start, so I think it's fine :) I took the liberty to push some suggestions directly, I hope you don't mind! Let me know if they look good, then let's merge 🚀 |
Oh only just saw this now. I do wonder about that, because I'm now thinking that we could have a function like |
More sidenotes: The list of licenses should ideally be automatically generated from the SPDX list directly somehow, and regularly updated, such that we don't even have to worry about that, and always have all the licenses available. |
I'm very much in favor of this, but wouldn't it almost be better to integrate it into Nix(CPP) itself? I'd venture to guess it fits the bill for a
oh, crap. Did I forgot to actually make it usable? .... either way, thanks for the cleanup! I don't know if there's anything left to do or discuss, other than perhaps for other people to review it, but I'll take the PR out of draft mode nonetheless. :) |
I think in general we only need builtins if a non-builtin would be too inefficient, which I don't think is the case here :)
Nah, it was just only usable as |
Description of changes
Adds a mapping from SPDX IDs to the licenses defined in
lib.licenses
, available inlib.licenses-spdx
.I've needed this several times, so figured I'd add it to the lib. Do let me know if this is appropriate! :)
This is my first non-package contribution to Nix, so of course any and all feedback is welcome! :) (although hopefully there isn't much to say about such a simple change)
Things done
nix.conf
? (See Nix manual)sandbox = relaxed
sandbox = true
nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD"
. Note: all changes have to be committed, also see nixpkgs-review usage./result/bin/
)Add a 👍 reaction to pull requests you find important.