improve realizeProjects & resolveProjectsFromSource

This commit is contained in:
DavHau 2022-02-27 17:25:24 +07:00
parent 6a232399ad
commit c470172eea

View File

@ -426,6 +426,7 @@ let
let let
flakeMode = ! builtins ? currentSystem;
discoveredProjects = dlib.discoverers.discoverProjects { inherit tree; }; discoveredProjects = dlib.discoverers.discoverProjects { inherit tree; };
getTranslator = subsystem: translatorName: getTranslator = subsystem: translatorName:
@ -434,6 +435,23 @@ let
isImpure = project: translatorName: isImpure = project: translatorName:
(getTranslator project.subsystem translatorName).type == "impure"; (getTranslator project.subsystem translatorName).type == "impure";
isResolved = project:
let
dreamLockExists = l.pathExists project.dreamLockPath;
invalidationHash = dlib.calcInvalidationHash {
inherit source;
# TODO: add translatorArgs
translatorArgs = {};
translator = project.translator;
};
dreamLockValid =
project.dreamLock.lock._generic.invalidationHash or ""
== invalidationHash;
in
dreamLockExists && dreamLockValid;
getDreamLockPath = project: getDreamLockPath = project:
let let
root = root =
@ -453,14 +471,14 @@ let
# list of projects extended with some information requried for processing # list of projects extended with some information requried for processing
projectsList = projectsList =
l.map l.map
(project: project // rec { (project: project // (let self = rec {
dreamLockPath = getDreamLockPath project; dreamLockPath = getDreamLockPath project;
dreamLock = dlib.readDreamLock dreamLockPath; dreamLock = dlib.readDreamLock dreamLockPath;
impure = isImpure project translator; impure = isImpure project translator;
key = getProjectKey project; key = getProjectKey project;
resolved = l.pathExists dreamLockPath; resolved = isResolved self;
translator = l.head project.translators; translator = l.head project.translators;
}) }; in self))
discoveredProjects; discoveredProjects;
# attrset of projects by key # attrset of projects by key
@ -504,10 +522,36 @@ let
in in
if projectsImpureUnresolved != [] then if projectsImpureUnresolved != [] then
throw '' if flakeMode then
The following projects cannot be resolved on the fly and require preprocessing: throw ''
${l.concatStringsSep "\n " projectsImpureUnresolvedPaths} ${"\n"}
'' Run `nix run .#resolve` once to resolve impure projects.
The following projects cannot be resolved on the fly and require preprocessing:
${l.concatStringsSep "\n " projectsImpureUnresolvedPaths}
''
else
throw ''
${"\n"}
The following projects cannot be resolved on the fly and require preprocessing:
${l.concatStringsSep "\n " projectsImpureUnresolvedPaths}
''
else if projectsUnresolved != [] then
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).
To speed up future evalutations run once:
nix run .#resolve
''
dreamLocks
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).
''
dreamLocks
else else
dreamLocks; dreamLocks;
@ -518,22 +562,28 @@ let
# alternative way of calling (for debugging) # alternative way of calling (for debugging)
pname ? null, pname ? null,
source ? throw "Pass either `dreamLocks` or `source` to realizeProjects", source ? null,
}: }:
let let
defaultSourceOverride = dreamLock:
if source == null then
{}
else
let
defaultPackage = dreamLock._generic.defaultPackage;
defaultPackageVersion =
dreamLock._generic.packages."${defaultPackage}";
in
{ "${defaultPackage}"."${defaultPackageVersion}" = source; };
projectOutputs = projectOutputs =
l.map l.map
(dreamLock: makeOutputsForDreamLock rec { (dreamLock: makeOutputsForDreamLock rec {
inherit dreamLock; inherit dreamLock;
sourceOverrides = sourceOverrides = oldSources:
let (defaultSourceOverride dreamLock);
defaultPackage = dreamLock._generic.defaultPackage;
defaultPackageVersion =
dreamLock._generic.packages."${defaultPackage}";
in
oldSources: {
"${defaultPackage}"."${defaultPackageVersion}" = source;
};
}) })
dreamLocks; dreamLocks;