Vertical NixOS module organisation and module dependency

Maybe you want to try the dendritic pattern.

It might be able to solve your first problem:

However, I do not recommend using any existing dendritic frameworks, such as den. Because I believe these ‘early practices’ did not address your second question:

So far, these frameworks use functions to deduplicate module dependencies, which is not transparent and makes error reporting harder to understand.

However, according to the design concept of the dendritic pattern, it is feasible to use module options in the top-level module to conditionally import modules, thereby controlling module dependencies. I use a similar method in my configuration (pardon the mess).

btw, I don’t want to belittle the efforts of the dendritic pattern developers. They are very friendly and have helped me in many ways. But I feel that these frameworks are a bit too complicated, and I find it hard to understand. ‘early practices’ is my honest opinion about these libraries, with no intent to offend, but I feel that they are not yet ready for use in a production environment.

EDIT: To add, I think the solution proposed in this RFC addresses the issues of module dependencies and interactions. Although this is aimed at NixOS modules, this idea has inspired me, and I believe this approach can be used in more places.

1 Like