aboutsummaryrefslogtreecommitdiff
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2022 Maxim Cournoyer <maxim.cournoyer@gmail.com>
;;;
;;; 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 services vnc)
  #:use-module (gnu packages admin)
  #:use-module (gnu packages vnc)
  #:use-module ((gnu services) #:hide (delete))
  #:use-module (gnu system shadow)
  #:use-module (gnu services configuration)
  #:use-module (gnu services shepherd)
  #:use-module (guix gexp)
  #:use-module (guix records)

  #:export (xvnc-configuration
            xvnc-configuration-xvnc
            xvnc-configuration-display-number
            xvnc-configuration-geometry
            xvnc-configuration-depth
            xvnc-configuration-port
            xvnc-configuration-ipv4?
            xvnc-configuration-ipv6?
            xvnc-configuration-password-file
            xvnc-configuration-xdmcp?
            xvnc-configuration-inetd?
            xvnc-configuration-frame-rate
            xvnc-configuration-security-types
            xvnc-configuration-localhost?
            xvnc-configuration-log-level
            xvnc-configuration-extra-options

            xvnc-service-type))

;;;
;;; Xvnc.
;;;

(define (color-depth? x)
  (member x '(16 24 32)))

(define (port? x)
  (and (number? x)
       (and (>= x 0) (<= x 65535))))

(define-maybe/no-serialization port)

(define-maybe/no-serialization string)

(define %security-types '("None" "VncAuth" "Plain" "TLSNone" "TLSVnc" "TLSPlain"
                          "X509None" "X509Vnc"))

(define (security-type? x)
  (member x %security-types))

(define (security-types? x)
  (and (list? x)
       (and-map security-type? x)))

(define (log-level? x)
  (and (number? x)
       (and (>= x 0) (<= x 100))))

(define (strings? x)
  (and (list? x)
       (and-map string? x)))

(define-configuration/no-serialization xvnc-configuration
  (xvnc
   (file-like tigervnc-server)
   "The package that provides the Xvnc binary.")
  (display-number
   (number 0)
   "The display number used by Xvnc.  You should set this to a number not
already used by a Xorg server.  When remoting a complete desktop session via
XDMCP and using a compatible VNC viewer as provided by the
@code{tigervnc-client} or @code{turbovnc} packages, the geometry is
automatically adjusted.")
  (geometry
   (string "1024x768")
   "The size of the desktop to be created.")
  (depth
   (color-depth 24)
   "The pixel depth in bits of the desktop to be created.  Accepted values are
16, 24 or 32.")
  (port
   maybe-port
   "The port on which to listen for connections from viewers.  When left
unspecified, it defaults to 5900 plus the display number.")
  (ipv4?
   (boolean #t)
   "Use IPv4 for incoming and outgoing connections.")
  (ipv6?
   (boolean #t)
   "Use IPv6 for incoming and outgoing connections.")
  (password-file
   maybe-string
   "The password file to use, if any.  Refer to vncpasswd(1) to learn how to
generate such a file.")
  (xdmcp?
   (boolean #f)
   "Query the XDMCP server for a session.  This enables users to log in a
desktop session from the login manager screen.  For a multiple users scenario,
you'll want to enable the @code{inetd?} option as well, so that each
connection to the VNC server is handled separately rather than shared.")
  (inetd?
   (boolean #f)
   "Use an Inetd-style service, which runs the Xvnc server on demand.")
  (frame-rate
   (number 60)
   "The maximum number of updates per second sent to each client.")
  (security-types
   (security-types (list "None"))
   (format #f "The allowed security schemes to use for incoming connections.
The default is \"None\", which is safe given that Xvnc is configured to
authenticate the user via the display manager, and only for local connections.
Accepted values are any of the following: ~s" %security-types))
  (localhost?
   (boolean #t)
   "Only allow connections from the same machine.  It is set to @code{#true}
by default for security, which means SSH or another secure means should be
used to expose the remote port.")
  (log-level
   (log-level 30)
   "The log level, a number between 0 and 100, 100 meaning most verbose
output.  The log messages are output to syslog.")
  (extra-options
   (strings '())
   "This can be used to provide extra Xvnc options not exposed via this
<xvnc-configuration> record."))

(define (xvnc-configuration->command-line-arguments config)
  "Derive the command line arguments to used to launch the Xvnc daemon from
CONFIG, a <xvnc-configuration> object."
  (match-record config <xvnc-configuration>
    (xvnc display-number geometry depth port ipv4? ipv6? password-file xdmcp?
          inetd? frame-rate security-types localhost? log-level extra-options)
    #~(list #$(file-append xvnc "/bin/Xvnc")
            #$@(if inetd? '() (list (format #f ":~a" display-number)))
            "-geometry" #$geometry
            "-depth" #$(number->string depth)
            #$@(if inetd?
                   (list "-inetd")
                   '())
            #$@(if (not inetd?)
                   (if (maybe-value-set? port)
                       (list "-rfbport" (number->string port))
                       '())
                   '())
            #$@(if (not inetd?)
                   (if ipv4?
                       (list "-UseIPv4")
                       '())
                   '())
            #$@(if (not inetd?)
                   (if ipv6?
                       (list "-UseIPv6")
                       '())
                   '())
            #$@(if (maybe-value-set? password-file)
                   (list "-PasswordFile" password-file)
                   '())
            "-FrameRate" #$(number->string frame-rate)
            "-SecurityTypes" #$(string-join security-types ",")
            #$@(if localhost?
                   (list "-localhost")
                   '())
            "-Log" #$(format #f "*:syslog:~a" log-level)
            #$@(if xdmcp?
                   (list "-query" "localhost" "-once")
                   '())
            #$@extra-options)))

(define %xvnc-accounts
  (list (user-group
         (name "xvnc")
         (system? #t))
        (user-account
         (name "xvnc")
         (group "xvnc")
         (system? #t)
         (comment "User for Xvnc server")
         (home-directory "/var/empty")
         (shell (file-append shadow "/sbin/nologin")))))

(define (xvnc-shepherd-service config)
  "Return a <shepherd-service> for Xvnc with CONFIG."
  (let* ((display-number (xvnc-configuration-display-number config))
         (port (if (maybe-value-set? (xvnc-configuration-port config))
                   (xvnc-configuration-port config)
                   #f))
         (port* (or port (+ 5900 display-number))))
    (shepherd-service
     (provision '(xvnc vncserver))
     (documentation "Run the Xvnc server.")
     (requirement '(networking syslogd))
     (start (if (xvnc-configuration-inetd? config)
                #~(let* ((inaddr (if #$(xvnc-configuration-localhost? config)
                                     INADDR_LOOPBACK
                                     INADDR_ANY))
                         (in6addr (if #$(xvnc-configuration-localhost? config)
                                      IN6ADDR_LOOPBACK
                                      IN6ADDR_ANY))
                         (ipv4-socket (and #$(xvnc-configuration-ipv4? config)
                                           (make-socket-address AF_INET inaddr
                                                                #$port*)))
                         (ipv6-socket (and #$(xvnc-configuration-ipv6? config)
                                           (make-socket-address AF_INET6 in6addr
                                                                #$port*))))
                    (make-inetd-constructor
                     #$(xvnc-configuration->command-line-arguments config)
                     `(,@(if ipv4-socket
                             (list (endpoint ipv4-socket))
                             '())
                       ,@(if ipv6-socket
                             (list (endpoint ipv6-socket))
                             '()))
                     #:requirements '#$requirement
                     #:user "xvnc"
                     #:group "xvnc"))
                #~(make-forkexec-constructor
                   #$(xvnc-configuration->command-line-arguments config)
                   #:user "xvnc"
                   #:group "xvnc")))
     (stop #~(make-inetd-destructor)))))

(define xvnc-service-type
  (service-type
   (name 'xvnc)
   (default-value (xvnc-configuration))
   (description "Run the Xvnc server, which creates a virtual X11 session and
allow remote clients connecting to it via the remote framebuffer (RFB)
protocol.")
   (extensions (list (service-extension
                      shepherd-root-service-type
                      (compose list xvnc-shepherd-service))
                     (service-extension account-service-type
                                        (const %xvnc-accounts))))))
hronization. <jami>: Set DBUS_SESSION_BUS_ADDRESS environment variable. Poll using 'jami-service-available?' instead of 'dbus-service-available?'. * gnu/tests/telephony.scm (run-jami-test): Add needed Guile extensions. Set DBUS_SESSION_BUS_ADDRESS environment variable. Adjust all tests to use 'jami-service-available?' to determine if the service is started rather than the now problematic Shepherd's 'start-service'. Maxim Cournoyer 2022-04-12services: Replace murmur-service-type with mumble-server-service-type....* gnu/services/telephony.scm (murmur-configuration, make-murmur-configuration) (murmur-configuration?, murmur-configuration-package) (murmur-configuration-user, murmur-configuration-group) (murmur-configuration-port, murmur-configuration-welcome-text) (murmur-configuration-server-password) (murmur-configuration-max-users) (murmur-configuration-max-user-bandwidth) (murmur-configuration-database-file) (murmur-configuration-log-file, murmur-configuration-pid-file) (murmur-configuration-autoban-attempts) (murmur-configuration-autoban-timeframe) (murmur-configuration-autoban-time) (murmur-configuration-opus-threshold) (murmur-configuration-channel-nesting-limit) (murmur-configuration-channelname-regex) (murmur-configuration-username-regex) (murmur-configuration-test-message-length) (murmur-configuration-image-message-length) (murmur-configuration-cert-required?) (murmur-configuration-remember-channel?) (murmur-configuration-allow-html?) (murmur-configuration-allow-ping?) (murmur-configuration-bonjour?) (murmur-configuration-send-version?) (murmur-configuration-log-days) (murmur-configuration-obfuscate-ips?) (murmur-configuration-ssl-cert murmur-configuration-ssl-key) (murmur-configuration-ssl-dh-params murmur-configuration-ssl-ciphers) (murmur-configuration-public-registration) (murmur-configuration-file) (murmur-public-registration-configuration) (make-murmur-public-registration-configuration) (murmur-public-registration-configuration?) (murmur-public-registration-configuration-name) (murmur-public-registration-configuration-url) (murmur-public-registration-configuration-password) (murmur-public-registration-configuration-hostname) (murmur-service-type): Add deprecation alias and rename to ... (mumble-server-configuration, make-mumble-server-configuration) (mumble-server-configuration?, mumble-server-configuration-package) (mumble-server-configuration-user, mumble-server-configuration-group) (mumble-server-configuration-port, mumble-server-configuration-welcome-text) (mumble-server-configuration-server-password) (mumble-server-configuration-max-users) (mumble-server-configuration-max-user-bandwidth) (mumble-server-configuration-database-file) (mumble-server-configuration-log-file, mumble-server-configuration-pid-file) (mumble-server-configuration-autoban-attempts) (mumble-server-configuration-autoban-timeframe) (mumble-server-configuration-autoban-time) (mumble-server-configuration-opus-threshold) (mumble-server-configuration-channel-nesting-limit) (mumble-server-configuration-channelname-regex) (mumble-server-configuration-username-regex) (mumble-server-configuration-test-message-length) (mumble-server-configuration-image-message-length) (mumble-server-configuration-cert-required?) (mumble-server-configuration-remember-channel?) (mumble-server-configuration-allow-html?) (mumble-server-configuration-allow-ping?) (mumble-server-configuration-bonjour?) (mumble-server-configuration-send-version?) (mumble-server-configuration-log-days) (mumble-server-configuration-obfuscate-ips?) (mumble-server-configuration-ssl-cert mumble-server-configuration-ssl-key) (mumble-server-configuration-ssl-dh-params) (mumble-server-configuration-ssl-ciphers) (mumble-server-configuration-public-registration) (mumble-server-configuration-file) (mumble-server-public-registration-configuration) (make-mumble-server-public-registration-configuration) (mumble-server-public-registration-configuration?) (mumble-server-public-registration-configuration-name) (mumble-server-public-registration-configuration-url) (mumble-server-public-registration-configuration-password) (mumble-server-public-registration-configuration-hostname) (mumble-server-service-type): ... these. * doc/guix.texi ("Murmur (VoIP server)"): Rename to ... ("Mumble server"): ... this. Adjust documentation accordingly. Liliana Marie Prikler 2022-03-24services: murmur: Fix server program name....* gnu/services/telephony.scm (murmur-activation): (murmur-shepherd-service): Change file name of mumble server, which is now called mumble-server instead of murmurd since version 1.4.x. Co-authored-by: Ludovic Courtès <ludo@gnu.org> fesoj000 2022-01-13services: Adjust the jami service for the upgraded jami....* gnu/services/telephony.scm (jami-configuration)[jamid]: Rename libring to libjami. * gnu/services/telephony.scm (jami-configuration->command-line-arguments): Adjust daemon file name. * gnu/services/telephony.scm (jami-service-type): Adjust doc. * gnu/tests/telephony.scm (run-jami-test): Check for 'jamid' process, not 'dring'. * doc/guix.texi (Telephony Services): Adjust doc for the jami-qt to jami and libring to libjami packages renaming. Maxim Cournoyer 2021-11-30services: Accept <inferior-package>s in lieu of <package>s....* gnu/services/authentication.scm (fprintd-configuration) (nslcd-configuration): Substitute file-like objects for package ones. * gnu/services/cgit.scm (cgit-configuration, opaque-cgit-configuration): Likewise. * gnu/services/cups.scm (package-list?, cups-configuration): Likewise. * gnu/services/dns.scm (verify-knot-configuration) (ddclient-configuration): Likewise. * gnu/services/docker.scm (docker-configuration): Likewise. * gnu/services/file-sharing.scm (transmission-daemon-configuration): Likewise. * gnu/services/getmail.scm (getmail-configuration): Likewise. * gnu/services/mail.scm (dovecot-configuration) (opaque-dovecot-configuration): Likewise. * gnu/services/messaging.scm (prosody-configuration) (opaque-prosody-configuration): Likewise. * gnu/services/monitoring.scm (zabbix-server-configuration) (zabbix-agent-configuration): Likewise. * gnu/services/networking.scm (opendht-configuration): Likewise. * gnu/services/pm.scm (tlp-configuration): Likewise. * gnu/services/telephony.scm (jami-configuration): Likewise. * gnu/services/virtualization.scm (libvirt-configuration) (qemu-guest-agent-configuration): Likewise. * gnu/services/vpn.scm (openvpn-client-configuration): Likewise. Tobias Geerinckx-Rice 2021-08-02Reinstate "services: Add a service for Jami."...This reverts commit 4673f817938d9d2b1b40a072ab2e0c44a32ccc97, which reverted commit 69dcc24c9f0cdfea674eb690e7755d26a25ced2b with the fix detailed below. Thanks to Christopher Baines for reporting the failure and proposing a fix. * guix/self.scm (compiled-guix) [*system-test-modules*]: Add the test data files via the 'extra-files' argument. * gnu/local.mk (dist_patch_DATA): Move the tests/data/jami-dummy-account.dat file to... * gnu/local.mk (MODULES_NOT_COMPILED): ... here. Maxim Cournoyer 2021-08-02Revert "services: Add a service for Jami."...This reverts commit 69dcc24c9f0cdfea674eb690e7755d26a25ced2b. It broke 'guix pull'. Maxim Cournoyer 2021-08-02services: Add a service for Jami....* gnu/services/telephony.scm (string-or-computed-file?) (string-list?, account-fingerprint-list?): New procedures. (maybe-string-list, maybe-account-fingerprint-list) (maybe-boolean, maybe-string, jami-account-list): New configuration field types. (serialize-string-list, serialize-boolean, serialize-string) (jami-account, jami-account->alist, jami-configuration) (jami-account-list?, jami-account-list-maybe): New procedures. (%jami-accounts): New variable. (jami-configuration->command-line-arguments): New procedure. (jami-dbus-session-activation, jami-shepherd-services): New procedures. (jami-service-type): New variable. * gnu/build/jami-service.scm: New file. * gnu/tests/data/jami-dummy-account.dat: Likewise. * gnu/tests/telephony.scm: Likewise. * gnu/local.mk (GNU_SYSTEM_MODULES): Register them. * Makefile.am (SCM_TESTS): Register the test file. (dist_patch_DATA): Register the new data file. * doc/guix.texi (Telephony Services): Document it. Maxim Cournoyer 2020-04-02services: murmur: Add missing newline in murmur-configuration....* gnu/services/telephony.scm (default-murmur-config): Add newline after "max-user-bandwidth". Signed-off-by: Marius Bakke <mbakke@fastmail.com> Simon Mages