feat: add license extraction for nodejs and rust

This commit is contained in:
Yusuf Bera Ertan 2022-09-13 21:02:43 +03:00
parent c2ebb96bf2
commit 2ec675e394
No known key found for this signature in database
GPG Key ID: 1D8F8FAF2294D6EA
9 changed files with 55 additions and 4 deletions

View File

@ -1,6 +1,6 @@
{
inputs = {
dream2nix.url = "github:nix-community/dream2nix";
dream2nix.url = "path:../..";
src.url = "github:prettier/prettier/2.4.1";
src.flake = false;
};

View File

@ -1,6 +1,6 @@
{
inputs = {
dream2nix.url = "github:nix-community/dream2nix";
dream2nix.url = "path:../..";
src.url = "github:BurntSushi/ripgrep/13.0.0";
src.flake = false;
};

View File

@ -34,6 +34,7 @@
traceJ
modules
warnIfIfd
parseSpdxId
;
inherit
@ -322,5 +323,21 @@
(ifdWarningEnabled && module.type == "ifd")
(ifdWarnMsg module)
val;
idToLicenseKey =
l.mapAttrs'
(n: v: l.nameValuePair (l.toLower (v.spdxId or v.fullName or n)) n)
l.licenses;
# Parses a string like "Unlicense OR MIT" to `["unlicense" "mit"]`
# TODO: this does not parse `AND` or `WITH` or paranthesis, so it is
# pretty hacky in how it works. But for most cases this should be okay.
parseSpdxId = _id: let
# some spdx ids might have paranthesis around them
id = l.removePrefix "(" (l.removeSuffix ")" _id);
licenseStrings = l.map l.toLower (l.splitString " OR " id);
_licenses = l.map (string: idToLicenseKey.${string} or null) licenseStrings;
licenses = l.filter (license: license != null) _licenses;
in
licenses;
in
dlib

View File

@ -216,6 +216,10 @@
inherit pname;
meta = {
licenses = l.map (name: l.licenses.${name}) subsystemAttrs.licenses;
};
passthru.dependencies = passthruDeps;
passthru.devShell = import ./devShell.nix {

View File

@ -170,7 +170,10 @@
subsystemName = "nodejs";
subsystemAttrs = {nodejsVersion = b.toString args.nodejs;};
subsystemAttrs = {
nodejsVersion = b.toString args.nodejs;
licenses = dlib.parseSpdxId (packageJson.license or "");
};
# functions
serializePackages = inputData: let

View File

@ -140,7 +140,10 @@
subsystemName = "nodejs";
subsystemAttrs = {nodejsVersion = b.toString args.nodejs;};
subsystemAttrs = {
nodejsVersion = b.toString args.nodejs;
licenses = dlib.parseSpdxId (packageJson.license or "");
};
keys = {
yarnName = rawObj: finalObj:

View File

@ -3,6 +3,7 @@
build = {
lib,
dlib,
pkgs,
...
} @ topArgs: {
@ -60,6 +61,13 @@
${replacePaths}
${utils.writeCargoLock}
'';
meta = {
licenses =
l.map
(name: l.licenses.${name})
subsystemAttrs.licenses.${pname}.${version};
};
});
mkShellForPkg = pkg:

View File

@ -112,6 +112,12 @@
${utils.writeCargoLock}
'';
passthru = {dependencies = deps;};
meta = {
licenses =
l.map
(name: l.licenses.${name})
subsystemAttrs.licenses.${pname}.${version};
};
};
in
produceDerivation

View File

@ -251,6 +251,16 @@ in {
gitDeps = l.filter (dep: (getSourceTypeFrom dep) == "git") parsedDeps;
in
l.unique (l.map (dep: parseGitSource dep) gitDeps);
licenses = l.foldl' l.recursiveUpdate {} (
l.map
(
package: let
pkg = package.value.package;
licenses = dlib.parseSpdxId (pkg.license or "");
in {${pkg.name}.${pkg.version} = licenses;}
)
cargoPackages
);
};
defaultPackage = package.name;