PSA: pinning users uid is important when reinstalling NixOS + restoring backups

Hey

After experimenting with two disks migration from ext4 to btrfs yesterday, this didn’t go very well and ended up reinstalling NixOS (not really btrfs fault :wink: ), however, after reinstalling my users had different uid than in the previous install, and I had to fix many uid / gid in my 6 users home directories.

This wouldn’t have happened if I did set each user its uid in the configuration file.

Don’t be like me :+1:t3:

  users.users.solene.uid = 1000;
  users.users.foo.uid = 1001;
  users.users.bar.uid = 1002;
  users.users.hunter2.uid = 1337;
2 Likes

You could also backup and restore /var/lib/nixos/. As I understand it, that would keep the maps for uids and gids that nixos picked before.

4 Likes

Thanks, I didn’t know how this directory, I usually don’t restore /var but I see my backup of /var/lib/nixos contains all the groups and users ids, for a full restore, that’s very important. (but it would be included in a full restore anyway :smiley: )