nixos-config/README.md at main · chvp/nixos-config · GitHub
— Permalink
You probably want to have some more persistent files than the two bind mounts we already have created during the setup.
Adding persistent files from etc:
{
# …
# machine-id is used by systemd for the journal, if you don't
# persist this file you won't be able to easily use journalctl to
# look at journals for previous boots.
environment.etc."machine-id".source
= "/nix/persist/etc/machine-id";
# if you want to run an openssh daemon, you may want to store the
# host keys across reboots.
#
# For this to work you will need to create the directory yourself:
# $ mkdir /nix/persist/etc/ssh
environment.etc."ssh/ssh_host_rsa_key".source
= "/nix/persist/etc/ssh/ssh_host_rsa_key";
environment.etc."ssh/ssh_host_rsa_key.pub".source
= "/nix/persist/etc/ssh/ssh_host_rsa_key.pub";
environment.etc."ssh/ssh_host_ed25519_key".source
= "/nix/persist/etc/ssh/ssh_host_ed25519_key";
environment.etc."ssh/ssh_host_ed25519_key.pub".source
= "/nix/persist/etc/ssh/ssh_host_ed25519_key.pub";
# …
}
From here you can probably figure out how to do more bind-mounts and symbolic links in /etc for the files you want to live across reboots.
A useful tool to discovering files in your tmpfs is ncdu, I tend to run sudo ncdu -x / to walk around the directory tree to see if there's something I want to make persistent.
You may want to make your /home persistent, that can be done by a mount or bind-mount. I have that as tmpfs as well, but that is probably enough content for it's own post.
Update: Now there's a follow-up post for putting tmpfs on /home as well, it's located here: NixOS ❄: tmpfs as home.