Skip to content

Commit

Permalink
fixup! [#201] Deduce profile directory during activation
Browse files Browse the repository at this point in the history
  • Loading branch information
rvem committed Sep 12, 2023
1 parent 56d5497 commit e910f47
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions src/bin/activate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -482,8 +482,8 @@ async fn revoke(profile_path: String) -> Result<(), DeactivateError> {

#[derive(Error, Debug)]
pub enum GetProfilePathError {
#[error("Failed to deduce HOME directory for user {0}")]
NoUserHome(String),
#[error("Failed to deduce state directory for user {0}")]
NoUserStateDir(String),
}

fn get_profile_path(
Expand Down Expand Up @@ -515,14 +515,8 @@ fn get_profile_path(
Ok(format!("{}/{}", old_user_profiles_dir, profile_name))
} else {
// https://github.com/NixOS/nix/blob/2.17.0/src/libstore/profiles.cc#L308
let state_dir = env::var("XDG_STATE_HOME").or_else(|_| {
dirs::home_dir()
.map(|h| {
format!("{}/.local/state", h.as_path().display().to_string())
})
.ok_or(GetProfilePathError::NoUserHome(profile_user))
})?;
Ok(format!("{}/nix/profiles/{}", state_dir, profile_name))
let state_dir = dirs::state_dir().ok_or(GetProfilePathError::NoUserStateDir(profile_user))?;
Ok(format!("{}/nix/profiles/{}", state_dir.display(), profile_name))
}
}
}
Expand Down

0 comments on commit e910f47

Please sign in to comment.