2015-07-11 14:55:22 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
# TODO multiple users
|
|
|
|
# TODO inform about unused caches
|
|
|
|
# cache = url: "${cfg.dataDir}/.urlwatch/cache/${hashString "sha1" url}"
|
|
|
|
|
2016-10-20 18:54:38 +00:00
|
|
|
with import <stockholm/lib>;
|
2015-07-11 14:55:22 +00:00
|
|
|
let
|
2015-07-24 09:55:16 +00:00
|
|
|
cfg = config.krebs.urlwatch;
|
2015-07-11 14:55:22 +00:00
|
|
|
|
2015-07-13 15:48:58 +00:00
|
|
|
# TODO assert sendmail's existence
|
|
|
|
out = {
|
2015-07-24 09:55:16 +00:00
|
|
|
options.krebs.urlwatch = api;
|
2016-02-14 15:43:44 +00:00
|
|
|
config = lib.mkIf cfg.enable imp;
|
2015-07-13 15:48:58 +00:00
|
|
|
};
|
|
|
|
|
2015-07-11 14:55:22 +00:00
|
|
|
api = {
|
2015-07-24 09:55:16 +00:00
|
|
|
enable = mkEnableOption "krebs.urlwatch";
|
2015-07-11 14:55:22 +00:00
|
|
|
dataDir = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "/var/lib/urlwatch";
|
|
|
|
description = ''
|
|
|
|
Directory where the urlwatch service should store its state.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
from = mkOption {
|
|
|
|
type = types.str;
|
2017-04-12 09:28:10 +00:00
|
|
|
default = "${user.name}@${config.networking.hostName}.r";
|
2015-07-11 14:55:22 +00:00
|
|
|
description = ''
|
|
|
|
Content of the From: header of the generated mails.
|
|
|
|
'';
|
|
|
|
};
|
2016-02-18 15:42:11 +00:00
|
|
|
# TODO hooks :: attrsOf hook
|
|
|
|
hooksFile = mkOption {
|
|
|
|
type = with types; nullOr path;
|
|
|
|
default = null;
|
|
|
|
description = ''
|
|
|
|
File to use as hooks.py module.
|
|
|
|
'';
|
|
|
|
};
|
2015-07-11 14:55:22 +00:00
|
|
|
mailto = mkOption {
|
|
|
|
type = types.str;
|
2015-07-27 00:39:41 +00:00
|
|
|
default = config.krebs.build.user.mail;
|
2015-07-11 14:55:22 +00:00
|
|
|
description = ''
|
|
|
|
Content of the To: header of the generated mails. [AKA recipient :)]
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
onCalendar = mkOption {
|
|
|
|
type = types.str;
|
2015-07-27 00:39:41 +00:00
|
|
|
default = "04:23";
|
2015-07-11 14:55:22 +00:00
|
|
|
description = ''
|
|
|
|
Run urlwatch at this interval.
|
|
|
|
The format is described in systemd.time(7), CALENDAR EVENTS.
|
|
|
|
'';
|
|
|
|
};
|
2019-08-13 07:29:49 +00:00
|
|
|
sendmail.enable = mkEnableOption "krebs.urlwatch.sendmail" // {
|
|
|
|
default = true;
|
|
|
|
};
|
2019-07-09 18:30:05 +00:00
|
|
|
telegram = {
|
2019-08-13 07:29:49 +00:00
|
|
|
enable = mkEnableOption "krebs.urlwatch.telegram";
|
2019-07-09 18:30:05 +00:00
|
|
|
botToken = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
};
|
|
|
|
chatId = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
};
|
|
|
|
};
|
2015-07-11 14:55:22 +00:00
|
|
|
urls = mkOption {
|
2016-02-18 15:42:11 +00:00
|
|
|
type = with types; listOf (either str subtypes.job);
|
2015-07-27 00:39:41 +00:00
|
|
|
default = [];
|
2015-07-11 14:55:22 +00:00
|
|
|
description = "URL to watch.";
|
|
|
|
example = [
|
|
|
|
https://nixos.org/channels/nixos-unstable/git-revision
|
2017-07-02 21:08:09 +00:00
|
|
|
{ url = http://localhost ; filter = "grep:important.*stuff"; }
|
2015-07-11 14:55:22 +00:00
|
|
|
];
|
2016-01-17 20:42:31 +00:00
|
|
|
apply = map (x: getAttr (typeOf x) {
|
|
|
|
set = x;
|
2019-08-13 07:41:55 +00:00
|
|
|
string.url = x;
|
2016-01-17 20:42:31 +00:00
|
|
|
});
|
2015-07-11 14:55:22 +00:00
|
|
|
};
|
2015-10-25 23:04:15 +00:00
|
|
|
verbose = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
verbose output of urlwatch
|
|
|
|
'';
|
|
|
|
};
|
2015-07-11 14:55:22 +00:00
|
|
|
};
|
|
|
|
|
2016-02-18 15:42:11 +00:00
|
|
|
urlsFile = pkgs.writeText "urls"
|
2017-07-02 21:08:09 +00:00
|
|
|
(concatMapStringsSep "\n---\n"
|
|
|
|
(x: toJSON (filterAttrs (n: v: n != "_module") x)) cfg.urls);
|
2016-02-18 15:42:11 +00:00
|
|
|
|
|
|
|
hooksFile = cfg.hooksFile;
|
2016-01-17 20:42:31 +00:00
|
|
|
|
2019-08-13 07:44:26 +00:00
|
|
|
configFile = pkgs.writeJSON "urlwatch.yaml" {
|
2016-01-17 20:42:31 +00:00
|
|
|
display = {
|
|
|
|
error = true;
|
|
|
|
new = true;
|
|
|
|
unchanged = false;
|
|
|
|
};
|
|
|
|
report = {
|
|
|
|
email = {
|
|
|
|
enabled = false;
|
|
|
|
from = "";
|
|
|
|
html = false;
|
|
|
|
smtp = {
|
|
|
|
host = "localhost";
|
|
|
|
keyring = true;
|
|
|
|
port = 25;
|
|
|
|
starttls = true;
|
|
|
|
};
|
|
|
|
subject = "{count} changes: {jobs}";
|
|
|
|
to = "";
|
|
|
|
};
|
|
|
|
html.diff = "unified";
|
|
|
|
stdout = {
|
|
|
|
color = true;
|
|
|
|
enabled = true;
|
|
|
|
};
|
2019-07-09 18:30:05 +00:00
|
|
|
${if cfg.telegram.enable then "telegram" else null} = {
|
|
|
|
enabled = cfg.telegram.enable;
|
|
|
|
bot_token = cfg.telegram.botToken;
|
|
|
|
chat_id = cfg.telegram.chatId;
|
|
|
|
};
|
2016-01-17 20:42:31 +00:00
|
|
|
text = {
|
|
|
|
details = true;
|
|
|
|
footer = true;
|
|
|
|
line_length = 75;
|
|
|
|
};
|
|
|
|
};
|
2019-08-13 07:44:26 +00:00
|
|
|
};
|
2015-07-11 14:55:22 +00:00
|
|
|
|
2015-07-13 15:48:58 +00:00
|
|
|
imp = {
|
2015-07-11 14:55:22 +00:00
|
|
|
systemd.timers.urlwatch = {
|
|
|
|
wantedBy = [ "timers.target" ];
|
|
|
|
timerConfig = {
|
|
|
|
OnCalendar = cfg.onCalendar;
|
|
|
|
Persistent = "true";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
systemd.services.urlwatch = {
|
|
|
|
path = with pkgs; [
|
|
|
|
coreutils
|
|
|
|
gnused
|
|
|
|
urlwatch
|
|
|
|
];
|
|
|
|
environment = {
|
|
|
|
HOME = cfg.dataDir;
|
|
|
|
LC_ALL = "en_US.UTF-8";
|
|
|
|
LOCALE_ARCHIVE = "${pkgs.glibcLocales}/lib/locale/locale-archive";
|
2015-08-26 15:10:02 +00:00
|
|
|
SSL_CERT_FILE = "${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt";
|
2015-07-11 14:55:22 +00:00
|
|
|
};
|
|
|
|
serviceConfig = {
|
2015-07-22 17:25:51 +00:00
|
|
|
User = user.name;
|
2015-07-11 14:55:22 +00:00
|
|
|
PermissionsStartOnly = "true";
|
|
|
|
PrivateTmp = "true";
|
2016-02-18 15:42:11 +00:00
|
|
|
SyslogIdentifier = "urlwatch";
|
2015-07-11 14:55:22 +00:00
|
|
|
Type = "oneshot";
|
2016-02-18 15:42:11 +00:00
|
|
|
ExecStart = pkgs.writeDash "urlwatch" ''
|
2015-07-11 14:55:22 +00:00
|
|
|
set -euf
|
|
|
|
|
|
|
|
cd /tmp
|
|
|
|
|
2016-01-17 20:42:31 +00:00
|
|
|
urlwatch \
|
|
|
|
${optionalString cfg.verbose "-v"} \
|
2016-02-18 15:42:11 +00:00
|
|
|
--config=${shell.escape configFile} \
|
|
|
|
${optionalString (hooksFile != null)
|
|
|
|
"--hooks=${shell.escape hooksFile}"
|
|
|
|
} \
|
|
|
|
--urls=${shell.escape urlsFile} \
|
2016-01-17 20:42:31 +00:00
|
|
|
> changes || :
|
2015-07-11 14:55:22 +00:00
|
|
|
|
2019-08-13 07:29:49 +00:00
|
|
|
${optionalString cfg.sendmail.enable /* sh */ ''
|
2019-07-09 18:29:41 +00:00
|
|
|
if test -s changes; then
|
|
|
|
{
|
|
|
|
echo Date: $(date -R)
|
|
|
|
echo From: ${shell.escape cfg.from}
|
|
|
|
echo Subject: $(
|
|
|
|
sed -n 's/^\(CHANGED\|ERROR\|NEW\): //p' changes \
|
|
|
|
| tr '\n' ' '
|
|
|
|
)
|
|
|
|
echo To: ${shell.escape cfg.mailto}
|
|
|
|
echo
|
|
|
|
cat changes
|
|
|
|
} | /run/wrappers/bin/sendmail -t
|
|
|
|
fi
|
|
|
|
''}
|
2015-07-11 14:55:22 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
2020-05-22 18:16:53 +00:00
|
|
|
users.users.${user.name} = {
|
|
|
|
inherit (user) uid;
|
2017-07-02 19:06:04 +00:00
|
|
|
home = cfg.dataDir;
|
|
|
|
createHome = true;
|
2021-06-05 13:52:49 +00:00
|
|
|
isSystemUser = true;
|
2021-12-04 21:20:50 +00:00
|
|
|
group = user.name;
|
2015-07-22 17:25:51 +00:00
|
|
|
};
|
2021-12-04 21:20:50 +00:00
|
|
|
users.groups.${user.name} = {};
|
2015-07-11 14:55:22 +00:00
|
|
|
};
|
|
|
|
|
2015-12-26 04:55:13 +00:00
|
|
|
user = rec {
|
2015-07-22 17:25:51 +00:00
|
|
|
name = "urlwatch";
|
2018-12-02 19:19:19 +00:00
|
|
|
uid = genid_uint31 name;
|
2015-07-22 17:25:51 +00:00
|
|
|
};
|
2016-02-18 15:42:11 +00:00
|
|
|
|
|
|
|
subtypes.job = types.submodule {
|
|
|
|
options = {
|
|
|
|
url = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
};
|
|
|
|
filter = mkOption {
|
2019-08-13 07:41:55 +00:00
|
|
|
default = null;
|
2016-02-18 15:42:11 +00:00
|
|
|
type = with types; nullOr str; # TODO nullOr subtypes.filter
|
|
|
|
};
|
2019-08-13 07:42:14 +00:00
|
|
|
ignore_cached = mkOption {
|
|
|
|
default = null;
|
|
|
|
type = with types; nullOr bool;
|
|
|
|
};
|
2016-02-18 15:42:11 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
in out
|