Skip to content

Commit 3180b55

Browse files
authored
Merge pull request #148 from afontaine/afontaine/add-doas-support
Add custom sudo command support
2 parents 0ac333c + 874af9b commit 3180b55

File tree

4 files changed

+20
-1
lines changed

4 files changed

+20
-1
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,11 @@ This is a set of options that can be put in any of the above definitions, with t
159159
# If `sshUser` is specified, this will be the default (though it will _not_ default to your own username)
160160
user = "root";
161161
162+
# Which sudo command to use. Must accept at least two arguments:
163+
# the user name to execute commands as and the rest is the command to execute
164+
# This will default to "sudo -u" if not specified anywhere.
165+
sudo = "doas -u";
166+
162167
# This is an optional list of arguments that will be passed to SSH.
163168
sshOpts = [ "-p" "2121" ];
164169

src/cli.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ pub struct Opts {
8989
/// Revoke all previously succeeded deploys when deploying multiple profiles
9090
#[clap(long)]
9191
rollback_succeeded: Option<bool>,
92+
/// Which sudo command to use. Must accept at least two arguments: user name to execute commands as and the rest is the command to execute
93+
#[clap(long)]
94+
sudo: Option<String>,
9295
}
9396

9497
/// Returns if the available Nix installation supports flakes
@@ -635,6 +638,7 @@ pub async fn run(args: Option<&ArgMatches>) -> Result<(), RunError> {
635638
temp_path: opts.temp_path,
636639
confirm_timeout: opts.confirm_timeout,
637640
dry_activate: opts.dry_activate,
641+
sudo: opts.sudo,
638642
};
639643

640644
let supports_flakes = test_flake_support().await.map_err(RunError::FlakeTest)?;

src/data.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ pub struct GenericSettings {
2828
pub temp_path: Option<String>,
2929
#[serde(rename(deserialize = "magicRollback"))]
3030
pub magic_rollback: Option<bool>,
31+
#[serde(rename(deserialize = "sudo"))]
32+
pub sudo: Option<String>,
3133
}
3234

3335
#[derive(Deserialize, Debug, Clone)]

src/lib.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ pub struct CmdOverrides {
161161
pub magic_rollback: Option<bool>,
162162
pub temp_path: Option<String>,
163163
pub confirm_timeout: Option<u16>,
164+
pub sudo: Option<String>,
164165
pub dry_activate: bool,
165166
}
166167

@@ -350,7 +351,7 @@ impl<'a> DeployData<'a> {
350351
let profile_path = self.get_profile_path()?;
351352

352353
let sudo: Option<String> = match self.merged_settings.user {
353-
Some(ref user) if user != &ssh_user => Some(format!("sudo -u {}", user)),
354+
Some(ref user) if user != &ssh_user => Some(format!("{} {}", self.get_sudo(), user)),
354355
_ => None,
355356
};
356357

@@ -392,6 +393,13 @@ impl<'a> DeployData<'a> {
392393
};
393394
Ok(profile_user)
394395
}
396+
397+
fn get_sudo(&'a self) -> String {
398+
return match self.merged_settings.sudo {
399+
Some(ref x) => x.clone(),
400+
None => "sudo -u".to_string()
401+
};
402+
}
395403
}
396404

397405
pub fn make_deploy_data<'a, 's>(

0 commit comments

Comments
 (0)