Subject: [PATCH] services: add perpipherals

From: Brice Waegeneire <[email-masked]>
Date: Sun, 5 Apr 2020 21:48:32 +0200

---
 Makefile                         |  1 +
 modules/config/base.scm          |  4 +---
 modules/config/workstation.scm   |  4 ++--
 modules/services/peripherals.scm | 30 ++++++++++++++++++++++++++++++
 4 files changed, 34 insertions(+), 5 deletions(-)
 create mode 100644 modules/services/peripherals.scm

diff --git a/Makefile b/Makefile
index 9242659..9941cf6 100644
--- a/Makefile
+++ b/Makefile
@@ -7,6 +7,7 @@ MODULES =                               								\
 	$(MODULES_DIR)/config/base.scm                          			\
 	$(MODULES_DIR)/config/workstation.scm                         		\
 	$(MODULES_DIR)/services/kernel-modules.scm                          \
+	$(MODULES_DIR)/services/peripherals.scm                             \
 	$(MODULES_DIR)/utils.scm
 
 SCM_FILES = $(MODULES) $(MISC_SCM_FILES)
diff --git a/modules/config/base.scm b/modules/config/base.scm
index acc76e9..ef80130 100644
--- a/modules/config/base.scm
+++ b/modules/config/base.scm
@@ -75,16 +75,14 @@
                  (supplementary-groups
                   '("wheel" "netdev" "audio" "video"
                     "lp" ; for bluetooth tether
-                    "plugdev" ; TODO extract it to u2f service
+                    "plugdev" ; u2f
                     "input"   ; for brightness control through brightnessctl
                     "adbusers"
                     "kvm" "libvirt"
                     )))
                 %base-user-accounts))
 
-   ;; TODO extract it to u2f service
    (groups (append (list
-                    (user-group (name "plugdev") (system? #t))
                     (user-group (name "adbusers") (system? #t)))
                    %base-groups))
 
diff --git a/modules/config/workstation.scm b/modules/config/workstation.scm
index 2ce09df..a965fbd 100644
--- a/modules/config/workstation.scm
+++ b/modules/config/workstation.scm
@@ -20,6 +20,7 @@
   #:use-module (config base)
   #:use-module (utils)
   #:use-module (services kernel-modules)
+  #:use-module (services peripherals)
   #:use-module (srfi srfi-1)
   #:export (workstation-os
             workstation-packages
@@ -48,8 +49,7 @@
    (service gpm-service-type)           ; Mouse on console
    (service pcscd-service-type)
    (load-kernel-modules-service '("ddcci" "ddcci_backlight"))
-   ;; TODO replace the following line with (service u2f-service-type)
-   (simple-service 'u2f-udev udev-service-type (list libu2f-host))
+   (service u2f-service-type)
    (simple-service 'android-udev udev-service-type (list android-udev-rules))
    (simple-service 'backlight-udev udev-service-type (list brightnessctl))))
 
diff --git a/modules/services/peripherals.scm b/modules/services/peripherals.scm
new file mode 100644
index 0000000..6d2d484
--- /dev/null
+++ b/modules/services/peripherals.scm
@@ -0,0 +1,30 @@
+(define-module (services peripherals)
+  #:use-module (gnu services)
+  #:use-module (gnu services base)
+  #:use-module (gnu services configuration)
+  #:use-module (gnu system accounts)
+  #:use-module (gnu system shadow)
+  #:use-module (gnu packages security-token)
+  #:use-module (guix packages)
+  #:export (u2f-service-type))
+
+(define-configuration u2f-configuration
+  (u2f    (package libu2f-host)
+          "The u2f package"))
+
+(define (u2f-udev-service config)
+  (list (u2f-configuration-u2f config)))
+
+(define u2f-accounts
+  (const (list (user-group (name "plugdev") (system? #t)))))
+
+(define u2f-service-type
+  (service-type (name 'u2f)
+                (extensions
+                 (list (service-extension udev-service-type
+                                          u2f-udev-service)
+                       (service-extension account-service-type
+                                          u2f-accounts)))
+                (default-value (u2f-configuration))
+                (description
+                 "Give access to u2f tokens for plugdev members.")))
-- 
2.26.0