mirror of
https://github.com/nix-community/dream2nix.git
synced 2024-12-25 15:33:20 +03:00
feat(eval-cache): allow nested fields as inputs
This commit is contained in:
parent
16d0ce469c
commit
6ad08f59af
@ -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}";
|
||||
|
||||
|
@ -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 = {
|
||||
|
Loading…
Reference in New Issue
Block a user