mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-06-13 05:05:29 +03:00
lib.meta.licensesSpdx: mapping from SPDX ID to licenses
This commit is contained in:
parent
bd17d739a8
commit
d04697aee8
1 changed files with 31 additions and 3 deletions
34
lib/meta.nix
34
lib/meta.nix
|
@ -286,6 +286,32 @@ rec {
|
||||||
((!pkg?meta.platforms) || any (platformMatch platform) pkg.meta.platforms) &&
|
((!pkg?meta.platforms) || any (platformMatch platform) pkg.meta.platforms) &&
|
||||||
all (elem: !platformMatch platform elem) (pkg.meta.badPlatforms or []);
|
all (elem: !platformMatch platform elem) (pkg.meta.badPlatforms or []);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Mapping of SPDX ID to the attributes in lib.licenses.
|
||||||
|
|
||||||
|
For SPDX IDs, see https://spdx.org/licenses
|
||||||
|
|
||||||
|
# Examples
|
||||||
|
:::{.example}
|
||||||
|
## `lib.meta.licensesSpdx` usage example
|
||||||
|
|
||||||
|
```nix
|
||||||
|
lib.licensesSpdx.MIT == lib.licenses.mit
|
||||||
|
=> true
|
||||||
|
lib.licensesSpdx."MY LICENSE"
|
||||||
|
=> error: attribute 'MY LICENSE' missing
|
||||||
|
```
|
||||||
|
|
||||||
|
:::
|
||||||
|
*/
|
||||||
|
licensesSpdx =
|
||||||
|
lib.attrsets.mapAttrs'
|
||||||
|
(_key: license: {
|
||||||
|
name = license.spdxId;
|
||||||
|
value = license;
|
||||||
|
})
|
||||||
|
(lib.attrsets.filterAttrs (_key: license: license ? spdxId) lib.licenses);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Get the corresponding attribute in lib.licenses from the SPDX ID
|
Get the corresponding attribute in lib.licenses from the SPDX ID
|
||||||
or warn and fallback to `{ shortName = <license string>; }`.
|
or warn and fallback to `{ shortName = <license string>; }`.
|
||||||
|
@ -361,10 +387,12 @@ rec {
|
||||||
*/
|
*/
|
||||||
getLicenseFromSpdxIdOr =
|
getLicenseFromSpdxIdOr =
|
||||||
let
|
let
|
||||||
spdxLicenses = lib.mapAttrs (id: ls: assert lib.length ls == 1; builtins.head ls)
|
lowercaseLicenses = lib.mapAttrs' (name: value: {
|
||||||
(lib.groupBy (l: lib.toLower l.spdxId) (lib.filter (l: l ? spdxId) (lib.attrValues lib.licenses)));
|
name = lib.toLower name;
|
||||||
|
inherit value;
|
||||||
|
}) licensesSpdx;
|
||||||
in licstr: default:
|
in licstr: default:
|
||||||
spdxLicenses.${ lib.toLower licstr } or default;
|
lowercaseLicenses.${ lib.toLower licstr } or default;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Get the path to the main program of a package based on meta.mainProgram
|
Get the path to the main program of a package based on meta.mainProgram
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue