From e910f4769c7576a116f2addcc15ad996dcb01ba8 Mon Sep 17 00:00:00 2001 From: Roman Melnikov Date: Tue, 12 Sep 2023 11:27:24 +0200 Subject: [PATCH] fixup! [#201] Deduce profile directory during activation --- src/bin/activate.rs | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/bin/activate.rs b/src/bin/activate.rs index 26f59379..f4e78d61 100644 --- a/src/bin/activate.rs +++ b/src/bin/activate.rs @@ -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( @@ -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)) } } }