psd: add module

PR #5349
This commit is contained in:
Jan Schmitz 2024-04-28 19:35:01 +02:00 committed by Robert Helgesson
parent c1609d584a
commit d1980931de
No known key found for this signature in database
GPG Key ID: 96E745BD17AA17ED
4 changed files with 107 additions and 0 deletions

View File

@ -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";

View File

@ -1537,6 +1537,18 @@ in {
for more.
'';
}
{
time = "2024-04-28T20:27:08+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).
'';
}
];
};
}

View File

@ -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

88
modules/services/psd.nix Normal file
View File

@ -0,0 +1,88 @@
{ config, lib, pkgs, ... }:
let
cfg = config.services.psd;
in {
meta.maintainers = [ lib.hm.maintainers.danjujan ];
options.services.psd = {
enable = lib.mkEnableOption "Profile-sync-daemon service";
resyncTimer = lib.mkOption {
type = lib.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 time span, see {manpage}`systemd.time(7)`. The time unit
defaults to seconds if omitted.
'';
};
};
config = lib.mkIf cfg.enable {
assertions = [
(lib.hm.assertions.assertPlatform "services.psd" pkgs lib.platforms.linux)
];
home.packages = [ pkgs.profile-sync-daemon ];
systemd.user = {
services = let
exe = "${pkgs.profile-sync-daemon}/bin/profile-sync-daemon";
envPath = lib.makeBinPath (with pkgs; [
rsync
kmod
gawk
nettools
util-linux
profile-sync-daemon
]);
in {
psd = {
Unit = {
Description = "Profile-sync-daemon";
Wants = [ "psd-resync.service" ];
RequiresMountsFor = [ "/home/" ];
After = "winbindd.service";
};
Service = {
Type = "oneshot";
RemainAfterExit = "yes";
ExecStart = "${exe} startup";
ExecStop = "${exe} unsync";
Environment = [ "LAUNCHED_BY_SYSTEMD=1" "PATH=$PATH:${envPath}" ];
};
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 = "${exe} resync";
Environment = [ "PATH=$PATH:${envPath}" ];
};
Install = { WantedBy = [ "default.target" ]; };
};
};
timers.psd-resync = {
Unit = {
Description = "Timer for Profile-sync-daemon";
PartOf = [ "psd-resync.service" "psd.service" ];
};
Timer = { OnUnitActiveSec = cfg.resyncTimer; };
};
};
};
}