I’m playing around with a nix flake to hold configurations for multiple systems and am looking for a good layout which allows for a sparse checkout to address information leakage between multiple hosts.
The layout looks roughly like this:
flake.nix # should auto-detect nixos configs in deployments/ lib/* # support functions for building the systems modules/* # functions which produce nixos modules (get the flake inputs passed as arguments) machines/* # functions which produce hardware configurations deployments/* # contains the different nixos configs composed from modules/ & machines/
I want to be able to auto-detect the nixos configurations in the
deployments directory. I’ve written a small function for this in
lib which uses
readDir. And this is were the problem begins: At some point I need to interpolate the return values of
deployments/ which causes
deployments/ to be copied in the nix store although it is already part of the flake (but nix doesn’t know this) which is already in the nix store at evaluation time. As the nixos configs in
deployments/ reference files in e.g.
modules/ they use another relative import e.g.
../modules/xyz which fails to resolve because the flake uses the
deployments/ from the nix store and then tries to evaluate
../modules/xyz (relative to the path pointing to the nix store) which of course doesn’t exist in the nix store.
Is there some way to work around this? e.g. to tell nix that “hey, the resulting path of the interpolation is still within the flake so you don’t have to copy it to the store”? I tried to use
self.outPath of the flake in the nixos config but that sent the evaluation into an infinite loop.