diff options
| author | lassulus <git@lassul.us> | 2026-01-11 01:29:31 +0100 |
|---|---|---|
| committer | lassulus <git@lassul.us> | 2026-01-11 01:29:31 +0100 |
| commit | 68d3c925b0edb958fcbafa589d35967dfb2a979c (patch) | |
| tree | 82018f93e411fcad47cb45867c646ce0f8feb683 /krebs/5pkgs/simple/git-hooks | |
| parent | 39ef2da7d30dba7c5c1556ffa90d330a9607bb44 (diff) | |
5pkgs: fix nix flake show compatibility
Integrate nix-writers flake for extended writer functions (writeJq,
writeGawkBin, etc.) using a fixpoint overlay so functions can reference
each other.
Update Python packages to new buildPythonPackage format:
- Add pyproject = true and build-system for ovh-zone, python-dnsstamps,
ssh-audit, tinc_graphs
Fix writer function usage by taking them as arguments instead of
accessing via pkgs:
- nixos-format-error, untilport, qrscan, logf, gitignore, urix, etc.
Update deprecated nixpkgs attribute names:
- gdk_pixbuf -> gdk-pixbuf
- libSM/libX11/libXinerama -> xorg.*
- buildGo120Module -> buildGoModule
Remove obsolete/broken packages:
- buildbot-classic-slave (missing buildbot-classic)
- cac-panel, drivedroid-gen-repo (Python 2 / format issues)
- games-user-env, generate-secrets (unused)
- internetarchive, bepasty-client-cli, krebspaste (Python 2)
- qrscan (conflicts with removed nixpkgs package)
Other fixes:
- Use lib.callPackageWith for package interdependencies
- Only export derivations in flake packages output
- Limit packages output to Linux systems
- Fix IFD in ukrepl by passing path to writer instead of readFile
- Import stockholm.lib directly where needed (bling)
- Rewrite brain and git-hooks to use runCommand
Diffstat (limited to 'krebs/5pkgs/simple/git-hooks')
| -rw-r--r-- | krebs/5pkgs/simple/git-hooks/default.nix | 235 |
1 files changed, 107 insertions, 128 deletions
diff --git a/krebs/5pkgs/simple/git-hooks/default.nix b/krebs/5pkgs/simple/git-hooks/default.nix index 3ec43739c..e6cde671e 100644 --- a/krebs/5pkgs/simple/git-hooks/default.nix +++ b/krebs/5pkgs/simple/git-hooks/default.nix @@ -1,129 +1,108 @@ -{ pkgs, stockholm, ... }: - -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 - ''; +{ pkgs, lib, writeDash, ... }: + +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 +}$*" } + +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 +'' |
