feat(eval-cache): allow nested fields as inputs

This commit is contained in:
DavHau 2023-02-17 12:53:29 +07:00
parent 16d0ce469c
commit 6ad08f59af
2 changed files with 19 additions and 11 deletions

View File

@ -7,21 +7,29 @@
then config.name
else config.pname;
filterTrue = l.filterAttrs (key: val: val == true);
filterTrue = l.filterAttrsRecursive (key: val: l.isAttrs val || val == true);
invalidationFields = (filterTrue cfg.invalidationFields);
# TODO: make this recursive
invalidationData = l.intersectAttrs invalidationFields config;
intersectAttrsRecursive = a: b:
l.mapAttrs
(key: valB:
if l.isAttrs valB && l.isAttrs a.${key}
then intersectAttrsRecursive a.${key} valB
else valB
)
(l.intersectAttrs a b);
invalidationData = intersectAttrsRecursive invalidationFields config;
invalidationHash = l.hashString "sha256"
(l.toJSON (invalidationData // cfg.fields));
(l.toJSON [invalidationData cfg.fields]);
fields = filterTrue cfg.fields;
# SAVE
content = l.intersectAttrs fields config;
content = intersectAttrsRecursive fields config;
cache-content = {
inherit
@ -39,8 +47,8 @@
file = cfg.repoRoot + cfg.cacheFileRel;
refreshCommand =
"cat ${cfg.newFile} > $(git rev-parse --show-toplevel)/${cfg.cacheFileRel}";
refreshCommand = l.unsafeDiscardStringContext
"cat $(nix-build ${cfg.newFile.drvPath}) > $(git rev-parse --show-toplevel)/${cfg.cacheFileRel}";
newFileMsg = "To generate a new cache file, execute:\n ${refreshCommand}";

View File

@ -16,8 +16,8 @@ in {
};
};
invalidationFields = l.mkOption {
type = t.attrsOf t.bool;
invalidationFields = l.mkOption rec {
type = t.attrsOf (t.oneOf [t.bool type]);
description = "Fields, when changed, require refreshing the cache";
default = {};
example = {
@ -48,8 +48,8 @@ in {
readOnly = true;
};
fields = l.mkOption {
type = t.attrsOf t.bool;
fields = l.mkOption rec {
type = t.attrsOf (t.oneOf [t.bool type]);
description = "Fields for which to cache evaluation";
default = {};
example = {