mirror of
https://gitlab.com/rensa-nix/core.git
synced 2026-02-02 15:25:08 +01:00
fix(loader): infinite recursion error when accessing sibling blocks
eg. accessing/returning `cell.b` (cell/b.nix) from cell/a.nix would cause infinite recursion. That's now fixed
This commit is contained in:
parent
558066d8df
commit
0d6970d95a
3 changed files with 24 additions and 1 deletions
4
cells/test/other.nix
Normal file
4
cells/test/other.nix
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
# test to make sure infinite recursion doesn't happen when accessing sibling blocks
|
||||||
|
# run `nix eval .#<system>.test` to check
|
||||||
|
# should return { other = { hello = "world"; }; test = «repeated»; }
|
||||||
|
{cell, ...}: cell.test
|
||||||
|
|
@ -19,6 +19,7 @@
|
||||||
cellsFrom = ./cells;
|
cellsFrom = ./cells;
|
||||||
cellBlocks = with rensa.blocks; [
|
cellBlocks = with rensa.blocks; [
|
||||||
(simple "test")
|
(simple "test")
|
||||||
|
(simple "other")
|
||||||
(simple "devShells")
|
(simple "devShells")
|
||||||
(simple "docs")
|
(simple "docs")
|
||||||
(simple "ci")
|
(simple "ci")
|
||||||
|
|
|
||||||
|
|
@ -128,9 +128,27 @@
|
||||||
inherit (utils) unique accumulate;
|
inherit (utils) unique accumulate;
|
||||||
|
|
||||||
loadCell = cellName: let
|
loadCell = cellName: let
|
||||||
cell = res.output;
|
|
||||||
cellP = paths.cellPath cellsFrom cellName;
|
cellP = paths.cellPath cellsFrom cellName;
|
||||||
cellBlocks' = (unique cellBlocks).result;
|
cellBlocks' = (unique cellBlocks).result;
|
||||||
|
# fixes `ìnfinite recursion` errors when accessing cell attributes from sibling blocks
|
||||||
|
# example: cells/test/a.nix returns `cell.b`, so the same thing as cells/test/b.nix.
|
||||||
|
# this would previously fail with infinite recursion, this makes it work:
|
||||||
|
cell = l.listToAttrs (l.concatMap (
|
||||||
|
block: let
|
||||||
|
blockP = paths.cellBlockPath cellP block;
|
||||||
|
exists = l.pathExists blockP.file || l.pathExists blockP.dir;
|
||||||
|
in
|
||||||
|
if exists
|
||||||
|
then [
|
||||||
|
{
|
||||||
|
name = block.name;
|
||||||
|
# accessing this value will force the loading of this block
|
||||||
|
value = (l.head (loadCellBlock cellName cellP block)).${block.name};
|
||||||
|
}
|
||||||
|
]
|
||||||
|
else []
|
||||||
|
)
|
||||||
|
cellBlocks');
|
||||||
loadCellBlock = createCellBlockLoader {inherit inputs system cells cell transformInputs;};
|
loadCellBlock = createCellBlockLoader {inherit inputs system cells cell transformInputs;};
|
||||||
res = accumulate (l.map (loadCellBlock cellName cellP) cellBlocks');
|
res = accumulate (l.map (loadCellBlock cellName cellP) cellBlocks');
|
||||||
in [
|
in [
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue