blob: 63f7a54961eefec56e54596d3fc38e63f7598cfb (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
;;; guix-forge --- Guix software forge meta-service
;;; Copyright © 2026 Ashish Shukla <ashish.is@lostca.se>
;;; Copyright © 2026 Arun Isaac <arunisaac@systemreboot.net>
;;;
;;; This file is part of guix-forge.
;;;
;;; guix-forge is free software: you can redistribute it and/or modify
;;; it under the terms of the GNU General Public License as published
;;; by the Free Software Foundation, either version 3 of the License,
;;; or (at your option) any later version.
;;;
;;; guix-forge is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
;;; General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with guix-forge. If not, see
;;; <https://www.gnu.org/licenses/>.
(define-module (forge anubis)
#:use-module ((gnu packages golang) #:select (go-1.26))
#:use-module (gnu services)
#:use-module (gnu services shepherd)
#:use-module (gnu system file-systems)
#:use-module (guix build-system gnu)
#:use-module (guix download)
#:use-module (guix gexp)
#:use-module (guix least-authority)
#:use-module ((guix licenses) #:prefix license:)
#:use-module (guix packages)
#:use-module (guix records)
#:use-module (ice-9 match)
#:export (anubis-configuration
anubis-configuration?
anubis-configuration-package
anubis-service-type
%anubis-unix-socket))
;; TODO: Unbundle vendored node and go dependencies. See work in progress at
;; https://codeberg.org/guix/guix/pulls/2572
;; This package is based on https://codeberg.org/group/guix-modules/src/commit/137fe9d6dcdad1582c64a70c6f8a052c9251a590/guix/abbe/packages/golang.scm#L902
(define-public anubis-ai-firewall
(package
(name "anubis-ai-firewall")
(version "1.26.2")
(source
(origin
(method url-fetch)
(uri (string-append "https://github.com/TecharoHQ/anubis/releases/download/v"
version "/anubis-src-vendor-npm-" version ".tar.gz"))
(sha256
(base32 "1yab3z58vgi16313wmx7g32xk6nv158lqic54qds43l63y6lmf92"))))
(build-system gnu-build-system)
(arguments
(list #:phases
#~(modify-phases %standard-phases
(delete 'configure)
(add-after 'unpack 'patch-Makefile
(lambda _
(substitute* "Makefile"
(("\\(GO\\) build" all)
(string-append all " -trimpath")))))
(replace 'build
(lambda _
(let ((tmpdir "/tmp"))
(setenv "TMPDIR" tmpdir)
(setenv "GOPATH" (string-append tmpdir "/go"))
(setenv "GOCACHE" (string-append tmpdir "/go-cache"))
(invoke "make" "prebaked-build"))))
(replace 'check
(lambda* (#:key tests? #:allow-other-keys)
(when tests?
(invoke "go" "test" "./..."
;; This test requires network access.
"-skip" "TestLookup"))))
(replace 'install
(lambda _
(install-file "var/anubis"
(string-append #$output "/bin")))))))
(native-inputs
(list go-1.26))
(home-page "https://anubis.techaro.lol/")
(synopsis "Identify and block HTTP requests from AI bots")
(description
"Anubis is a web AI firewall utility that uses a combination of heuristics
and challenges to identify and block bots before they take your website down.
Anubis is as lightweight as possible and is designed to help protect the small
internet from the endless storm of requests that flood in from AI companies.")
(license license:expat)))
(define-record-type* <anubis-configuration>
anubis-configuration make-anubis-configuration
anubis-configuration?
(package anubis-configuration-package
(default anubis-ai-firewall)))
;; TODO: Do not hard-code.
(define %anubis-unix-socket
"/var/run/anubis/socket")
(define (anubis-activation config)
#~(begin
(let ((user (getpw "nginx")))
(mkdir-p (dirname #$%anubis-unix-socket))
(chown (dirname #$%anubis-unix-socket)
(passwd:uid user)
(passwd:gid user)))))
(define anubis-shepherd-service
(match-lambda
(($ <anubis-configuration> package)
(shepherd-service
(documentation "Run the Anubis AI firewall.")
(provision '(anubis))
(requirement '(networking))
(start #~(make-forkexec-constructor
(list #$(least-authority-wrapper
(file-append package "/bin/anubis")
#:name "anubis-pola-wrapper"
#:mappings (list (file-system-mapping
(source (dirname %anubis-unix-socket))
(target source)
(writable? #t))))
"-bind" #$%anubis-unix-socket
"-bind-network" "unix"
"-target" " ")
#:user "nginx"
#:group "nginx"
#:log-file "/var/log/anubis.log"))
(stop #~(make-kill-destructor))))))
(define anubis-service-type
(service-type
(name 'anubis)
(description "Run the Anubis AI firewall.")
(extensions
(list (service-extension activation-service-type
anubis-activation)
(service-extension shepherd-root-service-type
(compose list anubis-shepherd-service))))
(default-value (anubis-configuration))))
|