Skip to content

Commit

Permalink
Support adding extra ssh options on node configurations
Browse files Browse the repository at this point in the history
  • Loading branch information
minhuw committed Feb 27, 2024
1 parent c84ccd0 commit d5e0e2f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/nix/hive/options.nix
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,13 @@ with builtins; rec {
type = types.listOf types.str;
default = [ "sudo" "-H" "--" ];
};
extraSSHOptions = lib.mkOption {
description = mdDoc ''
Extra SSH options to pass to the SSH command.
'';
type = types.listOf types.str;
default = [];
};
};
};
};
Expand Down
9 changes: 9 additions & 0 deletions src/nix/host/ssh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ pub struct Ssh {
/// Command to elevate privileges with.
privilege_escalation_command: Vec<String>,

/// extra SSH options
extra_ssh_options: Vec<String>,

/// Whether to use the experimental `nix copy` command.
use_nix3_copy: bool,

Expand Down Expand Up @@ -189,6 +192,7 @@ impl Ssh {
port: None,
ssh_config: None,
privilege_escalation_command: Vec::new(),
extra_ssh_options: Vec::new(),
use_nix3_copy: false,
job: None,
}
Expand All @@ -206,6 +210,10 @@ impl Ssh {
self.privilege_escalation_command = command;
}

pub fn set_extra_ssh_options(&mut self, options: Vec<String>) {
self.extra_ssh_options = options;
}

pub fn set_use_nix3_copy(&mut self, enable: bool) {
self.use_nix3_copy = enable;
}
Expand Down Expand Up @@ -346,6 +354,7 @@ impl Ssh {
]
.iter()
.map(|s| s.to_string())
.chain(self.extra_ssh_options.clone())
.collect();

if let Some(port) = self.port {
Expand Down
4 changes: 4 additions & 0 deletions src/nix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ pub struct NodeConfig {
#[serde(rename = "privilegeEscalationCommand")]
privilege_escalation_command: Vec<String>,

#[serde(rename = "extraSSHOptions")]
extra_ssh_options: Vec<String>,

#[validate(custom = "validate_keys")]
keys: HashMap<String, Key>,
}
Expand Down Expand Up @@ -181,6 +184,7 @@ impl NodeConfig {
self.target_host.as_ref().map(|target_host| {
let mut host = Ssh::new(self.target_user.clone(), target_host.clone());
host.set_privilege_escalation_command(self.privilege_escalation_command.clone());
host.set_extra_ssh_options(self.extra_ssh_options.clone());

if let Some(target_port) = self.target_port {
host.set_port(target_port);
Expand Down

0 comments on commit d5e0e2f

Please sign in to comment.