diff --git a/src/default.nix b/src/default.nix index 3066e7c4..59cac7d1 100644 --- a/src/default.nix +++ b/src/default.nix @@ -489,15 +489,18 @@ let resolveProjectsFromSource = { - discoveredProjects ? dlib.discoverers.discoverProjects { inherit tree; }, + discoveredProjects ? dlib.discoverers.discoverProjects + {inherit settings tree;}, source ? throw "Pass either `source` or `tree` to resolveProjectsFromSource", tree ? dlib.prepareSourceTree { inherit source; }, pname, + settings ? [], }@args: let + # This influences error messages only flakeMode = ! builtins ? currentSystem; getTranslator = subsystem: translatorName: @@ -548,7 +551,7 @@ let impure = isImpure project translator; key = getProjectKey project; resolved = isResolved self; - translator = l.head project.translators; + translator = project.translator or (l.head project.translators); }; in self)) discoveredProjects; @@ -610,8 +613,7 @@ let if flakeMode then b.trace '' ${"\n"} - The dream-lock.json for some projects doesn't exist or is outdated. - ...Falling back to on-the-fly evaluation (possibly slow). + Evaluating project data on the fly... To speed up future evalutations run once: nix run .#resolve '' @@ -619,8 +621,7 @@ let else b.trace '' ${"\n"} - The dream-lock.json for some projects doesn't exist or is outdated. - ...Falling back to on-the-fly evaluation (possibly slow). + Evaluating project data on the fly... '' dreamLocks else @@ -629,11 +630,13 @@ let # transform a list of resolved projects to buildable outputs realizeProjects = { - dreamLocks ? resolveProjectsFromSource { inherit pname source; }, + dreamLocks ? resolveProjectsFromSource { inherit pname settings source; }, # alternative way of calling (for debugging) pname ? null, source ? null, + + settings ? [], }: let diff --git a/src/discoverers/default.nix b/src/discoverers/default.nix index 6f5949f2..817ddace 100644 --- a/src/discoverers/default.nix +++ b/src/discoverers/default.nix @@ -17,11 +17,40 @@ let { source ? throw "Pass either `source` or `tree` to discoverProjects", tree ? dlib.prepareSourceTree { inherit source; }, - }: - l.flatten - (l.map - (discoverer: discoverer.discover { inherit tree; }) - allDiscoverers); + settings ? [], + }: let + discovered = + l.flatten + (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: (import (./. + "/${subsystem}") { inherit dlib lib subsystem; }) @@ -30,6 +59,7 @@ in { inherit + applyProjectSettings discoverProjects discoverers ; diff --git a/src/libV2.nix b/src/libV2.nix index a51048fc..bf308f6c 100644 --- a/src/libV2.nix +++ b/src/libV2.nix @@ -108,6 +108,7 @@ let { pname ? throw "Please pass `pname` to makeFlakeOutputs", pkgs ? null, + settings ? [], source, systems ? [], translator ? null, @@ -122,6 +123,7 @@ let forAllSystems = f: b.mapAttrs f allPkgs; dream2nixFor = forAllSystems (dream2nixForSystem config); discoveredProjects = dlib.discoverers.discoverProjects { + inherit settings; tree = dlib.prepareSourceTree { inherit source; }; }; @@ -132,7 +134,7 @@ let dream2nix = dream2nixFor."${system}"; dreamLocks = dream2nix.resolveProjectsFromSource { - inherit pname source; + inherit pname settings source; }; in dream2nix.realizeProjects {