aboutsummaryrefslogtreecommitdiff
path: root/src/lib.rs
diff options
context:
space:
mode:
authorRoman Melnikov2023-09-06 14:54:22 +0200
committerRoman Melnikov2023-09-12 12:00:17 +0200
commitf26e888c41d28107de9dbc5b4e1553c1dfcf83db (patch)
treee3a76bfd3b13bcd2888cabfc7cd6cada32129139 /src/lib.rs
parent724463b5a94daa810abfc64a4f87faef4e00f984 (diff)
[#201] Deduce profile directory during activation
Problem: Since https://github.com/NixOS/nix/pull/5226 nix profiles for users are stored in 'XDG_STATE_HOME' or 'HOME' directory. However, 'deploy-rs' still expects profiles to be present in '/nix/var/nix/profiles/per-user'. As a result, an attempt to deploy a profile with newer nix may fail with an error about non-existing files. Solution: Instead of deducing the profile path prior to ssh'ing and actual activation, deduce the path to the profile during as a part of 'activate-rs' invocation. Now if the profile path is not specified explicitly as an attribute in profile within the deploy flake, the path to the profile is determined based on the user to which the profile belongs and on the values of 'XDG_STATE_HOME' and 'HOME' variables. Additionally, if the old profile directory (in '/nix/var/nix/profiles/per-user') for a given user already exists, it is used instead for the sake of backward compatibility.
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs38
1 files changed, 19 insertions, 19 deletions
diff --git a/src/lib.rs b/src/lib.rs
index c6f8e03..0e5d817 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -332,9 +332,17 @@ pub struct DeployData<'a> {
pub struct DeployDefs {
pub ssh_user: String,
pub profile_user: String,
- pub profile_path: String,
pub sudo: Option<String>,
}
+enum ProfileInfo {
+ ProfilePath {
+ profile_path: String,
+ },
+ ProfileUserAndName {
+ profile_user: String,
+ profile_name: String,
+ },
+}
#[derive(Error, Debug)]
pub enum DeployDataDefsError {
@@ -351,8 +359,6 @@ impl<'a> DeployData<'a> {
let profile_user = self.get_profile_user()?;
- let profile_path = self.get_profile_path()?;
-
let sudo: Option<String> = match self.merged_settings.user {
Some(ref user) if user != &ssh_user => Some(format!("{} {}", self.get_sudo(), user)),
_ => None,
@@ -361,26 +367,10 @@ impl<'a> DeployData<'a> {
Ok(DeployDefs {
ssh_user,
profile_user,
- profile_path,
sudo,
})
}
- fn get_profile_path(&'a self) -> Result<String, DeployDataDefsError> {
- let profile_user = self.get_profile_user()?;
- let profile_path = match self.profile.profile_settings.profile_path {
- None => match &profile_user[..] {
- "root" => format!("/nix/var/nix/profiles/{}", self.profile_name),
- _ => format!(
- "/nix/var/nix/profiles/per-user/{}/{}",
- profile_user, self.profile_name
- ),
- },
- Some(ref x) => x.clone(),
- };
- Ok(profile_path)
- }
-
fn get_profile_user(&'a self) -> Result<String, DeployDataDefsError> {
let profile_user = match self.merged_settings.user {
Some(ref x) => x.clone(),
@@ -403,6 +393,16 @@ impl<'a> DeployData<'a> {
None => "sudo -u".to_string(),
}
}
+
+ fn get_profile_info(&'a self) -> Result<ProfileInfo, DeployDataDefsError> {
+ match self.profile.profile_settings.profile_path {
+ Some(ref profile_path) => Ok(ProfileInfo::ProfilePath { profile_path: profile_path.to_string() }),
+ None => {
+ let profile_user = self.get_profile_user()?;
+ Ok(ProfileInfo::ProfileUserAndName { profile_user, profile_name: self.profile_name.to_string() })
+ },
+ }
+ }
}
pub fn make_deploy_data<'a, 's>(