Hello,
I could successfully build disk images to bootstrap NixOS machines and it all works in a pure flake.
Now I’d love to support a “second mode” inside my flake, where I’d like to include host-specific instance data from an external file (absolute path). This works in impure evaluation.
The problem I am facing seems to be a quite general one: How do I know whether the current evaluation is pure or impure?
tryInstanceData = builtins.tryEval (
builtins.fromJSON (
builtins.readFile cfg.path));
Works fine in impure mode, whether cfg.path exists or not. But it rightfully throws an error in impure evaluation which I can’t catch.
Docs for try eval do state that it does not catch such errors, but no hint is given on how to catch them.
The environment variable IN_NIX_SHELL would contain the string “pure” or “impure”, but that’s for nix shell only, and isn’t set for nix build.
Any tips on how to solve this issue would be highly appreciated, thanks for reading