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:
technofab 2025-12-23 14:40:32 +01:00
parent 558066d8df
commit 0d6970d95a
Signed by: technofab
SSH key fingerprint: SHA256:bV4h88OqS/AxjbPn66uUdvK9JsgIW4tv3vwJQ8tpMqQ
3 changed files with 24 additions and 1 deletions

4
cells/test/other.nix Normal file
View 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

View file

@ -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")

View file

@ -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 [