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 11, 2023
1 parent 44b1b90 commit 6c7086d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,10 @@ This is the core of how `deploy-rs` was designed, any number of these can run on
path = deploy-rs.lib.x86_64-linux.activate.custom pkgs.hello "./bin/hello";
# An optional path to where your profile should be installed to, this is useful if you want to use a common profile name across multiple users, but would have conflicts in your node's profile list.
# This will default to `"/nix/var/nix/profiles/$PROFILE_NAME` if `user` is root (see: generic options), `/nix/var/nix/profiles/per-user/$USER/$PROFILE_NAME` if
# `/nix/var/nix/profiles/per-user/$USER` already exists, and `${XDG_STATE_HOME:-$HOME}/.local/state/nix/profiles/$PROFILE_NAME` otherwise.
# This will default to `"/nix/var/nix/profiles/system` if `user` is `root` and profile name is `system`,
# `/nix/var/nix/profiles/per-user/root/$PROFILE_NAME` if profile name is different.
# For non-root profiles will default to /nix/var/nix/profiles/per-user/$USER/$PROFILE_NAME if `/nix/var/nix/profiles/per-user/$USER` already exists,
# and `${XDG_STATE_HOME:-$HOME/.local/state}/nix/profiles/$PROFILE_NAME` otherwise.
profilePath = "/nix/var/nix/profiles/per-user/someuser/someprofile";
# ...generic options... (see lower section)
Expand Down
20 changes: 14 additions & 6 deletions src/bin/activate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,16 @@ fn get_profile_path(
let nix_state_dir = env::var("NIX_STATE_DIR").unwrap_or("/nix/var/nix".to_string());
// As per https://nixos.org/manual/nix/stable/command-ref/files/profiles#profiles
match &profile_user[..] {
"root" => Ok(format!("{}/profiles/{}", nix_state_dir, profile_name)),
"root" => {
match &profile_name[..] {
// NixOS system profile belongs to the root user, but isn't stored in the 'per-user/root'
"system" => Ok(format!("{}/profiles/system", nix_state_dir)),
_ => Ok(format!(
"{}/profiles/per-user/root/{}",
nix_state_dir, profile_name
)),
}
}
_ => {
let old_user_profiles_dir =
format!("{}/profiles/per-user/{}", nix_state_dir, profile_user);
Expand All @@ -508,13 +517,12 @@ fn get_profile_path(
// 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()))
.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
))
Ok(format!("{}/nix/profiles/{}", state_dir, profile_name))
}
}
}
Expand Down

0 comments on commit 6c7086d

Please sign in to comment.