1
0
Fork 1
mirror of https://github.com/NixOS/nixpkgs.git synced 2024-11-17 11:10:03 +00:00

lib.meta: Minor SPDX license function improvements

- 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
This commit is contained in:
Silvan Mosberger 2024-08-25 00:57:44 +02:00
parent d04697aee8
commit f55a4b99ef
2 changed files with 11 additions and 6 deletions

View file

@ -123,7 +123,8 @@ let
inherit (self.derivations) lazyDerivation optionalDrvAttr;
inherit (self.meta) addMetaAttrs dontDistribute setName updateName
appendToName mapDerivationAttrset setPrio lowPrio lowPrioSet hiPrio
hiPrioSet getLicenseFromSpdxId getLicenseFromSpdxIdOr getExe getExe';
hiPrioSet licensesSpdx getLicenseFromSpdxId getLicenseFromSpdxIdOr
getExe getExe';
inherit (self.filesystem) pathType pathIsDirectory pathIsRegularFile
packagesFromDirectoryRecursive;
inherit (self.sources) cleanSourceFilter

View file

@ -7,6 +7,7 @@
let
inherit (lib) matchAttrs any all isDerivation getBin assertMsg;
inherit (lib.attrsets) mapAttrs' filterAttrs;
inherit (builtins) isString match typeOf;
in
@ -289,7 +290,8 @@ rec {
/**
Mapping of SPDX ID to the attributes in lib.licenses.
For SPDX IDs, see https://spdx.org/licenses
For SPDX IDs, see https://spdx.org/licenses.
Note that some SPDX licenses might be missing.
# Examples
:::{.example}
@ -305,18 +307,19 @@ rec {
:::
*/
licensesSpdx =
lib.attrsets.mapAttrs'
mapAttrs'
(_key: license: {
name = license.spdxId;
value = license;
})
(lib.attrsets.filterAttrs (_key: license: license ? spdxId) lib.licenses);
(filterAttrs (_key: license: license ? spdxId) lib.licenses);
/**
Get the corresponding attribute in lib.licenses from the SPDX ID
or warn and fallback to `{ shortName = <license string>; }`.
For SPDX IDs, see https://spdx.org/licenses
For SPDX IDs, see https://spdx.org/licenses.
Note that some SPDX licenses might be missing.
# Type
@ -351,7 +354,8 @@ rec {
Get the corresponding attribute in lib.licenses from the SPDX ID
or fallback to the given default value.
For SPDX IDs, see https://spdx.org/licenses
For SPDX IDs, see https://spdx.org/licenses.
Note that some SPDX licenses might be missing.
# Inputs