aboutsummaryrefslogtreecommitdiff
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2017, 2018, 2019, 2020, 2022 Ludovic Courtès <ludo@gnu.org>
;;; Copyright © 2020 Mathieu Othacehe <othacehe@gnu.org>
;;; Copyright © 2022 Leo Nikkilä <hello@lnikki.la>
;;; Copyright © 2022 Arun Isaac <arunisaac@systemreboot.net>
;;;
;;; 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/>.

(define-module (gnu build shepherd)
  #:use-module (gnu system file-systems)
  #:use-module (gnu build linux-container)
  #:use-module (guix build utils)
  #:use-module (srfi srfi-1)
  #:use-module (srfi srfi-26)
  #:use-module (ice-9 match)
  ;; XXX: Lazy-bind the Shepherd to avoid a compile-time dependency.
  #:autoload (shepherd service) (fork+exec-command
                                 read-pid-file
                                 exec-command
                                 %precious-signals)
  #:autoload (shepherd system) (unblock-signals)
  #:export (default-mounts
            fork+exec-command/container))

;;; Commentary:
;;;
;;; This module provides extensions to the GNU Shepherd.  In particular, it
;;; provides a helper to start services in a container.
;;;
;;; Code:

(define (clean-up file)
  (when file
    (catch 'system-error
      (lambda ()
        (delete-file file))
      (lambda args
        (unless (= ENOENT (system-error-errno args))
          (apply throw args))))))

(define-syntax-rule (catch-system-error exp)
  (catch 'system-error
    (lambda ()
      exp)
    (const #f)))

(define (default-namespaces args)
  ;; Most daemons are here to talk to the network, and most of them expect to
  ;; run under a non-zero UID.
  (fold delq %namespaces '(net user)))

(define* (default-mounts #:key (namespaces (default-namespaces '())))
  (define (tmpfs directory)
    (file-system
      (device "none")
      (mount-point directory)
      (type "tmpfs")
      (check? #f)))

  (define accounts
    ;; This is for processes in the default user namespace but living in a
    ;; different mount namespace, so that they can lookup users.
    (list (file-system-mapping
           (source "/etc/passwd") (target source))
          (file-system-mapping
           (source "/etc/group") (target source))))

  (append (cons (tmpfs "/tmp") %container-file-systems)
          (let ((mappings `(,@(if (memq 'net namespaces)
                                  '()
                                  %network-file-mappings)
                            ,@(if (and (memq 'mnt namespaces)
                                       (not (memq 'user namespaces)))
                                  accounts
                                  '())

                            ;; Tell the process what timezone we're in.  This
                            ;; makes sure that, for instance, its syslog
                            ;; messages have the correct timestamp.
                            ,(file-system-mapping
                              (source "/etc/localtime")
                              (target source))

                            ,%store-mapping)))    ;XXX: coarse-grain
            (map file-system-mapping->bind-mount
                 (filter (lambda (mapping)
                           (file-exists? (file-system-mapping-source mapping)))
                         mappings)))))

(define* (exec-command* command #:key user group log-file pid-file
                        (supplementary-groups '())
                        (directory "/") (environment-variables (environ)))
  "Like 'exec-command', but first restore signal handles modified by
shepherd (PID 1)."
  ;; First restore the default handlers.
  (for-each (cut sigaction <> SIG_DFL) %precious-signals)

  ;; Unblock any signals that have been blocked by the parent process.
  (unblock-signals %precious-signals)

  (mkdir-p "/var/run")
  (clean-up pid-file)

  (exec-command command
                #:user user
                #:group group
                #:supplementary-groups supplementary-groups
                #:log-file log-file
                #:directory directory
                #:environment-variables environment-variables))

(define* (fork+exec-command/container command
                                      #:key pid
                                      #:allow-other-keys
                                      #:rest args)
  "This is a variant of 'fork+exec-command' procedure, that joins the
namespaces of process PID beforehand.  If there is no support for containers,
on Hurd systems for instance, fallback to direct forking."
  (define (strip-pid args)
    ;; TODO: Replace with 'strip-keyword-arguments' when that no longer pulls
    ;; in (guix config).
    (let loop ((args args)
               (result '()))
      (match args
        (()
         (reverse result))
        ((#:pid _ . rest)
         (loop rest result))
        ((head . rest)
         (loop rest (cons head result))))))

  (let ((container-support? (file-exists? "/proc/self/ns")))
    (if (and container-support?
             (not (and pid (= pid (getpid)))))
        (container-excursion* pid
          (lambda ()
            ;; Note: In the Shepherd 0.9, 'fork+exec-command' expects to be
            ;; called from the shepherd process (because it creates a pipe to
            ;; capture stdout/stderr and spawns a logging fiber) so we cannot
            ;; use it here.
            (match (primitive-fork)
              (0 (dynamic-wind
                   (const #t)
                   (lambda ()
                     (apply exec-command* command (strip-pid args)))
                   (lambda ()
                     (primitive-_exit 127))))
              (pid pid))))               ;XXX: assuming the same PID namespace
        (apply fork+exec-command command (strip-pid args)))))

;; Local Variables:
;; eval: (put 'container-excursion* 'scheme-indent-function 1)
;; End:

;;; shepherd.scm ends here
le='width: 7.1%;'/> -rw-r--r--gnu/packages/gl.scm2
-rw-r--r--gnu/packages/gnome-xyz.scm2
-rw-r--r--gnu/packages/haskell-xyz.scm4
-rw-r--r--gnu/packages/installers.scm2
-rw-r--r--gnu/packages/lisp-xyz.scm2
-rw-r--r--gnu/packages/maths.scm2
-rw-r--r--gnu/packages/ocaml.scm2
-rw-r--r--gnu/packages/perl6.scm2
-rw-r--r--gnu/packages/python-xyz.scm4
-rw-r--r--gnu/packages/statistics.scm2
-rw-r--r--gnu/packages/terminals.scm2
17 files changed, 25 insertions, 25 deletions
diff --git a/gnu/packages/admin.scm b/gnu/packages/admin.scm
index 7977f5113e..f42a644bf0 100644
--- a/gnu/packages/admin.scm
+++ b/gnu/packages/admin.scm
@@ -3895,7 +3895,7 @@ application, collecting the information received.")
("python-nose" ,python-nose)))
(arguments
`(#:test-target "test"))
- (synopsis "single tool that combines @command{cat} & @command{rm}")
+ (synopsis "Single tool that combines @command{cat} & @command{rm}")
(description
"hungrycat prints the contents of a file to standard output, while
simultaneously freeing the disk space it occupied. It is useful if you need
diff --git a/gnu/packages/cobol.scm b/gnu/packages/cobol.scm
index 3b5626daeb..c1699b7e3a 100644
--- a/gnu/packages/cobol.scm
+++ b/gnu/packages/cobol.scm
@@ -71,7 +71,7 @@
(list bdb gmp json-c libxml2 ncurses))
(build-system gnu-build-system)
(home-page "https://www.gnu.org/software/gnucobol/")
- (synopsis "modern COBOL compiler")
+ (synopsis "Modern COBOL compiler")
(description "GnuCOBOL is a free, modern COBOL compiler. GnuCOBOL
implements a substantial part of the COBOL 85, COBOL 2002 and COBOL 2014
standards and X/Open COBOL, as well as many extensions included in other
diff --git a/gnu/packages/cpp.scm b/gnu/packages/cpp.scm
index 37bff19a06..123dfb8470 100644
--- a/gnu/packages/cpp.scm
+++ b/gnu/packages/cpp.scm
@@ -1182,7 +1182,7 @@ computation.")
(native-inputs
`(("unzip" ,unzip)))
(home-page "https://sourceforge.net/projects/polyclipping")
- (synopsis "polygon and line clipping and offsetting library")
+ (synopsis "Polygon and line clipping and offsetting library")
(description
"The Clipper library performs line & polygon clipping - intersection,
union, difference & exclusive-or, and line & polygon offsetting.
diff --git a/gnu/packages/crates-graphics.scm b/gnu/packages/crates-graphics.scm
index 010d928988..d7385e3647 100644
--- a/gnu/packages/crates-graphics.scm
+++ b/gnu/packages/crates-graphics.scm
@@ -1671,7 +1671,7 @@ nicely with Piston libraries.")
(arguments `(#:skip-build? #t))
(home-page
"https://github.com/pistondevelopers/texture")
- (synopsis "generic library for textures")
+ (synopsis "Generic library for textures")
(description
"This package provides a generic library for textures")
(license license:expat)))
diff --git a/gnu/packages/crates-io.scm b/gnu/packages/crates-io.scm
index 937d5f4adf..35f9d9c80d 100644
--- a/gnu/packages/crates-io.scm
+++ b/gnu/packages/crates-io.scm
@@ -1903,7 +1903,7 @@ options to use calloc or a mutable global variable for pre-zeroed memory.")
`(#:cargo-inputs
(("rust-alloc-no-stdlib" ,rust-alloc-no-stdlib-2))))
(home-page "https://github.com/dropbox/rust-alloc-no-stdlib")
- (synopsis "dynamic allocator example that may be used with the stdlib")
+ (synopsis "Dynamic allocator example that may be used with the stdlib")
(description "This package provides a dynamic allocator example that may
be used with the stdlib.")
(license license:bsd-3)))
@@ -4196,7 +4196,7 @@ methods.")
"1qig9fcdqf07mzzpkicm5wgxv0zpr28njdsqf708wxq27yf6k1iw"))))
(build-system cargo-build-system)
(home-page "https://github.com/slide-rs/atom")
- (synopsis "safe abstraction around AtomicPtr")
+ (synopsis "Safe abstraction around AtomicPtr")
(description "This package provides a safe abstraction around AtomicPtr.")
(license license:asl2.0)))
@@ -35208,7 +35208,7 @@ contents.")
(build-system cargo-build-system)
(arguments `(#:skip-build? #t))
(home-page "https://hg.sr.ht/~icefox/oorandom")
- (synopsis "tiny, robust PRNG implementation")
+ (synopsis "Tiny, robust PRNG implementation")
(description
"This package provides a tiny, robust PRNG implementation.")
(license license:expat)))
@@ -41548,7 +41548,7 @@ data.")
("rust-parking-lot" ,rust-parking-lot-0.11)
("rust-scheduled-thread-pool" ,rust-scheduled-thread-pool-0.2))))
(home-page "https://github.com/sfackler/r2d2")
- (synopsis "generic connection pool")
+ (synopsis "Generic connection pool")
(description "This package provides a generic connection pool.")
(license (list license:expat license:asl2.0))))
@@ -47164,7 +47164,7 @@ server functionality.")
`(#:cargo-inputs
(("rust-parking-lot" ,rust-parking-lot-0.11))))
(home-page "https://github.com/sfackler/scheduled-thread-pool")
- (synopsis "scheduled thread pool")
+ (synopsis "Scheduled thread pool")
(description "This package provides a scheduled thread pool.")
(license (list license:expat license:asl2.0))))
@@ -54559,7 +54559,7 @@ without a mutable reference.")
"0hvd6vk4ksgg2y99498jw52ric4lxm0i6ygpzqm95gdrhvsxyynp"))))
(build-system cargo-build-system)
(home-page "https://docs.rs/takeable-option/")
- (synopsis "small wrapper around option")
+ (synopsis "Small wrapper around option")
(description
"This package provides a small wrapper around option.")
(license (list license:asl2.0 license:expat))))
@@ -60320,7 +60320,7 @@ the Trust-DNS client to use rustls for TLS.")
(build-system cargo-build-system)
(arguments `(#:skip-build? #t))
(home-page "https://github.com/RazrFalcon/ttf-parser")
- (synopsis "high-level, safe, zero-allocation TrueType font parser")
+ (synopsis "High-level, safe, zero-allocation TrueType font parser")
(description
"This package provides a high-level, safe, zero-allocation TrueType font
parser.")
diff --git a/gnu/packages/games.scm b/gnu/packages/games.scm
index a3e66b5d54..3e6cdf4514 100644
--- a/gnu/packages/games.scm
+++ b/gnu/packages/games.scm
@@ -2345,7 +2345,7 @@ exec -a \"~a\" ~a \"$@\"\n"
(inputs
(list python-pygame python-tmx))
(home-page "https://rogueboxadventures.tuxfamily.org")
- (synopsis "classical roguelike/sandbox game")
+ (synopsis "Classical roguelike/sandbox game")
(description
"RogueBox Adventures is a graphical roguelike with strong influences
from sandbox games like Minecraft or Terraria. The main idea of RogueBox
diff --git a/gnu/packages/gl.scm b/gnu/packages/gl.scm
index 34ffc3dd7e..6dd90eaf93 100644
--- a/gnu/packages/gl.scm
+++ b/gnu/packages/gl.scm
@@ -704,7 +704,7 @@ OpenGL graphics API.")
;; epoxy.pc: 'Requires.private: gl egl'
(list mesa))
(home-page "https://github.com/anholt/libepoxy/")
- (synopsis "library for handling OpenGL function pointer management")
+ (synopsis "Library for handling OpenGL function pointer management")
(description
"A library for handling OpenGL function pointer management.")
(license license:x11)))
diff --git a/gnu/packages/gnome-xyz.scm b/gnu/packages/gnome-xyz.scm
index 8c29afc199..0d0a27ede7 100644
--- a/gnu/packages/gnome-xyz.scm
+++ b/gnu/packages/gnome-xyz.scm
@@ -663,7 +663,7 @@ notebooks and tiling window managers.")
optipng
pkg-config
sassc/libsass-3.5))
- (synopsis "flat GTK+ theme with transparent elements")
+ (synopsis "Flat GTK+ theme with transparent elements")
(description "Arc is a flat theme with transparent elements for GTK 3, GTK
2, and GNOME Shell which supports GTK 3 and GTK 2 based desktop environments
like GNOME, Unity, Budgie, Pantheon, XFCE, Mate, etc.")
diff --git a/gnu/packages/haskell-xyz.scm b/gnu/packages/haskell-xyz.scm
index e7afe0de92..1d86fe0c47 100644
--- a/gnu/packages/haskell-xyz.scm
+++ b/gnu/packages/haskell-xyz.scm
@@ -1692,7 +1692,7 @@ command-line utility for working with CBOR data.")
ghc-vector
ghc-cborg))
(home-page "https://github.com/well-typed/cborg")
- (synopsis "library for encoding JSON as CBOR")
+ (synopsis "Library for encoding JSON as CBOR")
(description
"This package implements the bijection between JSON and CBOR
defined in the CBOR specification, RFC 7049.")
@@ -10855,7 +10855,7 @@ better for some purposes.")
(native-inputs
(list ghc-hspec ghc-quickcheck hspec-discover))
(home-page "https://github.com/commercialhaskell/rio#readme")
- (synopsis "standard library for Haskell")
+ (synopsis "Standard library for Haskell")
(description "This package works as a prelude replacement for Haskell,
providing more functionality and types out of the box than the standard
prelude (such as common data types like @code{ByteString} and
diff --git a/gnu/packages/installers.scm b/gnu/packages/installers.scm
index 3fabcc7c92..6ba9bf0827 100644
--- a/gnu/packages/installers.scm
+++ b/gnu/packages/installers.scm
@@ -128,7 +128,7 @@
(substitute* "Source/build.cpp" (("m_target_type=TARGET_X86ANSI")
(string-append "m_target_type=" ,nsis-target-type))))))))
(home-page "http://nsis.sourceforge.net/")
- (synopsis "professional open source system to create Windows installers")
+ (synopsis "Professional open source system to create Windows installers")
(description
"NSIS (Nullsoft Scriptable Install System) is a professional open source
system to create Windows installers. It is designed to be as small and flexible
diff --git a/gnu/packages/lisp-xyz.scm b/gnu/packages/lisp-xyz.scm
index 35c8bd83e4..08e05cae57 100644
--- a/gnu/packages/lisp-xyz.scm
+++ b/gnu/packages/lisp-xyz.scm
@@ -4203,7 +4203,7 @@ PROPER-LIST, ASSOCIATION-LIST, PROPERTY-LIST and TUPLE.")
(("in-package :cl-utilities)" all)
"in-package :cl-utilities)\n\n#+sbcl\n(require :sb-rotate-byte)")))))))
(home-page "http://common-lisp.net/project/cl-utilities")
- (synopsis "collection of semi-standard utilities")
+ (synopsis "Collection of semi-standard utilities")
(description
"On Cliki.net <http://www.cliki.net/Common%20Lisp%20Utilities>, there
is a collection of Common Lisp Utilities, things that everybody writes since
diff --git a/gnu/packages/maths.scm b/gnu/packages/maths.scm
index 54646ab212..3ed766c502 100644
--- a/gnu/packages/maths.scm
+++ b/gnu/packages/maths.scm
@@ -273,7 +273,7 @@ interactive dialogs to guide them.")
(arguments
'(#:configure-flags '("--with-hdf4" "--with-hdf5" "--enable-python"
"LIBS= -lz -lpcre -lexpat")))
- (synopsis "common interface to various earth observation data formats")
+ (synopsis "Common interface to various earth observation data formats")
(description
"The Common Data Access toolbox (CODA) provides a set of interfaces for
reading remote sensing data from earth observation data files. It consists of
diff --git a/gnu/packages/ocaml.scm b/gnu/packages/ocaml.scm
index 4e16252810..22ae63710c 100644
--- a/gnu/packages/ocaml.scm
+++ b/gnu/packages/ocaml.scm
@@ -5842,7 +5842,7 @@ ocaml values.")
("ocaml-ppxlib" ,(package-with-ocaml4.07 ocaml-ppxlib))))
(properties `((upstream-name . "ppx_sexp_message")))
(home-page "https://github.com/janestreet/ppx_sexp_message")
- (synopsis "ppx rewriter for easy construction of s-expressions")
+ (synopsis "Ppx rewriter for easy construction of s-expressions")
(description "Ppx_sexp_message aims to ease the creation of s-expressions
in OCaml. This is mainly motivated by writing error and debugging messages,
where one needs to construct a s-expression based on various element of the
diff --git a/gnu/packages/perl6.scm b/gnu/packages/perl6.scm
index e415c4afee..dab9dd477b 100644
--- a/gnu/packages/perl6.scm
+++ b/gnu/packages/perl6.scm
@@ -298,7 +298,7 @@ have profiling information collected when the grammar is used.")
(build-system rakudo-build-system)
(arguments '(#:with-zef? #f))
(home-page "https://github.com/moritz/json")
- (synopsis "minimal JSON (de)serializer")
+ (synopsis "Minimal JSON (de)serializer")
(description "This module is a simple Perl 6 module for serializing and
deserializing JSON.")
(license license:artistic2.0)))
diff --git a/gnu/packages/python-xyz.scm b/gnu/packages/python-xyz.scm
index a1f3a54342..beb3b3a471 100644
--- a/gnu/packages/python-xyz.scm
+++ b/gnu/packages/python-xyz.scm