services.scm (6644B)


      1 (define-module (mt services)
      2   #:use-module (srfi srfi-1)
      3   #:use-module (guix gexp)
      4   #:use-module (gnu packages admin)
      5   #:use-module (gnu packages libusb)
      6   #:use-module (gnu packages linux)
      7   #:use-module (gnu packages nfs)
      8   #:use-module (gnu services)
      9   #:use-module (gnu services avahi)
     10   #:use-module (gnu services base)
     11   #:use-module (gnu services dbus)
     12   #:use-module (gnu services desktop)
     13   #:use-module (gnu services networking)
     14   #:use-module (gnu services sound)
     15   #:use-module (gnu services ssh)
     16   #:use-module (gnu system)
     17   #:use-module (gnu system privilege)
     18   #:use-module (mt channels)
     19   #:use-module (mt channels-locked)
     20   #:export (etc-mt-client-service
     21             tuigreet-login-manager
     22             greetd-helper-service
     23             mt-base-services
     24             %mt-bishop-services
     25             %mt-clergy-services
     26             %mt-laity-services
     27             %mt-desktop-services))
     28 
     29 (define (etc-mt-client-service client)
     30   (simple-service 'etc-mt-client
     31                   etc-service-type
     32                   (list
     33                    `("mt-client"
     34                      ,(plain-file "mt-client" client)))))
     35 
     36 ;; Generate a login manager script based on tuigreet
     37 (define* (tuigreet-login-manager
     38           #:key (args '("--time"
     39                         "--user-menu"
     40                         "--window-padding" "1"
     41                         "--asterisks"
     42                         "--remember"
     43                         "--remember-user-session"))
     44                 ;; TODO: Fix atrocious light mode
     45                 (colors (list "FFFCF0" "F2F0E5"
     46                               "AF3029" "D14D41"
     47                               "66800B" "879A39"
     48                               "AD8301" "D0A215"
     49                               "205EA6" "4385BE"
     50                               "A02F6F" "CE5D97"
     51                               "24837B" "3AA99F"
     52                               "100F0F" "6F6E69")))
     53   (let ((tuigreet-bin (file-append tuigreet "/bin/tuigreet"))
     54         (setfont-bin (file-append kbd "/bin/setfont"))
     55         (color-codes (list "P0" "P8" "P1" "P9" "P2" "PA" "P3" "PB"
     56                            "P4" "PC" "P5" "PD" "P6" "PE" "P7" "PF")))
     57     (program-file
     58       "tuigreet-wrapper"
     59       #~(begin
     60          ;; TODO: Take font as argument
     61          (system* #$setfont-bin "-d" "alt-8x8")
     62          ;; Set TTY colors
     63          (for-each (lambda (color-code color)
     64                      (display #\esc)
     65                      (display "]")
     66                      (display color-code)
     67                      (display color))
     68                    '#$color-codes
     69                    '#$colors)
     70          ;; Switch current process to tuigreet
     71          (execl #$tuigreet-bin #$tuigreet-bin
     72                 #$@args)))))
     73 
     74 
     75 ;; Generate a greetd service
     76 (define* (greetd-helper-service #:key (login-manager (tuigreet-login-manager)))
     77   (service greetd-service-type
     78            (greetd-configuration
     79              (terminals
     80               (list
     81                (greetd-terminal-configuration (terminal-vt "1"))
     82                (greetd-terminal-configuration (terminal-vt "2"))
     83                (greetd-terminal-configuration (terminal-vt "3"))
     84                (greetd-terminal-configuration (terminal-vt "4"))
     85                (greetd-terminal-configuration (terminal-vt "5"))
     86                (greetd-terminal-configuration (terminal-vt "6"))
     87                (greetd-terminal-configuration
     88                 (terminal-vt "7")
     89                 (terminal-switch #t)
     90                 (default-session-command login-manager)))))))
     91 
     92 (define* (mt-base-services #:key (discover? #f)
     93                                  (sans-mt-substitutes? #f))
     94   (append
     95     (list
     96      (service openssh-service-type
     97               (openssh-configuration
     98                 (password-authentication? #f))))
     99     (modify-services %base-services
    100       (guix-service-type
    101           config => (guix-configuration
    102                       (inherit config)
    103                       (channels %mt-channels-locked)
    104                       (discover? discover?)
    105                       (substitute-urls (if sans-mt-substitutes?
    106                                          (cdr %mt-substitute-urls)
    107                                          %mt-substitute-urls))
    108                       (authorized-keys (if sans-mt-substitutes?
    109                                          (cdr %mt-authorized-guix-keys)
    110                                          %mt-authorized-guix-keys))))
    111       (delete login-service-type)
    112       (delete mingetty-service-type)
    113       (delete console-font-service-type))))
    114 
    115 ;; Provide substitutes for all machines and perform build farm capabilities
    116 ;; TODO: Add anti-spam measures
    117 ;; TODO: Add build farm capabilities
    118 ;; TODO: 
    119 (define %mt-bishop-services
    120   (append
    121     (list
    122      ;; Required by guix-publish
    123      (service avahi-service-type)
    124      ;; Host a substitute server on locahost.
    125      ;; Each server should ideally serve this from a subdomain.
    126      (service guix-publish-service-type
    127               (guix-publish-configuration
    128                 (port 8080))))
    129    (mt-base-services #:sans-mt-substitutes? #t)))
    130 
    131 (define %mt-clergy-services
    132   (append
    133     (list 
    134       ;; Host a local substitute server
    135       (service guix-publish-service-type
    136                (guix-publish-configuration
    137                  (host "0.0.0.0")
    138                  (advertise? #t))))
    139   (mt-base-services)))
    140 
    141 (define %mt-laity-services
    142   (mt-base-services #:discover? #t))
    143 
    144 ;; These are basic services that will generally be used by all user systems. It
    145 ;; should contain everything necessary to begin building a basic desktop setup.
    146 ;; Essentially, these are all the "standard" services that you wouldn't need on
    147 ;; a server.
    148 ;; TODO: Add printer-related services
    149 (define %mt-desktop-services
    150    (list
    151      ;; Essential
    152      (service dbus-root-service-type)
    153      (service elogind-service-type)
    154      (service polkit-service-type)
    155      polkit-wheel-service
    156      (service avahi-service-type) ;; Used by guix-daemon
    157      (service ntp-service-type)
    158     
    159      ;; Complimentary
    160      fontconfig-file-system-service
    161      (service udisks-service-type)
    162      (service upower-service-type) ;; TODO: Make optional
    163 
    164      ;; Networking
    165      (service network-manager-service-type)
    166      (service wpa-supplicant-service-type)
    167      (service usb-modeswitch-service-type)
    168 
    169      ;; Audio
    170      (service pulseaudio-service-type)
    171      (service alsa-service-type)))
    172 
    173 ;; TODO: Create automatic update services
    174 ;; This would be for laity and clergy machines. It would basically check for
    175 ;; configuration / channel updates daily and notify users that updates are
    176 ;; available. They will not be forced to update. It would also prompt monthly to
    177 ;; perform a guix update.