feat: Expose an app for rebuilding host configurations.
Maybe related to #83, but this one is specific for exposing apps to build nixosConfigurations and darwinConfigurations.
My current use case is this: Expose an app that lets me apply a host configuration on a fresh OS install.
For example, suppose I have a nix-darwin system named yavanna and a fresh MacOS installation.
After installing Nix, I'd love to just run:
nix run github:vic/vix#yavanna-rebuild switch
instead of this -- a bit hairy since darwin-rebuild is not exposed as an app:
nix shell github:LnL7/nix-darwin#darwin-rebuild --command darwin-rebuild --flake github:vic/vix#yavanna switch
The same would be possible for nixosConfigurations but using nixos-rebuild.
I have already implemented it on my hosts flake
$ nix flake show
...
├───apps
│ ├───x86_64-darwin
│ │ └───yavanna-rebuild: app
│ └───x86_64-linux
│ ├───annatar-rebuild: app
│ ├───mordor-rebuild: app
│ └───nargun-rebuild: app
Now, I'm not really sure this would be something worth having in blueprint itself, since maybe my use case is very particular - or at least just a convenience for me -. So, feel free to close this issue if you think like there is no value on having something like this for many blueprint users.
This might be of the domain of the deploy tool.
Ideally we want blueprint to integrate with colmena, comin, etc... Or at least propose a generic interface those tools can use.
Potentially blueprint itself could ship with a CLI that handles these things. ie: bp host switch [--host $HOSTNAME] or nix run .#bp host switch.
All of this is kinda on the table at the moment, but I agree with the premise of the ticket, that users should have access to a blessed way to rebuild switch their host.
Hi,
Just for reference, here's my packages/os-rebuild.nix that works as your second example CLI.
When running on an x86_64-linux, using --help will list all hosts defined for the same system. Which can be given as the first argument. Otherwise the uname -n is used to guess the current hostname.
On other systems like aarm64-darwin the script will mention darwin-rebuild instead of nixos-rebuild and will show hosts from same system.
Default action is switch meaning I just do nix run when applying new changes to my system (since I have this os-rebuild app also as default package).
$ nix run .#os-rebuild -- --help
Usage: os-rebuild [HOSTNAME] [NIXOS-REBUILD OPTIONS ...]
Default hostname: nargun
Default nixos-rebuild options: switch
Known hostnames on x86_64-linux:
annatar
mordor
nargun
nienna
Some other examples (these using nixos-rebuild options):
# with no arguments, switch the system matching current hostname.
$ nix run .#os-rebuild
# build and add to bootloader but not switch to it until reboot.
$ nix run .#os-rebuild boot
# explicit about what hostConfiguration to build an image for.
$ nix run .#os-rebuild mordor build-image
If you like this CLI utility, I could contribute it back into blueprint.