mirror of
https://github.com/nix-community/dream2nix.git
synced 2024-12-01 02:31:28 +03:00
feat: add license extraction for nodejs and rust
This commit is contained in:
parent
c2ebb96bf2
commit
2ec675e394
@ -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;
|
||||
};
|
||||
|
@ -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;
|
||||
};
|
||||
|
@ -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
|
||||
|
@ -216,6 +216,10 @@
|
||||
|
||||
inherit pname;
|
||||
|
||||
meta = {
|
||||
licenses = l.map (name: l.licenses.${name}) subsystemAttrs.licenses;
|
||||
};
|
||||
|
||||
passthru.dependencies = passthruDeps;
|
||||
|
||||
passthru.devShell = import ./devShell.nix {
|
||||
|
@ -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
|
||||
|
@ -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:
|
||||
|
@ -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:
|
||||
|
@ -112,6 +112,12 @@
|
||||
${utils.writeCargoLock}
|
||||
'';
|
||||
passthru = {dependencies = deps;};
|
||||
meta = {
|
||||
licenses =
|
||||
l.map
|
||||
(name: l.licenses.${name})
|
||||
subsystemAttrs.licenses.${pname}.${version};
|
||||
};
|
||||
};
|
||||
in
|
||||
produceDerivation
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user