Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

document finding unpersisted files #240

Open
KiaraGrouwstra opened this issue Dec 8, 2024 · 0 comments
Open

document finding unpersisted files #240

KiaraGrouwstra opened this issue Dec 8, 2024 · 0 comments

Comments

@KiaraGrouwstra
Copy link

KiaraGrouwstra commented Dec 8, 2024

hi there,
i feel like one challenge in using impermanence has been to figure out what state needs persisting.

for example, given persist dirs like /persist/home/$USER (and in my case a disko LUKS partition on disk main), i tried to answer that question using a script like:

# list-ephemeral.sh
# usage example: sh list-ephemeral.sh $HOME | $PAGER
user="$(whoami)"
DIR="${1:-$HOME}"
enquote_pattern="s@\(.*\)@-path '\1' -prune -o@g"
prepend_pattern="s@\(.*\)@-path '$HOME/\1' -prune -o@g"

system_global_dirs=$(nix eval ".#nixosConfigurations.default.config.environment.persistence.\"/persist\".directories" --json | jq -r '.[].dirPath' | sed "$enquote_pattern")
system_global_files=$(nix eval ".#nixosConfigurations.default.config.environment.persistence.\"/persist\".files" --json | jq -r '.[].filePath' | sed "$enquote_pattern")
system_user_dirs=$(nix eval ".#nixosConfigurations.default.config.environment.persistence.\"/persist\".users.$user.directories" --json | jq -r '.[].dirPath' | sed "$enquote_pattern")
system_user_files=$(nix eval ".#nixosConfigurations.default.config.environment.persistence.\"/persist\".users.$user.files" --json | jq -r '.[].filePath' | sed "$enquote_pattern")
home_dirs=$(nix eval ".#nixosConfigurations.default.config.home-manager.users.$user.home.persistence.\"/persist/home/$user\".directories" --json | jq -r '.[]' | sed "$prepend_pattern")
home_files=$(nix eval ".#nixosConfigurations.default.config.home-manager.users.$user.home.persistence.\"/persist/home/$user\".files" --json | jq -r '.[]' | sed "$prepend_pattern")
disk_subvolumes=$(nix eval ".#nixosConfigurations.default.config.disko.devices.disk.\"main\".content.partitions.luks.content.content.subvolumes" --json | jq -r '.[].mountpoint | select(. != "/")' | sed "$enquote_pattern")

cmd="find '$DIR' \
      $system_global_dirs \
      $system_global_files \
      $system_user_dirs \
      $system_user_files \
      $home_dirs \
      $home_files \
      $disk_subvolumes \
  -type f -printf '%p\\n'"

# shellcheck disable=SC2086
eval $cmd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant