NixOS/home/programs/whatsapp.nix

41 lines
1.1 KiB
Nix
Raw Normal View History

2024-07-10 09:32:51 +07:00
{ lib, config, pkgs, ... }:
2024-06-12 09:54:11 +07:00
let
cfg = config.profile.whatsapp;
in
{
config = lib.mkIf cfg.enable {
2024-07-10 09:32:51 +07:00
home.packages = [ pkgs.whatsapp-for-linux ];
2024-06-12 09:54:11 +07:00
systemd.user = lib.mkIf cfg.autostart {
services.whatsapp = {
Unit = {
Description = "WhatsApp for Linux";
Wants = [ "graphical.target" ];
After = [ "nss-lookup.target" ];
StartLimitIntervalSec = 300;
StartLimitBurst = 10;
};
Service =
let
bash = "${pkgs.bash}/bin/bash";
ping = "${pkgs.unixtools.ping}/bin/ping";
host = "web.whatsapp.com";
sleep = "${pkgs.coreutils}/bin/sleep";
2024-07-10 09:32:51 +07:00
whatsapp = "${pkgs.whatsapp-for-linux}/bin/whatsapp-for-linux";
2024-06-12 09:54:11 +07:00
exec = ''${bash} -c "until ${ping} -c 1 ${host}; do ${sleep} 1; done; ${whatsapp}"'';
in
{
Type = "simple";
ExecStartPre = "${sleep} 10";
ExecStart = exec;
Restart = "on-failure";
RemainAfterExit = "yes";
};
Install = {
WantedBy = [ "default.target" ];
};
};
};
};
}