Move nixos-container to different machine

I’m trying to migrate a nixos-container to a different NixOS machine. I copied the container data from the older server to the new server with rsync -av old.server.example.com:/var/lib/containers/gitea /var/lib/containers/gitea and copied the relevant NixOS config to the new server. After running nixos-rebuild switch I’m greeted with working gitea instance, but it doesn’t appear to have any of my data.

When I log into the container with nixos-container root-login and run ls /var/lib/gitea/ I see a mostly empty folder. Outside of the container ls /var/lib/containers/gitea/var/lib/gitea/ shows me a lot of clutter.

Did I understand something wrong about how NixOS containers work or did something change in the meantime?

One possibility is that the uids are different between hosts, and the new one doesn’t match the filesystem owner

NixOS container data is stored in /var/lib/nixos-containers and not /var/lib/containers but it used to be in the latter. Could that be old data you’re seeing on the source machine?

3 Likes

NixOS container data is stored in /var/lib/nixos-containers and not /var/lib/containers but it used to be in the latter. Could that be old data you’re seeing on the source machine?

Old server doesn’t have data in /var/lib/nixos-containers but it got NixOS state version 19.09 so maybe it got moved in the last couple years. I will try moving it to nixos-containers on my new server.

Thanks, moving the container folder to /var/lib/nixos-containers solved the problem.