feat(sleep-or-die): fix my sleep schedule

This commit is contained in:
Artur Manuel 2025-02-24 02:50:37 +00:00
commit 6d555ec898
Signed by: amadaluzia
SSH key fingerprint: SHA256:Zwg7gBuZyaG48ucAZneJwltiXu0+tJb7c3lYt9AYlLg
9 changed files with 141 additions and 5 deletions

View file

@ -0,0 +1,75 @@
{
config,
lib,
pkgs,
...
}: let
cfg = config.alqueva.programs.sleep-or-die;
inherit (lib) mkOption mkEnableOption types mkIf;
sleep-or-die = let
image =
if cfg.image == null
then ""
else "-i ${cfg.image}";
sound =
if cfg.sound == null
then ""
else "ffplay -nodisp -autoexit ${cfg.sound}";
in
pkgs.writeShellApplication {
name = "sod";
runtimeInputs = [
pkgs.libnotify
pkgs.ffmpeg
];
text = ''
notify-send -u critical "${cfg.title}" "${cfg.message}" ${image}
${sound}
shutdown +60 "This was automatically invoked by 'sleep-or-die'"
'';
};
in {
options.alqueva.programs.sleep-or-die = {
enable = mkEnableOption "sleep-or-die";
title = mkOption {
type = types.str;
description = "The title of the notification";
default = "Go to sleep!";
};
message = mkOption {
type = types.str;
description = "The message of the notification";
default = "You are missing on sleep! You have one hour to use your PC before it shuts off.";
};
image = mkOption {
type = types.nullOr types.path;
description = "The image to display on the notification.";
default = null;
};
sound = mkOption {
type = types.nullOr types.path;
description = "The sound to play on notification.";
default = null;
};
startAt = mkOption {
type = types.str;
default = "20:00:00";
description = "The time to start the daemon.";
};
};
config = mkIf cfg.enable {
systemd.user.services.sleep-or-die = {
inherit (cfg) startAt;
serviceConfig = {
RestartSec = 5;
ExecStart = "${lib.getExe' sleep-or-die "sod"}";
};
};
};
}