@@ -1,6 +1,7 @@
11{ pkgs ? import <nixpkgs> {}
22, nodejs ? pkgs.nodejs
33, yarn ? pkgs.yarn
4+, allowAliases ? pkgs.config.allowAliases or true
45}:
56
67let
@@ -9,6 +10,14 @@ let
910 compose = f: g: x: f (g x);
1011 id = x: x;
1112 composeAll = builtins.foldl' compose id;
13+
14+ # https://docs.npmjs.com/files/package.json#license
15+ # TODO: support expression syntax (OR, AND, etc)
16+ getLicenseFromSpdxId = licstr:
17+ if licstr == "UNLICENSED" then
18+ lib.licenses.unfree
19+ else
20+ lib.getLicenseFromSpdxId licstr;
1221in rec {
1322 # Export yarn again to make it easier to find out which yarn was used.
1423 inherit yarn;
@@ -30,16 +39,7 @@ in rec {
3039 non-null = builtins.filter (x: x != null) parts;
3140 in builtins.concatStringsSep "-" non-null;
3241
33− # https://docs.npmjs.com/files/package.json#license
34− # TODO: support expression syntax (OR, AND, etc)
35− spdxLicense = licstr:
36− if licstr == "UNLICENSED" then
37− lib.licenses.unfree
38− else
39− lib.findFirst
40− (l: l ? spdxId && l.spdxId == licstr)
41− { shortName = licstr; }
42− (builtins.attrValues lib.licenses);
42+ inherit getLicenseFromSpdxId;
4343
4444 # Generates the yarn.nix from the yarn.lock file
4545 mkYarnNix = { yarnLock, flags ? [] }:
@@ -369,7 +369,7 @@ in rec {
369369 description = packageJSON.description or "";
370370 homepage = packageJSON.homepage or "";
371371 version = packageJSON.version or "";
372− license = if packageJSON ? license then spdxLicense packageJSON.license else "";
372+ license = if packageJSON ? license then getLicenseFromSpdxId packageJSON.license else "";
373373 } // (attrs.meta or {});
374374 });
375375
@@ -437,4 +437,7 @@ in rec {
437437
438438 patchShebangs $out
439439 '';
440+} // lib.optionalAttrs allowAliases {
441+ # Aliases
442+ spdxLicense = getLicenseFromSpdxId; # added 2021-12-01
440443}