My old MacOS workstation where I used Nix as sort of package manager (brew replacement) died. I have a copy of (only) /nix/store from it. It is not really important since I can just reinstall everything I need on new machine but for the sake of learning something new: how could I take say /mnt/nix/store (the backup) and move everything to my new /nix/store? I mean I can just copy it over, but as far as I am aware Nix has some sqlite database. Also all the stuff should land in my .nix-profile. Can that be done with ânix copyâ somehow?
Yes, I am aware of NixOS and declarative package management out of some configuration.nix. I have a toy NixOS machine to play around, but I am not yet confident enough to use it for my everyday tasks.
You should be able to just rsync --hard-links --archive all the stuff over, then create a symlink from ~/.nix-profile to /nix/var/nix/profiles/per-user/${USER}/profile, ~/.nix-defexpr/channels to /nix/var/nix/profiles/per-user/${USER}/channels, that should roughly be it.
Though this is an assumption, I have never tried it!
Also this does not consider anything that is special to macOS! I do not own such a thing, nor did I ever.
I donât think you need to hack nix-serve. Instead you can run a shell under unshare and mount the backup nix store at /nix/store while nix-serve is running. Thatâs what I have done to restore from a backup
Let me perhaps rephrase my question, what is /nix/var/nix/db/db.sqlite for?
Based on Rebuild sqlite db from scratch? ¡ Issue #3091 ¡ NixOS/nix ¡ GitHub I guess itâs just a cache.
Then what (exactly) happens when there is something in /nix/store but not in the sqlite database?
Unshare is a cool thing, but I donât have that on MacOS. So ok I guess it is safe (but not very elegant)
if I just manually copy/rsync into /nix/store. And then I can just ânix-store --add /nix/store/*â.
Then I still have the problem that the stuff is not in my .nix-profile. So I was thinking about going through all *.drv files, sorting the stuff and then re-realizing the latest version of each program (hope I am using the right terminology). Which since everything is already present shouldnât do anything except add that symlinks.
Let me perhaps rephrase my question, what is /nix/var/nix/db/db.sqlite for?
I tracks valid paths (ie. whatâs installed) among other things. If you start with an empty database nix will remove everything thatâs not registered when you start a garbage collect. This is because nix canât validate the content or track any of itâs dependencies without it.