blueprint icon indicating copy to clipboard operation
blueprint copied to clipboard

Support nested `hosts` directory

Open arianvp opened this issue 11 months ago • 5 comments

Is your feature request related to a problem? Please describe.

we have nesting in our hosts directory a la:

hosts/
  production/
     host1/
     host2/
  staging/
    host3/
    host4/

Describe the solution you'd like

would be neat if this would work and up with making

{
  nixosConfigurations = {
    "production/host1" = ...
     "staging/host3" = ...
  };
}

Describe alternatives you've considered

Flatten directory structure but make me sad

Additional context

arianvp avatar Jan 10 '25 15:01 arianvp

Not quite a duplicate, but probably some overlap with https://github.com/numtide/blueprint/issues/51.

  • "/" as a separator in the attrset makes quoting necessary which can be a bit of an annoyance in the repl IMO. Are there drawbacks in replacing them with "-" in the attrset?

  • we should probably stop to recurse once we find a (darwin)-configuration.nix?

phaer avatar Jan 10 '25 15:01 phaer

makes quoting necessary

Does it? This works fine for me (on zsh):

arian@Arians-MacBook-Pro try-blueprint % nix flake show
warning: Git tree '/Users/arian/Projects/try-blueprint' is dirty
git+file:///Users/arian/Projects/try-blueprint
└───nixosConfigurations
    └───"production/host1": NixOS configuration
arian@Arians-MacBook-Pro try-blueprint % nix build .#nixosConfigurations.production/host1.config.system.build.toplevel
warning: Git tree '/Users/arian/Projects/try-blueprint' is dirty
[1/0/1 copied (175.8/175.8 MiB), 27.5 MiB DL] fetching source from htt

arianvp avatar Jan 10 '25 15:01 arianvp

I thought / was a common pattern. e.g. also used in flake-utils.flattenTree

arianvp avatar Jan 10 '25 15:01 arianvp

Alternatively, what if you could re-instantiate a blueprint?

  • shared/flake.nix - a normal blueprint, with your hosts/ folder and everything.
  • staging/flake.nix
    {
      inputs.shared.url = "path:../shared";
      outputs = inputs: inputs.shared {
        inherit inputs;
        vars = {
          environment = "staging";
        };
      };
    }
    

Where vars in a new global that gets injected everywhere in the blueprint and can be used to parameterize it.

And where the new instance of the blueprint would also merge in its own folder structure. So you can still override or add a host on staging or prod for special cases.

zimbatm avatar Jan 10 '25 17:01 zimbatm

a possibly similar usecase: in my current config, my nixosConfigurations exist once with withSecrets=true and once with withSecrets=false. It lets me boostrap my config without having all my secrets available yet (which are copied manually).

For instance, I have a nixosConfiguration laptop and laptop-bootstrap = laptop.override { specialArgs = { withSecrets = false }.

teto avatar Feb 13 '25 15:02 teto