Tempfs sdimage so that sd card can survive power cuts

Hello, I want to be able to plug in/out the power of my raspberry pi however I want without having to worry about filesystem crashes. To solve that, my idea is to mount a temps to /. And only persist a few things with a manual action after I manually configured a few.

I already tried to override the root file system like so:

          fileSystems = {
            "/" = {
               device = lib.mkForce "none";
               fsType = lib.mkForce "tmpfs";
               options = lib.mkForce [ "defaults" "size=25%" "mode=755" ];

But then obviously the nix store and boot directories are not present with this setup. And also all the default folders like /var, /etc, … which normally get generated on the first boot now would be written to the tmpfs. But that’s not quite what I want, because the RAM of that machine is very limited with 512MB, but should be enough because if everything is created, there should be only minor changes in the fs.

Another other idea would be to mount the / fileSystem only readonly, but then the initial structure cannot be created the first time because its read only. And how about runtime? Aren’t there any files which would need to be written to a tempfs then?

If you have any idea how to solve that or know an even better way to solve the initial problem, I would really appreciate if you could help me with this.