infinisil / nixus

Experimental deployment tool supporting multi-host abstractions
GNU General Public License v3.0
195 stars 15 forks source link

Feature wishlist and general orientation of this tool #2

Open infinisil opened 4 years ago

infinisil commented 4 years ago

https://discourse.nixos.org/t/seeking-help-to-understand-nixops-use-cases/5468

infinisil commented 3 years ago

In #nixus, @ashkitten was wondering about bootstrapping a system (logs). A possibility I thought of:

infinisil commented 3 years ago

In #nixos-chat @andir was talking about wanting to have machines configs depend on IP's yet to be provisioned, and related things (logs). After thinking about this, I came up with the following idea that generalizes this concept well:

This could look like this:

{ pkgs, ... }: {
  phases.provision = {}: {
    executable = pkgs.writeScript "provision" ''
      ip=$(curl https://my.provider/provision)
      echo "{ \"ip\" : $ip }"
    '';
    # If this file exists, its value will be used as the phase output
    # If it doesn't exist, the output is written there on phase call
    persistTo = ./provision.json;
  };
  # The deploy phase depends on the provision phases output, which will be
  # passed to this function
  phases.deploy = { provision }: {
    executable = pkgs.writeScript "deploy" ''
      nix-copy-closure --to ${provision.ip} ${<system-closure>}
      ssh ${provision.ip} ${<system-closure>}/bin/switch-to-configuration switch
    '';
  };
}