Add initial prototype of NixOS module

Signed-off-by: Danila Fedorin <danila.fedorin@gmail.com>
This commit is contained in:
2025-12-27 09:06:16 +00:00
parent 2d17c8cdfb
commit fda16de4fa
2 changed files with 74 additions and 1 deletions

View File

@@ -23,5 +23,7 @@
packages = { inherit joann-pupper-bot; };
defaultPackage = joann-pupper-bot;
}
);
) // {
nixosModules.joann-pupper-bot = import ./module.nix;
};
}

71
module.nix Normal file
View File

@@ -0,0 +1,71 @@
{ config, lib, pkgs, ... }:
with lib;
let cfg = config.services.joann-pupper-bot; in {
options.services.joann-pupper-bot = {
enable = mkEnableOption "Joann's Pupper Bot";
user = mkOption {
type = types.str;
default = "joann-pupper-bot";
example = "myuser";
description = "Which user should be running Joann's Pupper Bot";
};
group = mkOption {
type = types.str;
default = "joann-pupper-bot";
example = "mygroup";
description = "Which group should be running Joann's Pupper Bot";
};
stateDir = mkOption {
type = types.str;
default = "/var/lib/joann-pupper-bot";
description = "Which directory the bot should use for storage";
};
config.token = mkOption {
type = types.str;
description = "Bot token used for Telegram";
};
config.subreddits = mkOption {
type = types.listOf types.str;
description = "Which subreddits to draw images from";
default = ["rarepuppers"];
};
config.sendCron = mkOption {
type = types.str;
description = "cron-style string determining when images should be sent";
default = "*/30 8-21 * * *";
};
config.refreshCron = mkOption {
type = types.str;
description = "cron-style string determining when the bot polls Reddit for new images";
default = "*/15 * * * *";
};
config.recipients = mkOption {
type = types.listOf types.int;
description = "Telegram chat IDs for each of the image recipients";
};
};
config = mkIf cfg.enable {
systemd.tmpfiles.rules = [
"d '${cfg.stateDir}' 0750 ${cfg.user} ${cfg.group} - -"
];
systemd.services.joann-pupper-bot = {
description = "Joann's Pupper Bot";
wantedBy = [ "multi-user.target" ];
preStart =
let
yml = generators.toYAML {} cfg.config;
configFile = pkgs.writeText "config.yaml" yml;
in
''
cp -f '${configFile}' '${cfg.stateDir}'/config.yaml
'';
serviceConfig = {
Type = "oneshot";
ExecStart = "/bin/sh -c :";
};
};
};
}