From b6987329fe6dca5aca96fc651f06867c26dbf236 Mon Sep 17 00:00:00 2001 From: tv Date: Fri, 24 Jul 2015 11:55:16 +0200 Subject: 3: {tv -> krebs}.urlwatch --- 3modules/krebs/urlwatch.nix | 136 ++++++++++++++++++++++++++++++++++++++++++++ 3modules/tv/urlwatch.nix | 136 -------------------------------------------- 2 files changed, 136 insertions(+), 136 deletions(-) create mode 100644 3modules/krebs/urlwatch.nix delete mode 100644 3modules/tv/urlwatch.nix (limited to '3modules') diff --git a/3modules/krebs/urlwatch.nix b/3modules/krebs/urlwatch.nix new file mode 100644 index 000000000..58de72fc6 --- /dev/null +++ b/3modules/krebs/urlwatch.nix @@ -0,0 +1,136 @@ +{ config, lib, pkgs, ... }: + +# TODO multiple users +# TODO inform about unused caches +# cache = url: "${cfg.dataDir}/.urlwatch/cache/${hashString "sha1" url}" +# TODO hooks.py + +with builtins; +with lib; +let + cfg = config.krebs.urlwatch; + + # TODO assert sendmail's existence + out = { + options.krebs.urlwatch = api; + config = mkIf cfg.enable imp; + }; + + api = { + enable = mkEnableOption "krebs.urlwatch"; + + dataDir = mkOption { + type = types.str; + default = "/var/lib/urlwatch"; + description = '' + Directory where the urlwatch service should store its state. + ''; + }; + from = mkOption { + type = types.str; + default = "${user.name}@${config.networking.hostName}.retiolum"; + description = '' + Content of the From: header of the generated mails. + ''; + }; + mailto = mkOption { + type = types.str; + description = '' + Content of the To: header of the generated mails. [AKA recipient :)] + ''; + }; + onCalendar = mkOption { + type = types.str; + description = '' + Run urlwatch at this interval. + The format is described in systemd.time(7), CALENDAR EVENTS. + ''; + example = "04:23"; + }; + urls = mkOption { + type = with types; listOf str; + description = "URL to watch."; + example = [ + https://nixos.org/channels/nixos-unstable/git-revision + ]; + }; + }; + + urlsFile = toFile "urls" (concatStringsSep "\n" cfg.urls); + + imp = { + 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"; + SSL_CERT_FILE = "${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt"; + }; + serviceConfig = { + User = user.name; + PermissionsStartOnly = "true"; + PrivateTmp = "true"; + Type = "oneshot"; + ExecStartPre = + pkgs.writeScript "urlwatch-prestart" '' + #! /bin/sh + set -euf + + dataDir=$HOME + + if ! test -e "$dataDir"; then + mkdir -m 0700 -p "$dataDir" + chown ${user.name}: "$dataDir" + fi + ''; + ExecStart = pkgs.writeScript "urlwatch" '' + #! /bin/sh + set -euf + + from=${escapeShellArg cfg.from} + mailto=${escapeShellArg cfg.mailto} + urlsFile=${escapeShellArg urlsFile} + + cd /tmp + + urlwatch -e --urls="$urlsFile" > changes 2>&1 || : + + if test -s changes; then + date=$(date -R) + subject=$(sed -n 's/^\(CHANGED\|ERROR\|NEW\): //p' changes \ + | tr \\n \ ) + { + echo "Date: $date" + echo "From: $from" + echo "Subject: $subject" + echo "To: $mailto" + echo + cat changes + } | /var/setuid-wrappers/sendmail -t + fi + ''; + }; + }; + users.extraUsers = singleton { + inherit (user) name uid; + }; + }; + + user = { + name = "urlwatch"; + uid = 3467631196; # genid urlwatch + }; +in +out diff --git a/3modules/tv/urlwatch.nix b/3modules/tv/urlwatch.nix deleted file mode 100644 index a659fc74f..000000000 --- a/3modules/tv/urlwatch.nix +++ /dev/null @@ -1,136 +0,0 @@ -{ config, lib, pkgs, ... }: - -# TODO multiple users -# TODO inform about unused caches -# cache = url: "${cfg.dataDir}/.urlwatch/cache/${hashString "sha1" url}" -# TODO hooks.py - -with builtins; -with lib; -let - cfg = config.tv.urlwatch; - - # TODO assert sendmail's existence - out = { - options.tv.urlwatch = api; - config = mkIf cfg.enable imp; - }; - - api = { - enable = mkEnableOption "tv.urlwatch"; - - dataDir = mkOption { - type = types.str; - default = "/var/lib/urlwatch"; - description = '' - Directory where the urlwatch service should store its state. - ''; - }; - from = mkOption { - type = types.str; - default = "${user.name}@${config.networking.hostName}.retiolum"; - description = '' - Content of the From: header of the generated mails. - ''; - }; - mailto = mkOption { - type = types.str; - description = '' - Content of the To: header of the generated mails. [AKA recipient :)] - ''; - }; - onCalendar = mkOption { - type = types.str; - description = '' - Run urlwatch at this interval. - The format is described in systemd.time(7), CALENDAR EVENTS. - ''; - example = "04:23"; - }; - urls = mkOption { - type = with types; listOf str; - description = "URL to watch."; - example = [ - https://nixos.org/channels/nixos-unstable/git-revision - ]; - }; - }; - - urlsFile = toFile "urls" (concatStringsSep "\n" cfg.urls); - - imp = { - 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"; - SSL_CERT_FILE = "${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt"; - }; - serviceConfig = { - User = user.name; - PermissionsStartOnly = "true"; - PrivateTmp = "true"; - Type = "oneshot"; - ExecStartPre = - pkgs.writeScript "urlwatch-prestart" '' - #! /bin/sh - set -euf - - dataDir=$HOME - - if ! test -e "$dataDir"; then - mkdir -m 0700 -p "$dataDir" - chown ${user.name}: "$dataDir" - fi - ''; - ExecStart = pkgs.writeScript "urlwatch" '' - #! /bin/sh - set -euf - - from=${escapeShellArg cfg.from} - mailto=${escapeShellArg cfg.mailto} - urlsFile=${escapeShellArg urlsFile} - - cd /tmp - - urlwatch -e --urls="$urlsFile" > changes 2>&1 || : - - if test -s changes; then - date=$(date -R) - subject=$(sed -n 's/^\(CHANGED\|ERROR\|NEW\): //p' changes \ - | tr \\n \ ) - { - echo "Date: $date" - echo "From: $from" - echo "Subject: $subject" - echo "To: $mailto" - echo - cat changes - } | /var/setuid-wrappers/sendmail -t - fi - ''; - }; - }; - users.extraUsers = singleton { - inherit (user) name uid; - }; - }; - - user = { - name = "urlwatch"; - uid = 3467631196; # genid urlwatch - }; -in -out -- cgit v1.2.3 [cgit] Unable to lock slot /tmp/cgit/41100000.lock: No such file or directory (2)