77 lines
1.8 KiB
Nix
77 lines
1.8 KiB
Nix
{
|
|
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"}";
|
|
};
|
|
};
|
|
};
|
|
}
|