dustinlyons / nixos-config

General purpose Nix configuration for macOS / NixOS with starter templates + step-by-step guides ✨
BSD 3-Clause "New" or "Revised" License
1.8k stars 113 forks source link

Add -b backup to `home-manager switch` #50

Closed multivac61 closed 9 months ago

multivac61 commented 9 months ago

Would it be possible to automatically backup files via -b flag to home-manager. Unfortunately I don't know how to add that into the darwin.lib.darwinSystem or /apps/ directory.

dustinlyons commented 9 months ago

Hi @multivac61, this project doesn't use the imperative home-manager commands so we'd have to find a way to make the Nix daemon recognize it as part of the home-manager module build.

I dug into the home-manager code and it looks like it's as simple as setting an environment variable.

        export HOME_MANAGER_BACKUP_EXT="$1"

https://github.com/nix-community/home-manager/blob/f99eace7c167b8a6a0871849493b1c613d0f1b80/home-manager/home-manager#L947C13-L947C48

The argument $1 in this case is just the path where you want to save backups. I would experiment with adding this to your .zsh configuration or whatever you use, and see if it works.

dustinlyons commented 9 months ago

Hi @multivac61, I'm spending some time cleaning up Github Issues. I hope the answer above helps in some way. Feel free to let me know here (on this Issue) if you have any more questions.