Skip to content

Commit

Permalink
[#201] Deduce profile directory during activation
Browse files Browse the repository at this point in the history
Problem: Since NixOS/nix#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.
  • Loading branch information
rvem committed Sep 11, 2023
1 parent 724463b commit 44b1b90
Show file tree
Hide file tree
Showing 6 changed files with 301 additions and 67 deletions.
163 changes: 144 additions & 19 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ edition = "2018"

[dependencies]
clap = { version = "3.0.0-beta.2", features = [ "wrap_help" ] }
dirs = "5.0.1"
flexi_logger = "0.16"
fork = "0.1"
futures-util = "0.3.6"
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ 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), and `/nix/var/nix/profiles/per-user/$USER/$PROFILE_NAME` if it is not.
# 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.
profilePath = "/nix/var/nix/profiles/per-user/someuser/someprofile";
# ...generic options... (see lower section)
Expand Down
Loading

0 comments on commit 44b1b90

Please sign in to comment.