Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SSH compress to nix copy #297

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,10 @@ This is a set of options that can be put in any of the above definitions, with t
# This defaults to `false`
fastConnection = false;

# Use SSH gzip compress for `nix copy`.
# This defaults to `false`
compress = true;

# If the previous profile should be re-activated if activation fails.
# This defaults to `true`
autoRollback = true;
Expand Down
1 change: 1 addition & 0 deletions examples/system/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
sshOpts = [ "-p" "2221" ];
hostname = "localhost";
fastConnection = true;
compress = true;
interactiveSudo = true;
profiles = {
system = {
Expand Down
3 changes: 3 additions & 0 deletions interface.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
"fastConnection": {
"type": "boolean"
},
"compress": {
"type": "boolean"
},
"autoRollback": {
"type": "boolean"
},
Expand Down
4 changes: 4 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ pub struct Opts {
/// Override the SSH options used
#[clap(long, allow_hyphen_values = true)]
ssh_opts: Option<String>,
/// Override the SSH compression when using `nix copy`
#[clap(long)]
compress: Option<bool>,
/// Override if the connecting to the target node should be considered fast
#[clap(long)]
fast_connection: Option<bool>,
Expand Down Expand Up @@ -687,6 +690,7 @@ pub async fn run(args: Option<&ArgMatches>) -> Result<(), RunError> {
profile_user: opts.profile_user,
ssh_opts: opts.ssh_opts,
fast_connection: opts.fast_connection,
compress: opts.compress,
auto_rollback: opts.auto_rollback,
hostname: opts.hostname,
magic_rollback: opts.magic_rollback,
Expand Down
2 changes: 2 additions & 0 deletions src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ pub struct GenericSettings {
)]
#[merge(strategy = merge::vec::append)]
pub ssh_opts: Vec<String>,
#[serde(rename(deserialize = "compress"))]
pub compress: Option<bool>,
#[serde(rename(deserialize = "fastConnection"))]
pub fast_connection: Option<bool>,
#[serde(rename(deserialize = "autoRollback"))]
Expand Down
4 changes: 4 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ pub struct CmdOverrides {
pub ssh_user: Option<String>,
pub profile_user: Option<String>,
pub ssh_opts: Option<String>,
pub compress: Option<bool>,
pub fast_connection: Option<bool>,
pub auto_rollback: Option<bool>,
pub hostname: Option<String>,
Expand Down Expand Up @@ -439,6 +440,9 @@ pub fn make_deploy_data<'a, 's>(
if let Some(fast_connection) = cmd_overrides.fast_connection {
merged_settings.fast_connection = Some(fast_connection);
}
if let Some(compress) = cmd_overrides.compress {
merged_settings.compress = Some(compress);
}
if let Some(auto_rollback) = cmd_overrides.auto_rollback {
merged_settings.auto_rollback = Some(auto_rollback);
}
Expand Down
4 changes: 3 additions & 1 deletion src/push.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,9 +322,11 @@ pub async fn push_profile(data: PushProfileData<'_>) -> Result<(), PushProfileEr
None => &data.deploy_data.node.node_settings.hostname,
};

let compress = data.deploy_data.merged_settings.compress.unwrap_or_else(|| false);

let copy_exit_status = copy_command
.arg("--to")
.arg(format!("ssh://{}@{}", data.deploy_defs.ssh_user, hostname))
.arg(format!("ssh://{}@{}?compress={}", data.deploy_defs.ssh_user, hostname, compress))
.arg(&data.deploy_data.profile.profile_settings.path)
.env("NIX_SSHOPTS", ssh_opts_str)
.status()
Expand Down