add functions.discoverers.discoverProjects2

This commit is contained in:
DavHau 2022-12-07 14:14:02 +07:00
parent 3d6f13ef9d
commit e7bd51d83e
2 changed files with 66 additions and 0 deletions

View File

@ -2,6 +2,68 @@
l = config.lib // builtins;
dlib = config.dlib;
/*
Stripped down discoverProjects without settings merging and dreamLockPath
represented as an attrset:
{
${project-name} = {
relPath = ...;
subsystem = ...;
subsystemInfo = {
...
};
translator = "some-translator";
# all compatible translators
translators = [
"some-translator"
"some-alternative-translator"
];
}
}
*/
discoverProjects2 = {
source ? throw "Pass either `source` or `tree` to discoverProjects",
tree ? dlib.prepareSourceTree {inherit source;},
}: let
discoveredProjects =
l.flatten
(
l.map
(discoverer: discoverer.discover {inherit tree;})
(l.attrValues config.discoverers)
);
discoveredProjectsSorted = let
sorted =
l.sort
(p1: p2: l.hasPrefix p1.relPath or "" p2.relPath or "")
discoveredProjects;
in
sorted;
allProjects = discoveredProjectsSorted;
projectsExtended =
l.forEach allProjects
(proj:
proj
// {
relPath = proj.relPath or "";
translator = proj.translator or (l.head proj.translators);
});
in
l.listToAttrs (
l.map
(proj: l.nameValuePair proj.name proj)
projectsExtended
);
/*
legacy function doing some custom merging on `settings`.
We should remove that function once there is no more usage within the
frameworks code.
*/
discoverProjects = {
source ? throw "Pass either `source` or `tree` to discoverProjects",
tree ? dlib.prepareSourceTree {inherit source;},
@ -69,6 +131,7 @@ in {
functions.discoverers = {
inherit
discoverProjects
discoverProjects2
getDreamLockPath
applyProjectSettings
;

View File

@ -3,6 +3,9 @@
t = l.types;
in {
options.functions.discoverers = {
discoverProjects2 = l.mkOption {
type = t.uniq (t.functionTo (t.listOf t.attrs));
};
discoverProjects = l.mkOption {
type = t.uniq (t.functionTo (t.listOf t.attrs));
};