From 0d6970d95ae3f5e20046b2cb0ec88d396cc55d9e Mon Sep 17 00:00:00 2001 From: technofab Date: Tue, 23 Dec 2025 14:40:32 +0100 Subject: [PATCH] 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 --- cells/test/other.nix | 4 ++++ flake.nix | 1 + lib/core/loader.nix | 20 +++++++++++++++++++- 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 cells/test/other.nix diff --git a/cells/test/other.nix b/cells/test/other.nix new file mode 100644 index 0000000..1dba68a --- /dev/null +++ b/cells/test/other.nix @@ -0,0 +1,4 @@ +# test to make sure infinite recursion doesn't happen when accessing sibling blocks +# run `nix eval .#.test` to check +# should return { other = { hello = "world"; }; test = «repeated»; } +{cell, ...}: cell.test diff --git a/flake.nix b/flake.nix index 734f599..a47fa5a 100644 --- a/flake.nix +++ b/flake.nix @@ -19,6 +19,7 @@ cellsFrom = ./cells; cellBlocks = with rensa.blocks; [ (simple "test") + (simple "other") (simple "devShells") (simple "docs") (simple "ci") diff --git a/lib/core/loader.nix b/lib/core/loader.nix index 76cb3f0..eec8e70 100644 --- a/lib/core/loader.nix +++ b/lib/core/loader.nix @@ -128,9 +128,27 @@ inherit (utils) unique accumulate; loadCell = cellName: let - cell = res.output; cellP = paths.cellPath cellsFrom cellName; 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;}; res = accumulate (l.map (loadCellBlock cellName cellP) cellBlocks'); in [