lanjoni / snowflake

Complete Nix workflow for macOS. Let the snowflakes in. ❄️
25 stars 0 forks source link

How to run if existing configuration exists? #2

Open Zik42 opened 1 week ago

Zik42 commented 1 week ago

For example, I am having error when I try to do this.

Existing file '/Users/username/.zshrc' is in the way of '/nix/store/7g1cyv8bzdcy77lffy5fj5zh81g2j0k-home-manager-files/.zshrc'
Existing file '/Users/username/.zshenv' is in the way of '/nix/store/7g1cyv8bzdcy77lffy5fj5zh81g2j0k-home-manager-files/.zshenv'
Please move the above files and try again or use 'home-manager switch -b backup' to back up existing files automatically.

home-manager switch -b backup is not available. I tried add option home-manager.enable = true; to programs block in home-manger/default.nix file, did rebuild, and did not found executable in result directory to launch home-manager.

I guess it will be helpful to add, not only for me.

lanjoni commented 1 week ago

This error occurs when there is a pre-existing configuration file and the home-manager tries to write a new configuration file. This validation prevents the loss of your current configuration file.

The “practical” way would be to move your current configuration file to a backup manually, as I didn't really make that explicit in the settings.

Thank you for pointing out this issue, I will update the order of commands to be executed, but if you are interested in opening a pull request for this fix, know that PRs are appreciated!

Zik42 commented 1 week ago

@lanjoni I would open, but I am new to nix. I don't know hot to approach this. Ideal solution for is to be able to run home-manager switch -b backup so it does backup automatically. If you provide solution, I will make PR. Appreciate your fast response. And thank you for amazing example of config.

lanjoni commented 1 week ago

The backup command should work in case you have at least one configuration already run with home-manager. In this case, as the first run was not performed, there is no possibility of running a backup yet.

I believe that the “simplest” solution would be a script (in bash) that validates which directories and configuration files the home-manager will try to overwrite, performing an automatic backup. In this case, there must be some more practical way to do this directly with Nix, so I'll take a more careful look later, but this was the simplest way I've thought of so far.

I thank you for opening the issue and I'm glad you liked the example of configurations I've been using.