Open infinisil opened 4 years ago
In #nixus, @ashkitten was wondering about bootstrapping a system (logs). A possibility I thought of:
system.bootstrap = true
, which would turn off all non-essential system config, only leaving things like networking, hardware, filesystems, etc.nixos-install
can be used to install such a bootstrap system.drv
closure of the full system could also be installed with nixos-install
, such that on first boot, the system can start building that and switch to it automagically.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
'';
};
}
https://discourse.nixos.org/t/seeking-help-to-understand-nixops-use-cases/5468