From 90649d117a6cf0a2ce3a38031c3bf7f03e5c72eb Mon Sep 17 00:00:00 2001 From: DavHau Date: Sun, 6 Mar 2022 00:38:06 +0700 Subject: [PATCH] fix invalidationHash logic + remove .#resolve messages --- src/default.nix | 24 ++++++------------------ src/libV2.nix | 10 ++++++++++ src/utils/default.nix | 14 +++++++++++++- 3 files changed, 29 insertions(+), 19 deletions(-) diff --git a/src/default.nix b/src/default.nix index 46831464..84ff1838 100644 --- a/src/default.nix +++ b/src/default.nix @@ -518,7 +518,7 @@ let l.pathExists "${config.projectRoot}/${project.dreamLockPath}"; dreamLockValid = - project.dreamLock.lock._generic.invalidationHash or "" + project.dreamLock._generic.invalidationHash or "" == project.invalidationHash; in dreamLockExists && dreamLockValid; @@ -530,9 +530,9 @@ let projectsList = l.map (project: (let self = project // rec { - dreamLock = utils.readDreamLock { + dreamLock = (utils.readDreamLock { dreamLock = "${config.projectRoot}/${project.dreamLockPath}"; - }; + }).lock; impure = isImpure project translator; invalidationHash = getInvalidationHash project; key = getProjectKey project; @@ -598,31 +598,18 @@ let l.trace '' ${"\n"} Run `nix run .#resolveImpure` once to resolve impure projects. - The following projects cannot be resolved on the fly and require preprocessing: + The following projects cannot be resolved on the fly and are therefore excluded: ${l.concatStringsSep "\n " projectsImpureUnresolvedInfo} '' resolvedProjects else l.trace '' ${"\n"} - The following projects cannot be resolved on the fly and require preprocessing: + The following projects cannot be resolved on the fly and are therefore excluded: ${l.concatStringsSep "\n " projectsImpureUnresolvedInfo} '' resolvedProjects else if projectsPureUnresolved != [] then - if flakeMode then - l.trace '' - ${"\n"} - Evaluating project data on the fly... - To speed up future evalutations run once: - nix run .#resolve - '' - resolvedProjects - else - l.trace '' - ${"\n"} - Evaluating project data on the fly... - '' resolvedProjects else resolvedProjects; @@ -675,6 +662,7 @@ let passthru = old.passthru or {} // { resolve = utils.makeTranslateScript { inherit source; + invalidationHash = proj.invalidationHash; project = proj; }; }; diff --git a/src/libV2.nix b/src/libV2.nix index 892cc005..1cb394d9 100644 --- a/src/libV2.nix +++ b/src/libV2.nix @@ -122,6 +122,15 @@ let allPkgs = makeNixpkgs pkgs systems; forAllSystems = f: b.mapAttrs f allPkgs; dream2nixFor = forAllSystems (dream2nixForSystem config); + + getInvalidationHash = project: + dlib.calcInvalidationHash { + inherit source; + # TODO: add translatorArgs + translatorArgs = {}; + translator = project.translator; + }; + discoveredProjects = dlib.discoverers.discoverProjects { inherit settings; tree = dlib.prepareSourceTree { inherit source; }; @@ -148,6 +157,7 @@ let "Name: ${project.name}; Subsystem: ${project.subsystem}; relPath: ${project.relPath}" (dream2nix.utils.makeTranslateScript { inherit project source; + invalidationHash = getInvalidationHash project; }))); resolveImpureScript = diff --git a/src/utils/default.nix b/src/utils/default.nix index 5d9e3ab9..e5987cdc 100644 --- a/src/utils/default.nix +++ b/src/utils/default.nix @@ -167,6 +167,7 @@ overrideUtils makeTranslateScript = { + invalidationHash, source, project, }@args: @@ -184,12 +185,23 @@ overrideUtils in writePureShellScriptBin "resolve" [ - pkgs.nix + pkgs.coreutils + pkgs.jq pkgs.gitMinimal + pkgs.nix ] '' cd $WORKDIR ${translator.translateBin} ${argsJsonFile} + + # add invalidationHash to dream-lock.json + cp ${project.dreamLockPath} ${project.dreamLockPath}.tmp + cat ${project.dreamLockPath}.tmp \ + | jq '._generic.invalidationHash = "${invalidationHash}"' \ + > ${project.dreamLockPath} + rm ${project.dreamLockPath}.tmp + + # add dream-lock.json to git if git rev-parse --show-toplevel &>/dev/null; then echo "adding file to git: ${project.dreamLockPath}" git add ${project.dreamLockPath}