Add initial prototype of NixOS module
Signed-off-by: Danila Fedorin <danila.fedorin@gmail.com>
This commit is contained in:
@@ -23,5 +23,7 @@
|
|||||||
packages = { inherit joann-pupper-bot; };
|
packages = { inherit joann-pupper-bot; };
|
||||||
defaultPackage = joann-pupper-bot;
|
defaultPackage = joann-pupper-bot;
|
||||||
}
|
}
|
||||||
);
|
) // {
|
||||||
|
nixosModules.joann-pupper-bot = import ./module.nix;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
71
module.nix
Normal file
71
module.nix
Normal 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 :";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user