diff --git a/README.md b/README.md index db9a92e5..9a6ffe10 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/src/bin/activate.rs b/src/bin/activate.rs index cf4a4002..26f59379 100644 --- a/src/bin/activate.rs +++ b/src/bin/activate.rs @@ -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); @@ -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)) } } }