feat(nix-flake): add nix flake and nix module

This commit is contained in:
Philipp 2025-03-20 00:44:55 +01:00
parent 21d580d1a6
commit ddaf33b4f8
Signed by: Philipp
GPG key ID: 9EBD8439AFBAB750
6 changed files with 226 additions and 0 deletions

51
nix/services.nix Normal file
View file

@ -0,0 +1,51 @@
{config, lib, pkgs, ...}:
with lib;
let
cfg = config.services.discord-tweeter;
format = pkgs.formats.toml { };
configFile = format.generate "config.toml" cfg.settings;
in
{
options.services.discord-tweeter = {
enable = mkEnableOption (lib.mdDoc "discord-tweeter");
settings = mkOption {
type = format.type;
default = {
username = "";
password = "";
proxyaddr = "";
webhook = "";
DbPath = "/var/lib/discord-tweeter/";
CookiePath = "/var/lib/discord-tweeter/";
channels = [ ];
filter = [ 0b11111 ];
UseWebServer = true;
HostURL = "";
WebPort = 8080;
UserAgents = [ "discordbot" "curl" "httpie" "lwp-request" "wget" "python-requests" "openbsd ftp" "powershell" ];
NitterBase = "https://xcancel.com";
};
description = lib.mdDoc ''
'';
};
};
config = mkIf cfg.enable {
systemd.services.discord-tweeter = {
description = "Send tweets to Discord by scraping Twitter (now X)";
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
serviceConfig = {
DynamicUser = true;
ExecStart = "${self.packages.${pkgs.system}.default}/bin/discord-tweeter ${configFile}";
Restart = "on-failure";
};
};
};
}