aboutsummaryrefslogtreecommitdiff
path: root/build-aux/check-final-inputs-self-contained.scm
blob: a6148d12e33838596971762af3e76d32c93854ee (about) (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
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2014, 2015, 2016, 2017, 2018 Ludovic Courtès <ludo@gnu.org>
;;;
;;; This file is part of GNU Guix.
;;;
;;; GNU Guix 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.
;;;
;;; GNU Guix 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 GNU Guix.  If not, see <http://www.gnu.org/licenses/>.

;;;
;;; Check whether important binaries are available.
;;;

(use-modules (guix store)
             (guix grafts)
             (guix packages)
             (guix derivations)
             (guix ui)
             (gnu packages commencement)
             (ice-9 match)
             (srfi srfi-1)
             (srfi srfi-26))

(define (final-inputs store system)
  "Return the list of outputs directories of the final inputs for SYSTEM."
  (append-map (match-lambda
                ((or (name package) (name package _))
                 (let ((drv (package-derivation store package system)))
                   ;; Libc's 'debug' output refers to gcc-cross-boot0, but it's
                   ;; hard to avoid, so we tolerate it.  This should be the
                   ;; only exception.  Likewise, 'bash:include' depends on
                   ;; bootstrap-binaries via its 'Makefile.inc' (FIXME).
                   (filter-map (match-lambda
                                 (("debug" . directory)
                                  (if (string=? "glibc" (package-name package))
                                      #f
                                      directory))
                                 (("include" . directory)
                                  (if (string=? "bash" (package-name package))
                                      #f
                                      directory))
                                 ((_ . directory) directory))
                               (derivation->output-paths drv)))))
              %final-inputs))

(define (assert-valid-substitute substitute)
  "Make sure SUBSTITUTE does not refer to any bootstrap inputs, and bail out
if it does."
  (let ((references (substitutable-references substitute)))
    (when (any (cut string-contains <> "boot") references)
      (leave (G_ "'~a' refers to bootstrap inputs: ~s~%")
             (substitutable-path substitute) references))))

(define (test-final-inputs store system)
  "Check whether the final inputs for SYSTEM are clean---i.e., they don't
refer to the bootstrap tools."
  (format #t "checking final inputs for '~a'...~%" system)
  (let* ((inputs    (final-inputs store system))
         (available (substitutable-path-info store inputs)))
    (for-each (lambda (dir)
                (unless (find (lambda (substitute)
                                (string=? (substitutable-path substitute)
                                          dir))
                              available)
                  (leave (G_ "~a (system: ~a) has no substitute~%")
                         dir system)))
              inputs)

    (for-each assert-valid-substitute available)))

;; Entry point.
(with-store store
  (parameterize ((%graft? #f))
    (set-build-options store #:use-substitutes? #t)

    (for-each (cut test-final-inputs store <>)
              %cuirass-supported-systems)))
~(make-forkexec-constructor '#$(earlyoom-configuration->command-line-args config) #:log-file "/var/log/earlyoom.log")) (stop #~(make-kill-destructor)))) (define %earlyoom-log-rotation (list (log-rotation (files '("/var/log/earlyoom.log"))))) (define earlyoom-service-type (service-type (name 'earlyoom) (default-value (earlyoom-configuration)) (extensions (list (service-extension shepherd-root-service-type (compose list earlyoom-shepherd-service)) (service-extension rottlog-service-type (const %earlyoom-log-rotation)))) (description "Run @command{earlyoom}, a daemon that quickly responds to @acronym{OOM, out-of-memory} conditions by terminating relevant processes."))) ;;; ;;; fstrim ;;; (define (mcron-time? x) (or (procedure? x) (string? x) (list? x))) (define-maybe list-of-strings (prefix fstrim-)) (define (fstrim-serialize-boolean field-name value) (list (format #f "~:[~;--~a~]" value ;; Drop trailing '?' character. (string-drop-right (symbol->string field-name) 1)))) (define (fstrim-serialize-list-of-strings field-name value) (list (string-append "--" (symbol->string field-name)) #~(string-join '#$value ":"))) (define-configuration fstrim-configuration (package (file-like util-linux) "The package providing the @command{fstrim} command." empty-serializer) (schedule (mcron-time "0 0 * * 0") "Schedule for launching @command{fstrim}. This can be a procedure, a list or a string. For additional information, see @ref{Guile Syntax,, Job specification, mcron, the mcron manual}. By default this is set to run weekly on Sunday at 00:00." empty-serializer) ;; The following are fstrim-related options. (listed-in (maybe-list-of-strings '("/etc/fstab" "/proc/self/mountinfo")) ;; Note: documentation sourced from the fstrim manpage. "List of files in fstab or kernel mountinfo format. All missing or empty files are silently ignored. The evaluation of the list @emph{stops} after the first non-empty file. File systems with @code{X-fstrim.notrim} mount option in fstab are skipped.") (verbose? (boolean #t) "Verbose execution.") (quiet-unsupported? (boolean #t) "Suppress error messages if trim operation (ioctl) is unsupported.") (extra-arguments maybe-list-of-strings "Extra options to append to @command{fstrim} (run @samp{man fstrim} for more information)." (serializer (lambda (_ value) (if (maybe-value-set? value) value '())))) (prefix fstrim-)) (define (serialize-fstrim-configuration config) (list-transduce (compose (base-transducer config) tconcatenate) rcons fstrim-configuration-fields)) (define (fstrim-mcron-job config) (match-record config <fstrim-configuration> (package schedule) #~(job ;; Note: The “if” below is to ensure that ;; lists are ungexp'd correctly since @var{schedule} ;; can be either a procedure, a string or a list. #$(if (list? schedule) #~'(#$@schedule) schedule) (lambda () (system* #$(file-append package "/sbin/fstrim") #$@(serialize-fstrim-configuration config))) "fstrim"))) (define fstrim-service-type (service-type (name 'fstrim) (extensions (list (service-extension mcron-service-type (compose list fstrim-mcron-job)))) (description "Discard unused blocks from file systems.") (default-value (fstrim-configuration)))) ;;; ;;; Kernel module loader. ;;; (define kernel-module-loader-shepherd-service (match-lambda ((and (? list? kernel-modules) ((? string?) ...)) (shepherd-service (documentation "Load kernel modules.") (provision '(kernel-module-loader)) (requirement '(udev)) (one-shot? #t) (modules `((srfi srfi-1) (srfi srfi-34) (srfi srfi-35) (rnrs io ports) ,@%default-modules)) (start #~(lambda _ (cond ((null? '#$kernel-modules) #t) ((file-exists? "/proc/sys/kernel/modprobe") (let ((modprobe (call-with-input-file "/proc/sys/kernel/modprobe" get-line))) (guard (c ((message-condition? c) (format (current-error-port) "~a~%" (condition-message c)) #f)) (every (lambda (module) (invoke/quiet modprobe "--" module)) '#$kernel-modules)))) (else (format (current-error-port) "error: ~a~%" "Kernel is missing loadable module support.") #f)))))))) (define kernel-module-loader-service-type (service-type (name 'kernel-module-loader) (description "Load kernel modules.") (extensions (list (service-extension shepherd-root-service-type (compose list kernel-module-loader-shepherd-service)))) (compose concatenate) (extend append) (default-value '()))) ;;; ;;; Cachefilesd, an FS-Cache daemon ;;; (define (serialize-string variable-symbol value) #~(format #f "~a ~a~%" #$(symbol->string variable-symbol) #$value)) (define-maybe string) (define (non-negative-integer? val) (and (exact-integer? val) (not (negative? val)))) (define (serialize-non-negative-integer variable-symbol value) #~(format #f "~a ~d~%" #$(symbol->string variable-symbol) #$value)) (define-maybe non-negative-integer) (define (make-option-serializer option-symbol) (lambda (variable-symbol text) (if (maybe-value-set? text) #~(format #f "~a ~a~%" #$(symbol->string option-symbol) #$text) ""))) (define (make-percentage-threshold-serializer threshold-symbol) (lambda (variable-symbol percentage) (if (maybe-value-set? percentage) #~(format #f "~a ~a%~%" #$(symbol->string threshold-symbol) #$percentage) ""))) (define-configuration cachefilesd-configuration (cachefilesd (file-like cachefilesd) "The cachefilesd package to use." (serializer empty-serializer)) ;; command-line options (debug-output? (boolean #f) "Print debugging output to stderr." (serializer empty-serializer)) (use-syslog? (boolean #t) "Log to syslog facility instead of stdout." (serializer empty-serializer)) ;; culling is part of the configuration file ;; despite the name of the command-line option (scan? (boolean #t) "Scan for cachable objects." (serializer empty-serializer)) ;; sole required field in the configuration file (cache-directory maybe-string "Location of the cache directory." (serializer (make-option-serializer 'dir))) (cache-name (maybe-string "CacheFiles") "Name of cache (keep unique)." (serializer (make-option-serializer 'tag))) (security-context maybe-string "SELinux security context." (serializer (make-option-serializer 'secctx))) ;; percentage thresholds in the configuration file (pause-culling-for-block-percentage (maybe-non-negative-integer 7) "Pause culling when available blocks exceed this percentage." (serializer (make-percentage-threshold-serializer 'brun))) (pause-culling-for-file-percentage (maybe-non-negative-integer 7) "Pause culling when available files exceed this percentage." (serializer (make-percentage-threshold-serializer 'frun))) (resume-culling-for-block-percentage (maybe-non-negative-integer 5) "Start culling when available blocks drop below this percentage." (serializer (make-percentage-threshold-serializer 'bcull))) (resume-culling-for-file-percentage (maybe-non-negative-integer 5) "Start culling when available files drop below this percentage." (serializer (make-percentage-threshold-serializer 'fcull))) (pause-caching-for-block-percentage (maybe-non-negative-integer 1) "Pause further allocations when available blocks drop below this percentage." (serializer (make-percentage-threshold-serializer 'bstop))) (pause-caching-for-file-percentage (maybe-non-negative-integer 1) "Pause further allocations when available files drop below this percentage." (serializer (make-percentage-threshold-serializer 'fstop))) ;; run time optimizations in the configuration file (log2-table-size (maybe-non-negative-integer 12) "Size of tables holding cullable objects in logarithm of base 2." (serializer (make-option-serializer 'culltable))) (cull? (boolean #t) "Create free space by culling (consumes system load)." (serializer (lambda (variable-symbol value) (if value "" "nocull\n")))) ;; kernel module debugging in the configuration file (trace-function-entry-in-kernel-module? (boolean #f) "Trace function entry in the kernel module (for debugging)." (serializer empty-serializer)) (trace-function-exit-in-kernel-module? (boolean #f) "Trace function exit in the kernel module (for debugging)." (serializer empty-serializer)) (trace-internal-checkpoints-in-kernel-module? (boolean #f) "Trace internal checkpoints in the kernel module (for debugging)." (serializer empty-serializer))) (define (serialize-cachefilesd-configuration configuration) (mixed-text-file "cachefilesd.conf" (serialize-configuration configuration cachefilesd-configuration-fields))) (define (cachefilesd-shepherd-service config) "Return a list of <shepherd-service> for cachefilesd for CONFIG." (match-record config <cachefilesd-configuration> (cachefilesd debug-output? use-syslog? scan? cache-directory) (let ((configuration-file (serialize-cachefilesd-configuration config))) (shepherd-service (documentation "Run the cachefilesd daemon for FS-Cache.") (provision '(cachefilesd)) (requirement (append '(file-systems) (if use-syslog? '(syslogd) '()))) (start #~(begin (and=> #$(maybe-value cache-directory) mkdir-p) (make-forkexec-constructor `(#$(file-append cachefilesd "/sbin/cachefilesd") ;; do not detach "-n" #$@(if debug-output? '("-d") '()) #$@(if use-syslog? '() '("-s")) #$@(if scan? '() '("-N")) "-f" #$configuration-file)))) (stop #~(make-kill-destructor)))))) (define cachefilesd-service-type (service-type (name 'cachefilesd) (description "Run the file system cache daemon @command{cachefilesd}, which relies on the Linux @code{cachefiles} module.") (extensions (list (service-extension kernel-module-loader-service-type (const '("cachefiles"))) (service-extension shepherd-root-service-type (compose list cachefilesd-shepherd-service)))) (default-value (cachefilesd-configuration)))) ;;; ;;; Reliability, Availability, and Serviceability (RAS) daemon ;;; (define-record-type* <rasdaemon-configuration> rasdaemon-configuration make-rasdaemon-configuration rasdaemon-configuration? (record? rasdaemon-configuration-record? (default #f))) (define (rasdaemon-configuration->command-line-args config) "Translate <rasdaemon-configuration> to its command line arguments representation" (let ((record? (rasdaemon-configuration-record? config))) `(,(file-append rasdaemon "/sbin/rasdaemon") "--foreground" ,@(if record? '("--record") '())))) (define (rasdaemon-activation config) (let ((record? (rasdaemon-configuration-record? config)) (rasdaemon-dir "/var/lib/rasdaemon")) (with-imported-modules '((guix build utils)) #~(if #$record? (mkdir-p #$rasdaemon-dir))))) (define (rasdaemon-shepherd-service config) (shepherd-service (documentation "Run rasdaemon") (provision '(rasdaemon)) (requirement '(syslogd)) (start #~(make-forkexec-constructor '#$(rasdaemon-configuration->command-line-args config))) (stop #~(make-kill-destructor)))) (define rasdaemon-service-type (service-type (name 'rasdaemon) (default-value (rasdaemon-configuration)) (extensions (list (service-extension shepherd-root-service-type (compose list rasdaemon-shepherd-service)) (service-extension activation-service-type rasdaemon-activation))) (compose concatenate) (description "Run @command{rasdaemon}, the RAS monitor"))) ;;; ;;; Zram device ;;; (define-record-type* <zram-device-configuration> zram-device-configuration make-zram-device-configuration zram-device-configuration? (size zram-device-configuration-size (default "1G")) ; string or integer (compression-algorithm zram-device-configuration-compression-algorithm (default 'lzo)) ; symbol (memory-limit zram-device-configuration-memory-limit (default 0)) ; string or integer (priority zram-device-configuration-priority (default #f) ; integer | #f (delayed) ; to avoid printing the deprecation ; warning multiple times (sanitize warn-zram-priority-change))) (define-with-syntax-properties (warn-zram-priority-change (priority properties)) (if (eqv? priority -1) (begin (warning (source-properties->location properties) (G_ "using -1 for zram priority is deprecated~%")) (display-hint (G_ "Use #f or leave as default instead (@pxref{Linux \ Services}).")) #f) priority)) (define (zram-device-configuration->udev-string config) "Translate a <zram-device-configuration> into a string which can be placed in a udev rules file." (match config (($ <zram-device-configuration> size compression-algorithm memory-limit priority) (string-append "KERNEL==\"zram0\", " "ATTR{comp_algorithm}=\"" (symbol->string compression-algorithm) "\" " (if (not (or (equal? "0" size) (equal? 0 size))) (string-append "ATTR{disksize}=\"" (if (number? size) (number->string size) size) "\" ") "") (if (not (or (equal? "0" memory-limit) (equal? 0 memory-limit))) (string-append "ATTR{mem_limit}=\"" (if (number? memory-limit) (number->string memory-limit) memory-limit) "\" ") "") "RUN+=\"/run/current-system/profile/sbin/mkswap /dev/zram0\" " "RUN+=\"/run/current-system/profile/sbin/swapon " ;; TODO: Revert to simply use 'priority' after removing the deprecation ;; warning and the delayed property of the field. (let ((priority* (force priority))) (if priority* (format #f "--priority ~a " priority*) "")) "/dev/zram0\"\n")))) (define %zram-device-config `("modprobe.d/zram.conf" ,(plain-file "zram.conf" "options zram num_devices=1"))) (define (zram-device-udev-rule config) (file->udev-rule "99-zram.rules" (plain-file "99-zram.rules" (zram-device-configuration->udev-string config)))) (define zram-device-service-type (service-type (name 'zram) (default-value (zram-device-configuration)) (extensions (list (service-extension kernel-module-loader-service-type (const (list "zram"))) (service-extension etc-service-type (const (list %zram-device-config))) (service-extension udev-service-type (compose list zram-device-udev-rule)))) (description "Creates a zram swap device.")))