{ pkgs, inputs, ... }:
pkgs.writeShellApplication {
  name = "create-instance";
  runtimeInputs = [
    pkgs.khscodes.provision-instance
    pkgs.khscodes.nixos-install
    pkgs.jq
  ];
  text = ''
    hostname="$1"
    # Build the configuration to ensure it doesn't fail when trying to install it on the host
    nix build --no-link '${inputs.self}#nixosConfigurations."'"$hostname"'".config.system.build.toplevel'
    output="$(provision-instance "$hostname")"
    ipv4_addr="$(echo "$output" | jq --raw-output '.ipv4_address.value')"
    nixos-install "$hostname" "$ipv4_addr" "no"
  '';
}
