From 932bf43f0eb857edcf55742f239f459451ab47e5 Mon Sep 17 00:00:00 2001 From: AmineChikhaoui Date: Wed, 17 Apr 2019 09:28:05 -0400 Subject: [PATCH 1/2] update release date --- doc/manual/release-notes.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/manual/release-notes.xml b/doc/manual/release-notes.xml index ce125d544..205d61aef 100644 --- a/doc/manual/release-notes.xml +++ b/doc/manual/release-notes.xml @@ -5,7 +5,7 @@ -
Release 1.7 (April XX, 2019) +
Release 1.7 (April 17, 2019) General From eee6bd4ab0f82279e4b76a0e9e351e9412beffb3 Mon Sep 17 00:00:00 2001 From: exfalso <0slemi0@gmail.com> Date: Wed, 9 Feb 2022 13:02:06 +0100 Subject: [PATCH 2/2] Add deployment.bootstrapScript hook --- nix/eval-machine-info.nix | 2 +- nix/options.nix | 10 ++++++++++ nixops/backends/none.py | 5 +++++ nixops/deployment.py | 14 ++++++++++++++ 4 files changed, 30 insertions(+), 1 deletion(-) diff --git a/nix/eval-machine-info.nix b/nix/eval-machine-info.nix index e2e1def51..407526dda 100644 --- a/nix/eval-machine-info.nix +++ b/nix/eval-machine-info.nix @@ -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; diff --git a/nix/options.nix b/nix/options.nix index 0866c3ab8..6afd2c4d2 100644 --- a/nix/options.nix +++ b/nix/options.nix @@ -57,6 +57,16 @@ in ''; }; + deployment.bootstrapScript = mkOption { + type = types.nullOr types.lines; + default = null; + 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 = '' diff --git a/nixops/backends/none.py b/nixops/backends/none.py index 7971fc169..3d7f36e00 100644 --- a/nixops/backends/none.py +++ b/nixops/backends/none.py @@ -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.""" @@ -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) @@ -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... ") diff --git a/nixops/deployment.py b/nixops/deployment.py index 31f32ac31..3ea498ff8 100644 --- a/nixops/deployment.py +++ b/nixops/deployment.py @@ -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, @@ -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)