-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
119 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
{ config, lib, pkgs, ... }: | ||
|
||
let | ||
cfg = config.services.rssbot; | ||
defaultUser = "rssbot"; | ||
inherit (lib) mkEnableOption mkPackageOption mkOption mkIf types optionalAttrs; | ||
in | ||
{ | ||
options.services.rssbot = { | ||
enable = mkEnableOption "RSS bot for Telegram"; | ||
|
||
package = mkPackageOption pkgs "rssbot" { }; | ||
|
||
user = mkOption { | ||
type = types.str; | ||
default = defaultUser; | ||
description = "User under which RSS Bot runs."; | ||
}; | ||
|
||
adminId = mkOption { | ||
type = types.int; | ||
description = "Admin ID"; | ||
}; | ||
|
||
botTokenFile = mkOption { | ||
type = types.path; | ||
description = "File containing Telegram Bot Token"; | ||
}; | ||
|
||
# TODO: Find a way to load a custom post.gohtml | ||
# template = mkOption { | ||
# type = types.nullOr types.lines; | ||
# default = null; | ||
# description = "Custom post.gohtml template content"; | ||
# }; | ||
|
||
database = { | ||
host = lib.mkOption { | ||
type = types.str; | ||
description = "Database host."; | ||
default = "localhost"; | ||
}; | ||
|
||
port = mkOption { | ||
type = types.port; | ||
default = 3306; | ||
description = "Database port"; | ||
}; | ||
|
||
name = lib.mkOption { | ||
type = types.str; | ||
description = "Database name."; | ||
default = defaultUser; | ||
}; | ||
|
||
user = lib.mkOption { | ||
type = types.str; | ||
description = "Database username."; | ||
default = defaultUser; | ||
}; | ||
|
||
passwordFile = lib.mkOption { | ||
type = types.path; | ||
description = "Database user password file."; | ||
}; | ||
}; | ||
|
||
}; | ||
|
||
config = mkIf cfg.enable { | ||
systemd.services.rssbot = { | ||
description = "RSS Bot for Telegram"; | ||
after = [ "network.target" ]; | ||
wantedBy = [ "multi-user.target" ]; | ||
|
||
script = '' | ||
export BOT_TOKEN="$(< $CREDENTIALS_DIRECTORY/BOT_TOKEN )" | ||
export MYSQL_PASSWORD="$(< $CREDENTIALS_DIRECTORY/MYSQL_PASSWORD )" | ||
exec ${cfg.package}/bin/rssbot | ||
''; | ||
|
||
serviceConfig = { | ||
LoadCredential = [ | ||
"BOT_TOKEN:${cfg.botTokenFile}" | ||
"MYSQL_PASSWORD:${cfg.database.passwordFile}" | ||
]; | ||
|
||
Restart = "always"; | ||
User = cfg.user; | ||
Group = defaultUser; | ||
WorkingDirectory = "/var/lib/rssbot"; | ||
}; | ||
|
||
environment = { | ||
ADMIN_ID = toString cfg.adminId; | ||
MYSQL_HOST = cfg.database.host; | ||
MYSQL_PORT = toString cfg.database.port; | ||
MYSQL_USER = cfg.database.user; | ||
MYSQL_DB = cfg.database.name; | ||
}; | ||
}; | ||
|
||
users = optionalAttrs (cfg.user == defaultUser) { | ||
users.${defaultUser} = { | ||
isSystemUser = true; | ||
group = defaultUser; | ||
description = "RSS Bot user"; | ||
}; | ||
|
||
groups.${defaultUser} = { }; | ||
}; | ||
|
||
}; | ||
|
||
} |