Skip to content

Commit

Permalink
Merge pull request #197 from minhuw/main
Browse files Browse the repository at this point in the history
Support adding extra ssh options on node configurations
  • Loading branch information
zhaofengli committed Mar 23, 2024
2 parents c84ccd0 + afa7439 commit 7997ab7
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/nix/hive/options.nix
Expand Up @@ -208,6 +208,13 @@ with builtins; rec {
type = types.listOf types.str;
default = [ "sudo" "-H" "--" ];
};
sshOptions = 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
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
Expand Up @@ -78,6 +78,9 @@ pub struct NodeConfig {
#[serde(rename = "privilegeEscalationCommand")]
privilege_escalation_command: Vec<String>,

#[serde(rename = "sshOptions")]
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
1 change: 1 addition & 0 deletions src/nix/node_filter.rs
Expand Up @@ -248,6 +248,7 @@ mod tests {
build_on_target: false,
replace_unknown_profiles: false,
privilege_escalation_command: vec![],
extra_ssh_options: vec![],
keys: HashMap::new(),
};

Expand Down

0 comments on commit 7997ab7

Please sign in to comment.