Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion nix/eval-machine-info.nix
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ rec {

machines =
flip mapAttrs nodes (n: v': let v = scrubOptionValue v'; in
{ inherit (v.config.deployment) targetEnv targetPort targetHost encryptedLinksTo storeKeysOnMachine alwaysActivate owners keys hasFastConnection;
{ inherit (v.config.deployment) targetEnv targetPort targetHost encryptedLinksTo storeKeysOnMachine alwaysActivate owners keys hasFastConnection bootstrapScript;
nixosRelease = v.config.system.nixos.release or v.config.system.nixosRelease or (removeSuffix v.config.system.nixosVersionSuffix v.config.system.nixosVersion);
azure = optionalAttrs (v.config.deployment.targetEnv == "azure") v.config.deployment.azure;
ec2 = optionalAttrs (v.config.deployment.targetEnv == "ec2") v.config.deployment.ec2;
Expand Down
10 changes: 10 additions & 0 deletions nix/options.nix
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ in
'';
};

deployment.bootstrapScript = mkOption {
type = types.nullOr types.lines;
default = null;
Comment on lines +61 to +62

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
type = types.nullOr types.lines;
default = null;
type = types.lines;
default = "";

description = ''
This option specifies an optional bash script to be run on the target
before nix-specific operations are run. It only assumes `bash` to be
installed on the target.
'';
};

deployment.targetPort = mkOption {
type = types.int;
description = ''
Expand Down
5 changes: 5 additions & 0 deletions nixops/backends/none.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ def __init__(self, xml, config):
public_ipv4 = xml.find("attrs/attr[@name='publicIPv4']/string")
self._public_ipv4 = None if public_ipv4 is None else public_ipv4.get("value")

bootstrap_cript = xml.find("attrs/attr[@name='bootstrapScript']/string")
self._bootstrap_script = None if bootstrap_cript is None else bootstrap_cript.get("value")

class NoneState(MachineState):
"""State of a trivial machine."""

Expand All @@ -30,6 +33,7 @@ def get_type(cls):

target_host = nixops.util.attr_property("targetHost", None)
public_ipv4 = nixops.util.attr_property("publicIpv4", None)
bootstrap_script = nixops.util.attr_property("bootstrapScript", None)
_ssh_private_key = attr_property("none.sshPrivateKey", None)
_ssh_public_key = attr_property("none.sshPublicKey", None)
_ssh_public_key_deployed = attr_property("none.sshPublicKeyDeployed", False, bool)
Expand All @@ -52,6 +56,7 @@ def create(self, defn, check, allow_reboot, allow_recreate):
self.set_common_state(defn)
self.target_host = defn._target_host
self.public_ipv4 = defn._public_ipv4
self.bootstrap_script = defn._bootstrap_script

if not self.vm_id:
self.log_start("generating new SSH keypair... ")
Expand Down
14 changes: 14 additions & 0 deletions nixops/deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -1004,6 +1004,8 @@ def worker(r):

if build_only or dry_run: return

self.bootstrap_resources()

# Copy the closures of the machine configurations to the
# target machines.
self.copy_closures(self.configs_path, include=include, exclude=exclude,
Expand Down Expand Up @@ -1229,6 +1231,18 @@ def worker(m):

nixops.parallel.run_tasks(nr_workers=-1, tasks=self.active.itervalues(), worker_fun=worker)

def bootstrap_resources(self):

def worker(r):
if is_machine(r):
if r.bootstrap_script is not None:
r.run_command(r.bootstrap_script)

nixops.parallel.run_tasks(
nr_workers=-1,
tasks=iter(self.active_resources.values()),
worker_fun=worker,
)

def should_do(m, include, exclude):
return should_do_n(m.name, include, exclude)
Expand Down