Nix-darwin starting over but keeping nix/store

Hello! I feel like I am running into situations where I want to just start over again with my nix+nix-darwin+home-manager setup, but I am afraid to stray from the expected path. I have done it once, and I just nuked the entire /nix/ mount and re-building the store takes forever. It seems like it should be possible for me to roll back to a pre-nix-darwin+home-manager state and start over again, but I am not totally sure what that looks like.

Home manager may mutate things too much to really be sure, but in my head I should be able to go back to my old zsh+omz+brew setup, and nix will be lurking in the deeps of the system waiting to be invoked. Then I can add darwin, but not manage my homedir, and it should just use the existing items in the nix store if I haven’t changed anything, so there shouldn’t be any downloads unless there are mutating things. And then I can add home-manager, and it also shouldn’t need to download anything… but the goal is to see what it looks like to layer these tools incrementally. I am just not sure how to do it without confusing nix, since I am not totally sure what configuration space it is using.

I might also be asking the wrong question due to being a novice. :slight_smile:

1 Like

Hi Pol!

Just remove the /nix folder and redo an installation (sudo rm -rf /nix)

Nix only uses /nix directory.
Yes, Home-Manager manage files in your home directory but it creates symlinks to /nix.

Let us know how it goes.

I haven’t used it (so I can’t quite recommend it), but I know nix-darwin has an uninstall script. (I imagine home-manager has one as well…)

Of course, there’s no strong guarantee that these can get you back to a pure pre-state. Part of the reason these projects aren’t just a normal part of Nix is that they’re interfacing with stateful parts of the system that Nix doesn’t/can’t own.

(If you’ve used nix-darwin to modify a bunch of macOS settings, for example, I don’t expect these can be restored to what they were before the first time you activated nix-darwin.)


A few problems with this:

  1. Uninstalling Nix without addressing nix-darwin or home-manager first may leave you unable to properly run any install routine those tools provide. (And artifacts those tools leave behind may interfere with reinstalling Nix without needing to manually clean them up.)
  2. As mentioned earlier, these tools can make some stateful changes to your system that Nix doesn’t know about and is inherently incapable of unwinding.
  3. This instruction would only work for a single-user install, and macOS installs have been multi-user only for a while now. Installation steps for both Linux and macOS multi-user installs are available in the manual: Uninstalling Nix - Nix Reference Manual

Understood! I won’t recommend this practice in the future!

1 Like

Directly uninstalling Nix on systems that use Nix-Darwin usually leaves you with some dangling symlink chains in /etc. Some files there will be symlinks into /etc/static, and the files they point to will themselves be symlinks that point into now non-existent /nix/store paths. Besides not working, those symlinks will b0rk your next attempt to install Nix-Darwin.

IME it’s easy to repair, but it’s definitely an annoyance.

1 Like

That’s what I did before, I just deleted the /nix folder (and the disk mount, which is something that the Deterministic nix-installer does). But that’s the point, I want to start over, but not do that because it is really slow to repopulate it. Keep all of the local state, but somehow reset all of the local config.

Maybe a better question is, outside of the /nix/store, where does nix keep all of the config? Do I need to remove other things from /nix? Should I remove some stuff from /nix/var/? The deterministic installer creates a /nix/receipt.json which shows everything that it did, and it doesn’t look like it really does very much. I will keep poking around, but thanks for the info.

It’s not clear to me that you need to change any Nix config (unless Nix is broken in some way?)

As I said earlier:

I haven’t used it (so I can’t quite recommend it), but I know nix-darwin has an uninstall script. (I imagine home-manager has one as well…)

If you’re just looking to toss nix-darwin and home-manager out, which is what it sounded like, I’d recommend looking for the nix-darwin and HM-specific uninstall scripts (but mind my note that there are probably some changes that you can use both to make to your system that won’t be rolled back by uninstalling them).