projects/guix·blob javascript-team · refs

277 lines · 11.9 KiB

1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2025 Tomas Volf <[email protected]>
3;;; Copyright © 2023 Raven Hallsby <[email protected]>
4;;; Copyright © 2026 Giacomo Leidi <[email protected]>
5;;; Copyright © 2026 Nguyễn Gia Phong <[email protected]>
6;;;
7;;; This file is part of GNU Guix.
8;;;
9;;; GNU Guix is free software; you can redistribute it and/or modify it
10;;; under the terms of the GNU General Public License as published by
11;;; the Free Software Foundation; either version 3 of the License, or (at
12;;; your option) any later version.
13;;;
14;;; GNU Guix is distributed in the hope that it will be useful, but
15;;; WITHOUT ANY WARRANTY; without even the implied warranty of
16;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17;;; GNU General Public License for more details.
18;;;
19;;; You should have received a copy of the GNU General Public License
20;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
21
22;;;; Commentary:
23
24;;; Power-related packages.
25
26;;;; Code:
27
28(define-module (gnu packages power)
29 #:use-module (gnu packages)
30 #:use-module (gnu packages admin)
31 #:use-module (gnu packages base)
32 #:use-module (gnu packages bash)
33 #:use-module (gnu packages check)
34 #:use-module (gnu packages disk)
35 #:use-module (gnu packages file-systems)
36 #:use-module (gnu packages freedesktop)
37 #:use-module (gnu packages gawk)
38 #:use-module (gnu packages glib)
39 #:use-module (gnu packages instrumentation)
40 #:use-module (gnu packages libusb)
41 #:use-module (gnu packages linux)
42 #:use-module (gnu packages man)
43 #:use-module (gnu packages networking)
44 #:use-module (gnu packages pkg-config)
45 #:use-module (gnu packages python-xyz)
46 #:use-module (gnu packages ruby-xyz)
47 #:use-module (gnu packages virtualization)
48 #:use-module (guix build-system gnu)
49 #:use-module (guix build-system pyproject)
50 #:use-module (guix download)
51 #:use-module (guix git-download)
52 #:use-module (guix gexp)
53 #:use-module ((guix licenses) #:prefix license:)
54 #:use-module (guix packages))
55
56(define-public apcupsd
57 (package
58 (name "apcupsd")
59 (version "3.14.14")
60 (source (origin
61 (method url-fetch)
62 (uri
63 (string-append
64 "mirror://sourceforge/" name "/" name " - Stable/" version
65 "/" name "-" version ".tar.gz"))
66 (sha256
67 (base32
68 "0rwqiyzlg9p0szf3x6q1ppvrw6f6dbpn2rc5z623fk3bkdalhxyv"))))
69 (outputs '("out" "doc"))
70 (build-system gnu-build-system)
71 (arguments
72 (list
73 #:configure-flags
74 #~(list
75 ;; The configure script ignores --prefix for most of the file names.
76 (string-append "--exec-prefix=" #$output)
77 (string-append "--mandir=" #$output "/share/man")
78 (string-append "--sbindir=" #$output "/sbin")
79 (string-append "--sysconfdir=" #$output "/etc/apcupsd")
80 (string-append "--with-halpolicydir=" #$output "/share/halpolicy")
81
82 ;; Put us into the version string.
83 "--with-distname=GNU Guix"
84 "--disable-install-distdir"
85
86 ;; State directories.
87 "--localstatedir=/var"
88 "--with-log-dir=/var/log"
89 "--with-pid-dir=/run"
90 "--with-lock-dir=/run/apcupsd/lock"
91 "--with-nologin=/run/apcupsd"
92 "--with-pwrfail-dir=/run/apcupsd"
93
94 ;; Configure requires these, but we do not use the generated
95 ;; apcupsd.conf, so in order to reduce dependencies of the package,
96 ;; provide fake values.
97 (string-append "ac_cv_path_SHUTDOWN=/nope")
98 (string-append "ac_cv_path_APCUPSD_MAIL=/nope")
99 ;; While `wall' is not expanded anywhere, it still is searched for.
100 ;; See https://sourceforge.net/p/apcupsd/mailman/message/59128628/ .
101 (string-append "ac_cv_path_WALL=/nope")
102
103 ;; Enable additional drivers.
104 "--enable-usb"
105 "--enable-modbus-usb")
106 #:tests? #f ; There are no tests.
107 #:modules (cons '(ice-9 ftw) %default-gnu-modules)
108 #:phases
109 #~(modify-phases %standard-phases
110 (add-before 'configure 'remove-time-from-manual
111 (lambda _
112 ;; Do not bake the date and time of the build into the manual.
113 (substitute* "doc/manual/manual.rst"
114 (("\\| \\|date\\| \\|time\\|") ""))
115 (substitute* "autoconf/variables.mak.in"
116 (("^(RST2HTMLOPTS = .*) --time (.*)" all pref suff)
117 (string-append pref " " suff)))))
118 (add-after 'build 'build-manual
119 (lambda _
120 (invoke "make" "-C" "doc/manual" "manual.html")))
121 (add-after 'install-license-files 'move-doc
122 (lambda _
123 (let ((target (string-append #$output:doc
124 "/share/doc/"
125 (strip-store-file-name #$output))))
126 (mkdir-p target)
127 (for-each (lambda (f)
128 (copy-file (string-append "doc/manual/" f)
129 (string-append target "/" f)))
130 (scandir "doc/manual"
131 (lambda (f)
132 (or (string-suffix? ".png" f)
133 (string-suffix? ".html" f))))))))
134 ;; If sending mails is required, use proper mail program.
135 (add-after 'install 'remove-smtp
136 (lambda _
137 (delete-file (string-append #$output "/sbin/smtp"))))
138 ;; The configuration files and scripts are not really suitable for
139 ;; Guix, and our service provides its own version anyway. So delete
140 ;; these to make sure `apcupsd' and `apctest' executed without any
141 ;; arguments fail. `apctest' actually segfaults, but only after
142 ;; printing an error.
143 (add-after 'install 'remove-etc-apcupsd
144 (lambda _
145 (delete-file-recursively
146 (string-append #$output "/etc/apcupsd")))))))
147 (native-inputs (list mandoc pkg-config python-docutils-0.19 util-linux))
148 (inputs (list libusb libusb-compat))
149 (home-page "http://www.apcupsd.org")
150 (synopsis "Daemon for controlling APC UPSes")
151 (description "@command{apcupsd} can be used for power management and
152controlling most of @acronym{APC, American Power Conversion}’s @acronym{UPS,
153Uninterruptible Power Supply} models. @command{apcupsd} works with most of
154APC’s Smart-UPS models as well as most simple signalling models such a
155Back-UPS, and BackUPS-Office.")
156 (license license:gpl2)))
157
158(define-public tuned-minimal
159 (package
160 (name "tuned-minimal")
161 (version "2.27.0")
162 (source (origin
163 (method git-fetch)
164 (uri (git-reference
165 (url "https://github.com/redhat-performance/tuned")
166 (commit (string-append "v" version))))
167 (file-name (git-file-name name version))
168 (sha256
169 (base32
170 "11h65i65y0ly3iw8kkhzq6mv8csw9jkgy57k51jf3g99w57pcl9y"))))
171 (build-system pyproject-build-system)
172 (arguments
173 (list
174 ;; tests: 105 passed, 4 deselected
175 #:test-flags #~'("-k" "not udev and not get_device")
176 #:phases
177 #~(modify-phases %standard-phases
178 (add-after 'unpack 'patch-paths
179 (lambda* (#:key inputs outputs #:allow-other-keys)
180 (substitute* "Makefile"
181 (("^PYTHON_SITELIB = .*")
182 (simple-format #f "PYTHON_SITELIB = ~a\n"
183 (site-packages inputs outputs)))
184 ;; These directories do not make sense on Guix.
185 (("mkdir -p \\$\\(DESTDIR\\)/var/lib/tuned") "")
186 (("mkdir -p \\$\\(DESTDIR\\)/var/log/tuned") "")
187 (("mkdir -p \\$\\(DESTDIR\\)/run/tuned") "")
188 ;; Drop systemD services.
189 ((".*\\$\\(DESTDIR\\)\\$\\(UNITDIR\\).*\\.service.*") "")
190 ;; tuned-gui depends on systemctl being available. Drop it
191 ;; until it'll be compatible with other init systems.
192 ((".*\\$\\(DESTDIR\\).*tuned-gui.*") ""))
193 ;; Substitute FHS paths with Guix ones.
194 (substitute* (cons*
195 "experiments/powertop2tuned.py"
196 "tuned-adm.bash"
197 "tuned/consts.py"
198 (find-files "profiles"
199 (lambda (name stat)
200 (and (string-suffix? ".sh" name)
201 (eq? 'regular (stat:type stat))
202 (access? name X_OK)))))
203 (("/etc/tuned")
204 (string-append #$output "/etc/tuned"))
205 (("/usr/lib/tuned")
206 (string-append #$output "/lib/tuned")))
207 (substitute* "experiments/powertop2tuned.py"
208 (("/usr/sbin/powertop")
209 (search-input-file inputs "sbin/powertop")))
210 ;; TuneD really wants to write to
211 ;; /etc/modprobe.d/tuned.conf . Guix manages this file
212 ;; declaratively, so the default location for TuneD is
213 ;; is changed to a file where it can actually write.
214 (substitute* "tuned/consts.py"
215 (("/etc/modprobe\\.d/tuned\\.conf")
216 "/etc/tuned/modprobe.d/tuned.conf"))))
217 ;; There is nothing to build except documentation.
218 ;; https://github.com/redhat-performance/tuned/blob/v2.27.0/INSTALL#L4
219 ;; https://github.com/redhat-performance/tuned/blob/v2.27.0/tuned.spec
220 (replace 'build
221 (lambda* (#:key inputs #:allow-other-keys)
222 (invoke "make" "html"
223 (string-append
224 "PYTHON=" (search-input-file inputs "bin/python3")))))
225 (replace 'install
226 (lambda _
227 (invoke "make" "install" "install-ppd" "install-html"
228 (string-append "PREFIX=" #$output)
229 (string-append "SYSCONFDIR=" #$output "/etc")
230 (string-append "TMPFILESDIR=" #$output "/run/tuned"))))
231 (add-before 'check 'set-check-pythonpath
232 (lambda _
233 (setenv "PYTHONPATH" "tests/unit")))
234 (add-before 'wrap 'wrap-gi-and-path
235 (lambda* (#:key inputs #:allow-other-keys)
236 (for-each
237 (lambda (binary)
238 (wrap-program binary
239 `("GI_TYPELIB_PATH" =
240 (,(string-append #$(this-package-input "glib")
241 "/lib/girepository-1.0")))))
242 (find-files (string-append #$output "/sbin"))))))))
243 (native-inputs (list python-pytest
244 ruby-asciidoctor))
245 (inputs
246 (list bash-minimal
247 ethtool
248 gawk
249 glib
250 hdparm
251 kmod
252 iproute
253 powertop
254 python-dbus
255 python-pyinotify
256 python-linux-procfs
257 python-pygobject
258 python-pyudev
259 systemtap
260 util-linux
261 virt-what))
262 (synopsis "Dynamic adaptive system tuning daemon")
263 (description
264 "The TuneD package contains a daemon that tunes system settings
265dynamically. It does so by monitoring the usage of several system components
266periodically. Based on that information components will then be put into lower
267or higher power saving modes to adapt to the current usage.")
268 (home-page "https://tuned-project.org")
269 (license (list license:gpl2+ license:cc-by-sa3.0))))
270
271(define-public tuned
272 (package
273 (inherit tuned-minimal)
274 (name "tuned")
275 (inputs
276 (modify-inputs inputs
277 (prepend dmidecode perf wireless-tools)))))