add settings argument to lib2.makeFlakeOutputs

This commit is contained in:
DavHau 2022-03-03 15:48:30 +07:00
parent 29741906b2
commit 2b6bcb7b75
3 changed files with 48 additions and 13 deletions

View File

@ -489,15 +489,18 @@ let
resolveProjectsFromSource = resolveProjectsFromSource =
{ {
discoveredProjects ? dlib.discoverers.discoverProjects { inherit tree; }, discoveredProjects ? dlib.discoverers.discoverProjects
{inherit settings tree;},
source ? source ?
throw "Pass either `source` or `tree` to resolveProjectsFromSource", throw "Pass either `source` or `tree` to resolveProjectsFromSource",
tree ? dlib.prepareSourceTree { inherit source; }, tree ? dlib.prepareSourceTree { inherit source; },
pname, pname,
settings ? [],
}@args: }@args:
let let
# This influences error messages only
flakeMode = ! builtins ? currentSystem; flakeMode = ! builtins ? currentSystem;
getTranslator = subsystem: translatorName: getTranslator = subsystem: translatorName:
@ -548,7 +551,7 @@ let
impure = isImpure project translator; impure = isImpure project translator;
key = getProjectKey project; key = getProjectKey project;
resolved = isResolved self; resolved = isResolved self;
translator = l.head project.translators; translator = project.translator or (l.head project.translators);
}; in self)) }; in self))
discoveredProjects; discoveredProjects;
@ -610,8 +613,7 @@ let
if flakeMode then if flakeMode then
b.trace '' b.trace ''
${"\n"} ${"\n"}
The dream-lock.json for some projects doesn't exist or is outdated. Evaluating project data on the fly...
...Falling back to on-the-fly evaluation (possibly slow).
To speed up future evalutations run once: To speed up future evalutations run once:
nix run .#resolve nix run .#resolve
'' ''
@ -619,8 +621,7 @@ let
else else
b.trace '' b.trace ''
${"\n"} ${"\n"}
The dream-lock.json for some projects doesn't exist or is outdated. Evaluating project data on the fly...
...Falling back to on-the-fly evaluation (possibly slow).
'' ''
dreamLocks dreamLocks
else else
@ -629,11 +630,13 @@ let
# transform a list of resolved projects to buildable outputs # transform a list of resolved projects to buildable outputs
realizeProjects = realizeProjects =
{ {
dreamLocks ? resolveProjectsFromSource { inherit pname source; }, dreamLocks ? resolveProjectsFromSource { inherit pname settings source; },
# alternative way of calling (for debugging) # alternative way of calling (for debugging)
pname ? null, pname ? null,
source ? null, source ? null,
settings ? [],
}: }:
let let

View File

@ -17,11 +17,40 @@ let
{ {
source ? throw "Pass either `source` or `tree` to discoverProjects", source ? throw "Pass either `source` or `tree` to discoverProjects",
tree ? dlib.prepareSourceTree { inherit source; }, tree ? dlib.prepareSourceTree { inherit source; },
}: settings ? [],
l.flatten }: let
(l.map discovered =
(discoverer: discoverer.discover { inherit tree; }) l.flatten
allDiscoverers); (l.map
(discoverer: discoverer.discover { inherit tree; })
allDiscoverers);
in
applyProjectSettings discovered settings;
applyProjectSettings = projects: settingsList:
let
settingsListForProject = project:
l.filter
(settings:
if ! settings ? filter then true
else settings.filter project)
settingsList;
applySettings = project: settings:
l.recursiveUpdate project settings;
applyAllSettings = project:
l.foldl'
(proj: settings: applySettings proj settings)
project
(settingsListForProject project);
settingsApplied =
l.forEach projects
(proj: applyAllSettings proj);
in settingsApplied;
discoverers = l.genAttrs subsystems (subsystem: discoverers = l.genAttrs subsystems (subsystem:
(import (./. + "/${subsystem}") { inherit dlib lib subsystem; }) (import (./. + "/${subsystem}") { inherit dlib lib subsystem; })
@ -30,6 +59,7 @@ in
{ {
inherit inherit
applyProjectSettings
discoverProjects discoverProjects
discoverers discoverers
; ;

View File

@ -108,6 +108,7 @@ let
{ {
pname ? throw "Please pass `pname` to makeFlakeOutputs", pname ? throw "Please pass `pname` to makeFlakeOutputs",
pkgs ? null, pkgs ? null,
settings ? [],
source, source,
systems ? [], systems ? [],
translator ? null, translator ? null,
@ -122,6 +123,7 @@ let
forAllSystems = f: b.mapAttrs f allPkgs; forAllSystems = f: b.mapAttrs f allPkgs;
dream2nixFor = forAllSystems (dream2nixForSystem config); dream2nixFor = forAllSystems (dream2nixForSystem config);
discoveredProjects = dlib.discoverers.discoverProjects { discoveredProjects = dlib.discoverers.discoverProjects {
inherit settings;
tree = dlib.prepareSourceTree { inherit source; }; tree = dlib.prepareSourceTree { inherit source; };
}; };
@ -132,7 +134,7 @@ let
dream2nix = dream2nixFor."${system}"; dream2nix = dream2nixFor."${system}";
dreamLocks = dream2nix.resolveProjectsFromSource { dreamLocks = dream2nix.resolveProjectsFromSource {
inherit pname source; inherit pname settings source;
}; };
in in
dream2nix.realizeProjects { dream2nix.realizeProjects {