GnuPG user directory owned by root

I’m currently in the process of rebuilding my whole configuration and added the ability to produce ISOs to install new hosts as simply as possible.

The configuration is available on Github. Be aware that I’m actively working on it and it’s not quite done yet.

I’ve got two issues related to GnuPG:

  • the /home/<user>/.gnupg directory on ISOs is owned by root:root
  • there is a lockfile in /home/<user>/.gnupg/public-keys.d/pubring.db.lock

Therefore, when I run the ISO to install a new host, I have to run the following commands before running my install script:

sudo chown -R nixos:users ~/.gnupg
rm -rf ~/.gnupg/public-keys.d/pubring.db.lock

Only then, I can import my keys to perform the installation.

Any idea on why is this happening? As well as how to fix it without having to run the aforementioned commands?

Thanks!