diff options
| -rw-r--r-- | krebs/2configs/reaktor2.nix | 4 | ||||
| -rw-r--r-- | krebs/3modules/ci/default.nix | 2 | ||||
| -rw-r--r-- | krebs/3modules/tinc.nix | 2 | ||||
| -rw-r--r-- | krebs/5pkgs/simple/git-hooks/default.nix | 231 |
4 files changed, 131 insertions, 108 deletions
diff --git a/krebs/2configs/reaktor2.nix b/krebs/2configs/reaktor2.nix index faabf7677..e7d348d50 100644 --- a/krebs/2configs/reaktor2.nix +++ b/krebs/2configs/reaktor2.nix @@ -293,7 +293,7 @@ let { activate = "always"; command = { - filename = ../5pkgs/simple/Reaktor/scripts/tell-on_join.sh; + filename = ../5pkgs/simple/reaktor2-plugins/scripts/tell-on_join.sh; env = { PATH = makeBinPath [ pkgs.coreutils # XXX env, touch @@ -415,7 +415,7 @@ let (generators.command_hook { inherit (commands) dance random-emoji nixos-version; tell = { - filename = ../5pkgs/simple/Reaktor/scripts/tell-on_privmsg.sh; + filename = ../5pkgs/simple/reaktor2-plugins/scripts/tell-on_privmsg.sh; env = { PATH = makeBinPath [ pkgs.coreutils # XXX date, env diff --git a/krebs/3modules/ci/default.nix b/krebs/3modules/ci/default.nix index 899db45c5..1f029276a 100644 --- a/krebs/3modules/ci/default.nix +++ b/krebs/3modules/ci/default.nix @@ -1,5 +1,5 @@ { config, lib, pkgs, ... }: -with lib.slib or (import ../../lib/pure.nix { inherit lib; }); +with lib.slib or (import ../../../lib/pure.nix { inherit lib; }); let cfg = config.krebs.ci; diff --git a/krebs/3modules/tinc.nix b/krebs/3modules/tinc.nix index debbb184b..02b3eeb9d 100644 --- a/krebs/3modules/tinc.nix +++ b/krebs/3modules/tinc.nix @@ -91,7 +91,7 @@ with lib.slib or (import ../../lib/pure.nix { inherit lib; }); { hosts = mkOption { type = with types; attrsOf host; default = - filterAttrs (_: h: hasAttr tinc.config.netname h.nets) config.krebs.hosts; + filterAttrs (_: h: hasAttr tinc.config.netname h.nets && h.nets.${tinc.config.netname}.tinc.config or null != null) config.krebs.hosts; defaultText = "‹all-hosts-of-‹netname››"; description = '' Hosts to generate <literal>config.krebs.tinc.retiolum.hostsPackage</literal>. diff --git a/krebs/5pkgs/simple/git-hooks/default.nix b/krebs/5pkgs/simple/git-hooks/default.nix index e6cde671e..51b4babfc 100644 --- a/krebs/5pkgs/simple/git-hooks/default.nix +++ b/krebs/5pkgs/simple/git-hooks/default.nix @@ -1,108 +1,131 @@ -{ pkgs, lib, writeDash, ... }: - +{ pkgs, lib, ... }: let stockholm.lib = import ../../../../lib/pure.nix { inherit lib; }; - inherit (stockholm.lib) makeBinPath; in - -pkgs.runCommand "irc-announce-git-hook" {} '' - mkdir -p $out/bin - cat > $out/bin/irc-announce-git-hook << 'OUTER' -#!${pkgs.dash}/bin/dash -set -euf - -# Required environment variables: -# IRC_SERVER, IRC_PORT, IRC_NICK, IRC_CHANNEL -# Optional: IRC_TLS (set to "true" for TLS), CGIT_ENDPOINT, VERBOSE - -export PATH=${makeBinPath (with pkgs; [ - coreutils - git - gnugrep - gnused -])}:$PATH - -green() { printf '\x0303,99%s\x0F' "$1"; } -red() { printf '\x0304,99%s\x0F' "$1"; } -orange() { printf '\x0307,99%s\x0F' "$1"; } -pink() { printf '\x0313,99%s\x0F' "$1"; } -gray() { printf '\x0314,99%s\x0F' "$1"; } - -unset message -add_message() { - message="''${message+$message -}$*" +with stockholm.lib; + +{ + # TODO irc-announce should return a derivation + # but it cannot because krebs.git.repos.*.hooks :: attrsOf str + irc-announce = + { cgit_endpoint ? "http://cgit.${nick}.r" + , channel + , nick + , port ? 6667 + , refs ? [] + , server + , tls ? false + , verbose ? false + }: /* sh */ '' + #! /bin/sh + set -euf + + export PATH=${makeBinPath (with pkgs; [ + coreutils + git + gnugrep + gnused + ])} + + green() { printf '\x0303,99%s\x0F' "$1"; } + red() { printf '\x0304,99%s\x0F' "$1"; } + orange() { printf '\x0307,99%s\x0F' "$1"; } + pink() { printf '\x0313,99%s\x0F' "$1"; } + gray() { printf '\x0314,99%s\x0F' "$1"; } + + unset message + add_message() { + message="''${message+$message + }$*" + } + + nick=${escapeShellArg nick} + channel=${escapeShellArg channel} + server=${escapeShellArg server} + tls=${escapeShellArg tls} + port=${toString port} + + host=$nick + + empty=0000000000000000000000000000000000000000 + + while read oldrev newrev ref; do + + if [ $oldrev = $empty ]; then + receive_mode=create + elif [ $newrev = $empty ]; then + receive_mode=delete + elif [ "$(git merge-base $oldrev $newrev)" = $oldrev ]; then + receive_mode=fast-forward + else + receive_mode=non-fast-forward + fi + + ${optionalString (refs != []) '' + if ! { echo "$ref" | grep -qE "${concatStringsSep "|" refs}"; }; then + echo "we are not announcing this ref: $h" + exit 0 + fi + ''} + + h=$(echo $ref | sed 's:^refs/heads/::') + + # empty_tree=$(git hash-object -t tree /dev/null) + empty_tree=4b825dc6 + + id=$(echo $newrev | cut -b-7) + id2=$(echo $oldrev | cut -b-7) + if [ $newrev = $empty ]; then id=$empty_tree; fi + if [ $oldrev = $empty ]; then id2=$empty_tree; fi + + ${if cgit_endpoint != null then /* sh */ '' + cgit_endpoint=${escapeShellArg cgit_endpoint} + case $receive_mode in + create) + link="$cgit_endpoint/$GIT_SSH_REPO/?h=$h" + ;; + delete) + link="$cgit_endpoint/$GIT_SSH_REPO/ ($h)" + ;; + fast-forward|non-fast-forward) + link="$cgit_endpoint/$GIT_SSH_REPO/diff/?h=$h&id=$id&id2=$id2" + ;; + esac + '' else /* sh */ '' + link="$GIT_SSH_REPO $h" + ''} + + #$host $GIT_SSH_REPO $ref $link + add_message $(pink push) $link $(gray "($receive_mode)") + + ${optionalString (verbose == true || typeOf verbose == "set") /* sh */ '' + ${optionalString (verbose.exclude or [] != []) /* sh */ '' + case $ref in (${concatStringsSep "|" verbose.exclude}) + continue + esac + ''} + add_message "$( + git log \ + --format="$(orange %h) %s $(gray '(%ar)')" \ + --no-merges \ + --reverse \ + $id2..$id + + git diff --stat $id2..$id \ + | sed '$!s/\(+*\)\(-*\)$/'$(green '\1')$(red '\2')'/' + )" + ''} + + done + + if test -n "''${message-}"; then + exec ${pkgs.irc-announce}/bin/irc-announce \ + "$server" \ + "$port" \ + "$nick" \ + "$channel" \ + "$tls" \ + "$message" + fi + ''; } - -empty=0000000000000000000000000000000000000000 - -while read oldrev newrev ref; do - - if [ $oldrev = $empty ]; then - receive_mode=create - elif [ $newrev = $empty ]; then - receive_mode=delete - elif [ "$(git merge-base $oldrev $newrev)" = $oldrev ]; then - receive_mode=fast-forward - else - receive_mode=non-fast-forward - fi - - h=$(echo $ref | sed 's:^refs/heads/::') - - empty_tree=4b825dc6 - - id=$(echo $newrev | cut -b-7) - id2=$(echo $oldrev | cut -b-7) - if [ $newrev = $empty ]; then id=$empty_tree; fi - if [ $oldrev = $empty ]; then id2=$empty_tree; fi - - if [ -n "''${CGIT_ENDPOINT:-}" ]; then - case $receive_mode in - create) - link="$CGIT_ENDPOINT/$GIT_SSH_REPO/?h=$h" - ;; - delete) - link="$CGIT_ENDPOINT/$GIT_SSH_REPO/ ($h)" - ;; - fast-forward|non-fast-forward) - link="$CGIT_ENDPOINT/$GIT_SSH_REPO/diff/?h=$h&id=$id&id2=$id2" - ;; - esac - else - link="$GIT_SSH_REPO $h" - fi - - add_message $(pink push) $link $(gray "($receive_mode)") - - if [ "''${VERBOSE:-}" = "true" ]; then - add_message "$( - git log \ - --format="$(orange %h) %s $(gray '(%ar)')" \ - --no-merges \ - --reverse \ - $id2..$id - - git diff --stat $id2..$id \ - | sed '$!s/\(+*\)\(-*\)$/'"$(green '\1')$(red '\2')"'/' - )" - fi - -done - -if test -n "''${message-}"; then - tls_flag="" - if [ "''${IRC_TLS:-}" = "true" ]; then - tls_flag="1" - fi - exec ${pkgs.irc-announce}/bin/irc-announce \ - "$IRC_SERVER" \ - "$IRC_PORT" \ - "$IRC_NICK" \ - "$IRC_CHANNEL" \ - "$tls_flag" \ - "$message" -fi -OUTER - chmod +x $out/bin/irc-announce-git-hook -'' |
