add flake output projectsJson

This commit is contained in:
DavHau 2022-03-01 14:21:26 +07:00
parent 89a0c4f4c3
commit 1fc9998b0f
3 changed files with 23 additions and 22 deletions

View File

@ -489,6 +489,7 @@ let
resolveProjectsFromSource =
{
discoveredProjects ? dlib.discoverers.discoverProjects { inherit tree; },
source ?
throw "Pass either `source` or `tree` to resolveProjectsFromSource",
tree ? dlib.prepareSourceTree { inherit source; },
@ -498,7 +499,6 @@ let
let
flakeMode = ! builtins ? currentSystem;
discoveredProjects = dlib.discoverers.discoverProjects { inherit tree; };
getTranslator = subsystem: translatorName:
translators.translatorsV2."${subsystem}".all."${translatorName}";

View File

@ -21,16 +21,18 @@ let
let
nodes = l.readDir path;
packageJson = l.fromJSON (l.readFile "${path}/package.json");
in
# if the package has no dependencies we use the
# package-lock translator with `packageLock = null`
if ! packageJson ? dependencies && ! packageJson ? devDependencies
then [ "package-lock" ]
translators =
# if the package has no dependencies we use the
# package-lock translator with `packageLock = null`
if ! packageJson ? dependencies && ! packageJson ? devDependencies
then [ "package-lock" ]
else
l.optionals (nodes ? "package-lock.json") [ "package-lock" ]
++ l.optionals (nodes ? "yarn.lock") [ "yarn-lock" ]
++ [ "package-json" ];
else
l.optionals (nodes ? "package-lock.json") [ "package-lock" ]
++ l.optionals (nodes ? "yarn.lock") [ "yarn-lock" ]
++ [ "package-json" ];
in
translators;
# returns the parsed package.json of a given directory
getPackageJson = dirPath:

View File

@ -58,17 +58,9 @@ let
flakifyBuilderOutputs = system: outputs:
(lib.optionalAttrs (outputs ? "defaultPackage") {
defaultPackage."${system}" = outputs.defaultPackage;
})
//
(lib.optionalAttrs (outputs ? "packages") {
packages."${system}" = outputs.packages;
})
//
(lib.optionalAttrs (outputs ? "devShell") {
devShell."${system}" = outputs.devShell;
});
l.mapAttrs
(ouputType: outputValue: { "${system}" = outputValue; })
outputs;
init =
{
@ -129,6 +121,9 @@ let
allPkgs = makeNixpkgs pkgs systems;
forAllSystems = f: b.mapAttrs f allPkgs;
dream2nixFor = forAllSystems (dream2nixForSystem config);
discoveredProjects = dlib.discoverers.discoverProjects {
tree = dlib.prepareSourceTree { inherit source; };
};
allBuilderOutputs =
lib.mapAttrs
@ -150,12 +145,16 @@ let
(system: outputs: flakifyBuilderOutputs system outputs)
allBuilderOutputs;
flakeOutputs =
flakeOutputsBuilders =
b.foldl'
(allOutputs: output: lib.recursiveUpdate allOutputs output)
{}
flakifiedOutputsList;
flakeOutputs =
{ projectsJson = l.toJSON (discoveredProjects); }
// flakeOutputsBuilders;
in
lib.recursiveUpdate
flakeOutputs