diff --git a/modules/lib/maintainers.nix b/modules/lib/maintainers.nix index a2c56863..f3dd83fe 100644 --- a/modules/lib/maintainers.nix +++ b/modules/lib/maintainers.nix @@ -55,6 +55,12 @@ github = "cvoges12"; githubId = 38054771; }; + danjujan = { + name = "Jan Schmitz"; + email = "44864658+danjujan@users.noreply.github.com"; + github = "danjujan"; + githubId = 44864658; + }; d-dervishi = { email = "david.dervishi@epfl.ch"; github = "d-dervishi"; diff --git a/modules/misc/news.nix b/modules/misc/news.nix index 88e43a4c..bebb3666 100644 --- a/modules/misc/news.nix +++ b/modules/misc/news.nix @@ -1537,6 +1537,18 @@ in { for more. ''; } + + { + time = "2024-04-28T18:30:24+00:00"; + condition = hostPlatform.isLinux; + message = '' + A new module is available: 'services.psd'. + + Profile-sync-daemon (psd) is a tiny pseudo-daemon designed to manage + your browser's profile in tmpfs and to periodically sync it back + to your physical disc (HDD/SSD). + ''; + } ]; }; } diff --git a/modules/modules.nix b/modules/modules.nix index 06d1c331..b1e8b9b4 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -337,6 +337,7 @@ let ./services/plex-mpv-shim.nix ./services/polybar.nix ./services/poweralertd.nix + ./services/psd.nix ./services/pueue.nix ./services/pulseeffects.nix ./services/random-background.nix diff --git a/modules/services/psd.nix b/modules/services/psd.nix new file mode 100644 index 00000000..951d3d95 --- /dev/null +++ b/modules/services/psd.nix @@ -0,0 +1,105 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + + cfg = config.services.psd; + +in { + meta.maintainers = [ maintainers.danjujan ]; + + options.services.psd = { + enable = mkEnableOption "Profile-sync-daemon service"; + resyncTimer = mkOption { + type = types.str; + default = "1h"; + example = "1h 30min"; + description = '' + The amount of time to wait before syncing browser profiles back to the + disk. + + Takes a systemd.unit time span. The time unit defaults to seconds if + omitted. + ''; + }; + }; + + config = mkIf cfg.enable { + assertions = [ + (lib.hm.assertions.assertPlatform "services.psd" pkgs lib.platforms.linux) + ]; + + home.packages = [ pkgs.profile-sync-daemon ]; + + systemd.user = { + services = { + psd = { + Unit = { + Description = "Profile-sync-daemon"; + Wants = [ "psd-resync.service" ]; + RequiresMountsFor = [ "/home/" ]; + After = "winbindd.service"; + }; + Service = { + Type = "oneshot"; + RemainAfterExit = "yes"; + ExecStart = + "${pkgs.profile-sync-daemon}/bin/profile-sync-daemon startup"; + ExecStop = + "${pkgs.profile-sync-daemon}/bin/profile-sync-daemon unsync"; + Environment = [ + "LAUNCHED_BY_SYSTEMD=1" + "PATH=$PATH:${ + lib.makeBinPath (with pkgs; [ + rsync + kmod + gawk + nettools + util-linux + profile-sync-daemon + ]) + }" + ]; + }; + Install = { WantedBy = [ "default.target" ]; }; + }; + + psd-resync = { + Unit = { + Description = "Timed profile resync"; + After = [ "psd.service" ]; + Wants = [ "psd-resync.timer" ]; + PartOf = [ "psd.service" ]; + }; + Service = { + Type = "oneshot"; + ExecStart = + "${pkgs.profile-sync-daemon}/bin/profile-sync-daemon resync"; + Environment = [ + "PATH=$PATH:${ + lib.makeBinPath (with pkgs; [ + rsync + kmod + gawk + nettools + util-linux + profile-sync-daemon + ]) + }" + ]; + }; + Install = { WantedBy = [ "default.target" ]; }; + }; + }; + + timers.psd-resync = { + Unit = { + Description = "Timer for Profile-sync-daemon"; + PartOf = [ "psd-resync.service" "psd.service" ]; + }; + Timer = { OnUnitActiveSec = "${cfg.resyncTimer}"; }; + }; + }; + }; +}