Skip to content

Commit

Permalink
move extra info to subsystemAttrs
Browse files Browse the repository at this point in the history
  • Loading branch information
wmertens committed Aug 21, 2022
1 parent 9290337 commit 0c0ce5d
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 55 deletions.
25 changes: 14 additions & 11 deletions src/subsystems/nodejs/builders/granular/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@
(
dep: let
p = allPackages."${dep.name}"."${dep.version}";
s = p.sourceInfo;
s = p.extraInfo;
in
# this dep is a cyclee
!(isCyclee dep.name dep.version)
Expand Down Expand Up @@ -244,7 +244,7 @@
myDeps =
lib.filter
(dep: let
s = dep.sourceInfo;
s = dep.extraInfo;
in
(withOptionals || !(s.optional or false))
&& (!isMain || (withDev || !(s.dev or false))))
Expand Down Expand Up @@ -349,14 +349,13 @@
then null
else pkgs."electron_${electronVersionMajor}".headers;

sourceInfo = let
e = getSourceSpec name version;
try = builtins.tryEval (builtins.deepSeq e e);
in
if try.success
then try.value
else {};
hasInstall = !(sourceInfo.noInstall or false);
hasExtraInfo = subsystemAttrs ? extraInfo;
extraInfo = subsystemAttrs.extraInfo.${name}.${version} or {};
# If the translator doesn't provide extraInfo, assume scripts
hasInstall =
if hasExtraInfo
then extraInfo.hasInstallScript or false
else true;
isMain = isMainPackage name version;

pkg = produceDerivation name (stdenv.mkDerivation rec {
Expand Down Expand Up @@ -587,6 +586,10 @@
# Runs the install command which defaults to 'npm run postinstall'.
# Allows using custom install command by overriding 'buildScript'.
# TODO this logic supposes a build script, which is not documented
# for installing, we only need to run `npm run install` (pre and post scripts run automatically)
# https://github.com/npm/npm/issues/5919
# TODO build first if has build, give it devModules during build

buildPhase = ''
runHook preBuild
Expand Down Expand Up @@ -657,7 +660,7 @@
});
in
pkg
// {inherit sourceInfo;};
// {inherit extraInfo;};
in
outputs;
}
68 changes: 40 additions & 28 deletions src/subsystems/nodejs/translators/package-lock-v2/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,28 @@

rootDependencies = resolved.self.deps;

identifyGitSource = dependencyObject:
identifyGitSource = dep:
# TODO: when integrity is there, and git url is github then use tarball instead
# ! (dependencyObject ? integrity) &&
dlib.identifyGitUrl dependencyObject.url;
# ! (dep ? integrity) &&
dlib.identifyGitUrl dep.url;

getVersion = dependencyObject: dependencyObject.version;
getVersion = dep: dep.version;

getPath = dependencyObject:
lib.removePrefix "file:" dependencyObject.url;
getPath = dep:
lib.removePrefix "file:" dep.url;

stripDep = dep: l.removeAttrs dep ["pname" "version" "deps"];
getSource = {
url,
hash,
...
}: {inherit url hash;};

# TODO check that this works with workspaces
extraInfo = b.foldl' (acc: dep:
if dep.extra != {}
then l.recursiveUpdate acc {${dep.pname}.${dep.version} = dep.extra;}
else acc) {}
resolved.allDeps;
in
utils.simpleTranslate
({
Expand All @@ -81,40 +92,41 @@

subsystemName = "nodejs";

subsystemAttrs = {nodejsVersion = args.nodejs;};
subsystemAttrs = {
inherit extraInfo;
nodejsVersion = args.nodejs;
};

# functions
serializePackages = inputData: inputData;

getName = dependencyObject: dependencyObject.pname;
getName = dep: dep.pname;

inherit getVersion;

# TODO handle npm link maybe?
getSourceType = dependencyObject:
if identifyGitSource dependencyObject
then "git"
else if lib.hasPrefix "file:" dependencyObject.url
# TODO handle npm link maybe? not sure what it looks like in lock
getSourceType = dep:
if lib.hasPrefix "file:" dep.url
then "path"
else if identifyGitSource dep
then "git"
else "http";

sourceConstructors = {
git = dependencyObject:
(stripDep dependencyObject)
// (dlib.parseGitUrl dependencyObject.url);

http = dependencyObject: (stripDep dependencyObject);

path = dependencyObject:
(stripDep dependencyObject)
// (dlib.construct.pathSource {
path = getPath dependencyObject;
rootName = project.name;
rootVersion = packageVersion;
});
git = dep:
(getSource dep)
// (dlib.parseGitUrl dep.url);

http = dep: (getSource dep);

path = dep: (dlib.construct.pathSource {
path = getPath dep;
rootName = project.name;
rootVersion = packageVersion;
});
};

getDependencies = dependencyObject: dependencyObject.deps;
getDependencies = dep: dep.deps;
});
in rec {
version = 2;
Expand Down
34 changes: 18 additions & 16 deletions src/subsystems/nodejs/translators/package-lock-v2/v2-parse.nix
Original file line number Diff line number Diff line change
Expand Up @@ -58,32 +58,35 @@ assert (lib.elem lock.lockfileVersion [2 3]); let
if n == ""
then lockName
else n;

extraAttrs = {
# platforms this package works on
os = 1;
# this is a dev dependency
dev = 1;
# this is an optional dependency
optional = 1;
# this is an optional dev dependency
devOptional = 1;
# set of binary scripts { name = relativePath }
bin = 1; # pkg needs to run install scripts
hasInstallScript = 1;
};
getExtra = pkg: b.intersectAttrs extraAttrs pkg;
in
{
version ? "unknown",
# URL to content - only main package is not defined
resolved ? "file://${source}",
# hash for content
integrity ? null,
# platforms this package works on
os ? null,
# this is a dev dependency
dev ? false,
# this is an optional dependency
optional ? false,
# this is an optional dev dependency
devOptional ? false,
# set of binary scripts { name = relativePath }
bin ? {},
# pkg needs to run install scripts
hasInstallScript ? false,
dependencies ? null,
devDependencies ? null,
peerDependencies ? null,
optionalDependencies ? null,
peerDependenciesMeta ? null,
...
}: let
} @ pkg: let
deps =
lib.unique
((resolveDeps dependencies parts false)
Expand All @@ -92,11 +95,10 @@ assert (lib.elem lock.lockfileVersion [2 3]); let
++ (resolveDeps peerDependencies parts true)
++ (resolveDeps peerDependenciesMeta parts true));
in {
inherit pname version deps os dev optional devOptional bin;
inherit pname version deps;
url = resolved;
hash = integrity;
# Storing negation so other translators don't have to have this feature
noInstall = !hasInstallScript;
extra = getExtra pkg;
};

allDeps = lib.mapAttrsToList mapPkg pkgs;
Expand Down

0 comments on commit 0c0ce5d

Please sign in to comment.