;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2017 Oleg Pykhalov ;;; Copyright © 2021 Ludovic Courtès ;;; ;;; 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 . (define-module (gnu services rsync) #:use-module (gnu services) #:use-module (gnu services base) #:use-module (gnu services shepherd) #:use-module (
aboutsummaryrefslogtreecommitdiff
;; -*- mode: scheme; -*-
;; This is an operating system configuration for a VM image.
;; Modify it as you see fit and instantiate the changes by running:
;;
;;   guix system reconfigure /etc/config.scm
;;

(use-modules (gnu) (guix) (srfi srfi-1))
(use-service-modules desktop mcron networking spice ssh xorg sddm)
(use-package-modules bootloaders fonts
                     package-management xdisorg xorg)

(define vm-image-motd (plain-file "motd" "
\x1b[1;37mThis is the GNU system.  Welcome!\x1b[0m

This instance of Guix is a template for virtualized environments.
You can reconfigure the whole system by adjusting /etc/config.scm
and running:

  guix system reconfigure /etc/config.scm

Run '\x1b[1;37minfo guix\x1b[0m' to browse documentation.

\x1b[1;33mConsider setting a password for the 'root' and 'guest' \
accounts.\x1b[0m
"))

(operating-system
  (host-name "gnu")
  (timezone "Etc/UTC")
  (locale "en_US.utf8")
  (keyboard-layout (keyboard-layout "us" "altgr-intl"))

  ;; Label for the GRUB boot menu.
  (label (string-append "GNU Guix "
                        (or (getenv "GUIX_DISPLAYED_VERSION")
                            (package-version guix))))

  (firmware '())

  ;; Below we assume /dev/vda is the VM's hard disk.
  ;; Adjust as needed.
  (bootloader (bootloader-configuration
               (bootloader grub-bootloader)
               (targets '("/dev/vda"))
               (terminal-outputs '(console))))
  (file-systems (cons (file-system
                        (mount-point "/")
                        (device "/dev/vda1")
                        (type "ext4"))
                      %base-file-systems))

  (users (cons (user-account
                (name "guest")
                (comment "GNU Guix Live")
                (password "")           ;no password
                (group "users")
                (supplementary-groups '("wheel" "netdev"
                                        "audio" "video")))
               %base-user-accounts))

  ;; Our /etc/sudoers file.  Since 'guest' initially has an empty password,
  ;; allow for password-less sudo.
  (sudoers-file (plain-file "sudoers" "\
root ALL=(ALL) ALL
%wheel ALL=NOPASSWD: ALL\n"))

  (packages
   (append (list font-bitstream-vera
                 ;; Auto-started script providing SPICE dynamic resizing for
                 ;; Xfce (see:
                 ;; https://gitlab.xfce.org/xfce/xfce4-settings/-/issues/142).
                 x-resize)
           %base-packages))

  (services
   (append (list (service xfce-desktop-service-type)

                 ;; Choose SLiM, which is lighter than the default GDM.
                 (service slim-service-type
                          (slim-configuration
                           (auto-login? #t)
                           (default-user "guest")
                           (xorg-configuration
                            (xorg-configuration
                             ;; The QXL virtual GPU driver is added to provide
                             ;; a better SPICE experience.
                             (modules (cons xf86-video-qxl
                                            %default-xorg-modules))
                             (keyboard-layout keyboard-layout)))))

                 ;; Uncomment the line below to add an SSH server.
                 ;;(service openssh-service-type)

                 ;; Add support for the SPICE protocol, which enables dynamic
                 ;; resizing of the guest screen resolution, clipboard
                 ;; integration with the host, etc.
                 (service spice-vdagent-service-type)

                 ;; Use the DHCP client service rather than NetworkManager.
                 (service dhcp-client-service-type))

           ;; Remove some services that don't make sense in a VM.
           (remove (lambda (service)
                     (let ((type (service-kind service)))
                       (or (memq type
                                 (list gdm-service-type
                                       sddm-service-type
                                       wpa-supplicant-service-type
                                       cups-pk-helper-service-type
                                       network-manager-service-type
                                       modem-manager-service-type))
                           (eq? 'network-manager-applet
                                (service-type-name type)))))
                   (modify-services %desktop-services
                     (login-service-type config =>
                                         (login-configuration
                                          (inherit config)
                                          (motd vm-image-motd)))

                     ;; Install and run the current Guix rather than an older
                     ;; snapshot.
                     (guix-service-type config =>
                                        (guix-configuration
                                         (inherit config)
                                         (guix (current-guix))))))))

  ;; Allow resolution of '.local' host names with mDNS.
  (name-service-switch %mdns-host-lookup-nss))
file-name comment chroot? read-only? timeout) (list "[" name "]\n" " path = " file-name "\n" " use chroot = " (if chroot? "true" "false") "\n" " comment = " comment "\n" " read only = " (if read-only? "true" "false") "\n" " timeout = " (number->string timeout) "\n"))) (define modules (rsync-configuration-modules config)) (match-record config (package address port-number pid-file lock-file log-file user group uid gid) (unless (string=? user "root") (cond ((<= port-number 1024) (error (string-append "rsync-service: to run on port " (number->string port-number) ", user must be root."))) ((find rsync-module-chroot? modules) (error (string-append "rsync-service: to run in a chroot" ", user must be root."))) (uid (error "rsync-service: to use uid, user must be root.")) (gid (error "rsync-service: to use gid, user must be root.")))) (apply mixed-text-file "rsync.conf" "# Generated by 'rsync-service'.\n\n" "pid file = " pid-file "\n" "lock file = " lock-file "\n" "log file = " log-file "\n" (if address (string-append "address = " address "\n") "") "port = " (number->string port-number) "\n" (if uid (string-append "uid = " uid "\n") "") "gid = " (if gid gid "nogroup") "\n" ; no group nobody "\n\n" (append-map module-config modules)))) (define (rsync-shepherd-service config) "Return a for rsync with CONFIG." (let* ((rsync (rsync-configuration-package config)) (pid-file (rsync-configuration-pid-file config)) (port-number (rsync-configuration-port-number config)) (user (rsync-configuration-user config)) (group (rsync-configuration-group config))) (list (shepherd-service (provision '(rsync)) (documentation "Run rsync daemon.") (start #~(make-forkexec-constructor (list (string-append #$rsync "/bin/rsync") "--config" #$(rsync-config-file config) "--daemon") #:pid-file #$pid-file #:user #$user #:group #$group)) (stop #~(make-kill-destructor)))))) (define rsync-service-type (service-type (name 'rsync) (extensions (list (service-extension shepherd-root-service-type rsync-shepherd-service) (service-extension account-service-type rsync-account) (service-extension activation-service-type rsync-activation))) (default-value (rsync-configuration)) (description "Run the rsync file copying tool in daemon mode. This allows remote hosts to keep synchronized copies of the files exported by rsync.")))