Skip to content

Commit e92ebe3

Browse files
timothyklimneunenak
authored andcommitted
Add SSH compress to nix copy
1 parent 06d5a10 commit e92ebe3

7 files changed

Lines changed: 21 additions & 1 deletion

File tree

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,10 @@ This is a set of options that can be put in any of the above definitions, with t
220220
# This defaults to `false`
221221
fastConnection = false;
222222
223+
# Use SSH gzip compress for `nix copy`.
224+
# This defaults to `false`
225+
compress = true;
226+
223227
# If the previous profile should be re-activated if activation fails.
224228
# This defaults to `true`
225229
autoRollback = true;

examples/system/flake.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
sshOpts = [ "-p" "2221" ];
2727
hostname = "localhost";
2828
fastConnection = true;
29+
compress = true;
2930
interactiveSudo = true;
3031
profiles = {
3132
system = {

interface.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
"fastConnection": {
2222
"type": "boolean"
2323
},
24+
"compress": {
25+
"type": "boolean"
26+
},
2427
"autoRollback": {
2528
"type": "boolean"
2629
},

src/cli.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ pub struct Opts {
7474
/// Override the SSH options used
7575
#[arg(long, allow_hyphen_values = true)]
7676
ssh_opts: Option<String>,
77+
/// Override the SSH compression when using `nix copy`
78+
#[clap(long)]
79+
compress: Option<bool>,
7780
/// Override if the connecting to the target node should be considered fast
7881
#[arg(long)]
7982
fast_connection: Option<bool>,
@@ -702,6 +705,7 @@ pub async fn run(args: Option<&ArgMatches>) -> Result<(), RunError> {
702705
profile_user: opts.profile_user,
703706
ssh_opts: opts.ssh_opts,
704707
fast_connection: opts.fast_connection,
708+
compress: opts.compress,
705709
auto_rollback: opts.auto_rollback,
706710
hostname: opts.hostname,
707711
magic_rollback: opts.magic_rollback,

src/data.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ pub struct GenericSettings {
1919
)]
2020
#[merge(strategy = merge::vec::append)]
2121
pub ssh_opts: Vec<String>,
22+
#[serde(rename(deserialize = "compress"))]
23+
pub compress: Option<bool>,
2224
#[serde(rename(deserialize = "fastConnection"))]
2325
pub fast_connection: Option<bool>,
2426
#[serde(rename(deserialize = "autoRollback"))]

src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ pub struct CmdOverrides {
157157
pub ssh_user: Option<String>,
158158
pub profile_user: Option<String>,
159159
pub ssh_opts: Option<String>,
160+
pub compress: Option<bool>,
160161
pub fast_connection: Option<bool>,
161162
pub auto_rollback: Option<bool>,
162163
pub hostname: Option<String>,
@@ -454,6 +455,9 @@ pub fn make_deploy_data<'a, 's>(
454455
if let Some(fast_connection) = cmd_overrides.fast_connection {
455456
merged_settings.fast_connection = Some(fast_connection);
456457
}
458+
if let Some(compress) = cmd_overrides.compress {
459+
merged_settings.compress = Some(compress);
460+
}
457461
if let Some(auto_rollback) = cmd_overrides.auto_rollback {
458462
merged_settings.auto_rollback = Some(auto_rollback);
459463
}

src/push.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,9 +351,11 @@ pub async fn push_profile(data: PushProfileData<'_>) -> Result<(), PushProfileEr
351351
None => &data.deploy_data.node.node_settings.hostname,
352352
};
353353

354+
let compress = data.deploy_data.merged_settings.compress.unwrap_or_else(|| false);
355+
354356
let copy_exit_status = copy_command
355357
.arg("--to")
356-
.arg(format!("ssh://{}@{}", data.deploy_defs.ssh_user, hostname))
358+
.arg(format!("ssh://{}@{}?compress={}", data.deploy_defs.ssh_user, hostname, compress))
357359
.arg(&data.deploy_data.profile.profile_settings.path)
358360
.env("NIX_SSHOPTS", ssh_opts_str)
359361
.status()

0 commit comments

Comments
 (0)