refactor
This commit is contained in:
parent
66c05f9093
commit
45d6f4b0f3
205 changed files with 9040 additions and 342 deletions
66
modules/nixos/services/cowsay-mastodon-poster/default.nix
Normal file
66
modules/nixos/services/cowsay-mastodon-poster/default.nix
Normal file
|
@ -0,0 +1,66 @@
|
|||
{ lib, pkgs, config, ... }:
|
||||
|
||||
let
|
||||
inherit (lib) types mkIf;
|
||||
inherit (lib.plusultra) mkBoolOpt mkOpt;
|
||||
inherit (pkgs) fortune toot;
|
||||
inherit (pkgs.snowfallorg) cow2img;
|
||||
|
||||
cfg = config.plusultra.services.cowsay-mastodon-poster;
|
||||
|
||||
script = ''
|
||||
if [ ! -f ~/.config/toot/config.json ]; then
|
||||
echo "File ~/.config/toot/config.json does not exist. Run 'toot login_cli' first."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
tmp_dir=$(mktemp -d)
|
||||
|
||||
pushd $tmp_dir > /dev/null
|
||||
${cow2img}/bin/cow2img --no-spinner ${if cfg.short then "--message \"$(${fortune}/bin/fortune -s)\"" else ""}
|
||||
|
||||
cow_name=$(cat ./cow/name)
|
||||
cow_message=$(cat ./cow/message)
|
||||
|
||||
post="$cow_name saying:"$'\n\n'"$cow_message"
|
||||
|
||||
${toot}/bin/toot post --media ./cow/image.png --description "$post" "#hachybots"
|
||||
popd > /dev/null
|
||||
|
||||
rm -rf $tmp_dir
|
||||
'';
|
||||
in
|
||||
{
|
||||
options.plusultra.services.cowsay-mastodon-poster = with types; {
|
||||
enable = mkBoolOpt false "Whether or not to enable cowsay posts.";
|
||||
short = mkBoolOpt false "Use short fortunes only.";
|
||||
user = mkOpt str config.plusultra.user.name "The user to run as.";
|
||||
group = mkOpt str "users" "The group to run as.";
|
||||
};
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
systemd = {
|
||||
timers.cowsay-mastodon-poster = {
|
||||
wantedBy = [ "timers.target" ];
|
||||
timerConfig = {
|
||||
# Run once a day at 10am.
|
||||
OnCalendar = "*-*-* 10:00:00";
|
||||
Unit = "cowsay-mastodon-poster.service";
|
||||
};
|
||||
};
|
||||
|
||||
services.cowsay-mastodon-poster = {
|
||||
after = [ "network-online.target" ];
|
||||
description = "Post a cowsay image to Mastodon.";
|
||||
|
||||
inherit script;
|
||||
|
||||
serviceConfig = {
|
||||
Type = "oneshot";
|
||||
User = cfg.user;
|
||||
Group = cfg.group;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue