-
Notifications
You must be signed in to change notification settings - Fork 62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a lib function to extract nixosConfigurations from raw flake #161
base: main
Are you sure you want to change the base?
Conversation
This commit adds a function to load colmena hive from the flake. Use case: If I have a flake output like this: ``` outputs = {}: { colmena = { systemA = {...}; systemB = {...}; }; } ``` Currently I have no way to obtain the nixosConfiguration associated to systemA and systemB. With this new function, I can now do for instance ``` inputs.colmena = "github:zhaofengli/colmena"; outputs = { colmena }: { nixosConfiguration = colmena.fromRawFlake self; colmena = { systemA = {...}; systemB = {...}; }; } ``` And this nixosConfiguration will contain the same system as the one that would be built by colmena. This is incomplete (keys are not uploaded), but it is still useful in (at least) two situations: - If I want to test the configuration in a VM (or anywhere) - If I want to bootstrap the machine with for instance https://github.com/numtide/nixos-anywhere This function roughly adds the same content as what "colmena repl" gives access to, but in a nix evaluation context.
I use something similar but to convert from |
@otavio : we could indeed have two functions to do it both ways (colmena -> nixosConfiguration and nixosConfiguration -> colmena) |
Note however that in your case (nixosConfiguration -> colmena) you don’t get the exact same output between |
I would also like this feature. My use-case is that my colmena configuration contains the list of hosts, IP addresses, and DNS names. I have an app defined in my flake that takes this information and generates a Terraform config I can use to update Route 53 (i.e. I can run I'm working around this by having an extra nix file that just duplicates the information and doesn't require any evaluation, but I'd love to get rid of it. |
Why not use that extra file as single source of truth and import it onto the flake(s) instead? |
It’s not sufficient if you have configuration that depends on other nodes (i.e. if you use the |
That's basically what I'm doing, but I don't like it. As in, I'd much rather write The thing that makes me dislike the above is that the IP address string I have is the input of some potentially complicated expression. For example, my machines file specifies |
I made a PR that documents how to install NixOS with Colmena, #209 Hopefully this helps! |
@itslychee That's a nice tutorial, but I'm struggling to see how it relates to anything here. This PR is about getting the generated |
you're right, i should read more. Personally was having issues with this and was seeing if anyone else was confused so i could help out in any way! |
This PR adds a function to load colmena hive from the flake.
Use case:
If I have a flake output like this:
Currently I have no way to obtain the nixosConfiguration associated to systemA and systemB. With this new function, I can now do for instance
And this nixosConfiguration will contain the same system as the one that would be built by colmena. This is incomplete (keys are not uploaded), but it is still useful in (at least) two situations:
This function roughly adds the same content as what "colmena repl" gives access to, but in a nix evaluation context.