nix-community / impermanence

Modules to help you handle persistent state on systems with ephemeral root storage [maintainer=@talyz]
MIT License
1.09k stars 80 forks source link

Support configuring other dirs as tmpfs, or a sync daemon #46

Open colemickens opened 2 years ago

colemickens commented 2 years ago

Hello.

I was reading a user raving about Firefox performance after moving the cache to an SSD and using a daemon to synchronize their firefox profile between a tmpfs dir and actual persistent storage.

These to me feel like very related-features to impermanence. I'd love to be able to specify some further configuration that would allow me to mount tmpfs at ~/.cache and then mount a tmpfs at ~/.mozilla that is then synchronized with a persistent directory in the same storage that impermanence is using.

Alternatively, maybe just an HM service to run ASD/PSD.

related links/apps:

talyz commented 2 years ago

Writing HM modules for PSD and ASD and submitting them upstream would probably be preferred, since they don't depend on any of the functionality provided by impermanence. We could then implement support for automatically setting up the configuration for the relevant directories.

Just a warning before you spend any time on this, though: in my experience, the claims of increased preformance are a bit exaggerated, at least when running off an SSD. While the claims of massively decreased latency are true, it's not that noticable in reality. Just try mounting a tmpfs at ~/.mozilla and see if it lives up to your expectations first.

Th3Whit3Wolf commented 2 years ago

@colemickens for the time being this can be achieved by creating a systemd service and timer with home-manager (assuming home is mounted on tmpfs).

    systemd.user = {
      # This is effectively what psd does
      services.firefox-persist = {
        Unit = {
          Description = "Firefox persistent storage sync";
        };

        Service = {
          CPUSchedulingPolicy = "idle";
          IOSchedulingClass = "idle";
          Environment = "PATH=${pkgs.coreutils}";
          # copy all files except those that are symlinks
          ExecStart = toString (pkgs.writeShellScript "firefox-backup" ''
            ${pkgs.rsync}/bin/rsync -avh --exclude={'user.js','chrome','extensions'} /home/doc/.mozilla/firefox/doc /persist/home/doc/.mozilla/firefox/
          '');
        };
      };

      timers.firefox-persist = {
        Unit = {
          Description = "Firefox persistent storage periodic sync";
        };

        Timer = {
          Unit = "firefox-persist.service";
          # Run every 15 minutes
          OnCalendar = "*:0/15";
          Persistent = true;
        };

        Install = { WantedBy = [ "timers.target" ]; };
      };
    };

I use --exclude={'user.js','chrome','extensions'} because these are symlinks in the nix store which impermanence seems to have an issue with right now.

PSD uses rsync -aX --inplace --no-whole-file

Then all you need to do is copy the files over on login.