From 3fa1e930b827aebca2dbbfe84c36cf203f15afda Mon Sep 17 00:00:00 2001
From: Chris Marusich
Date: Mon, 20 Aug 2018 00:16:06 -0700
Subject: [PATCH] gnu: services: Fix pcscd activation bug.
* gnu/services/security-token.scm (pcscd-activation): Idempotently create the
/var/lib/pcsc symlink so that it does not fail when it already exists.
---
gnu/services/security-token.scm | 36 +++++++++++++++++++++++++--------
1 file changed, 28 insertions(+), 8 deletions(-)
diff --git a/gnu/services/security-token.scm b/gnu/services/security-token.scm
index 7e7ea54a5..8bea49538 100644
--- a/gnu/services/security-token.scm
+++ b/gnu/services/security-token.scm
@@ -20,6 +20,7 @@
#:use-module (gnu services)
#:use-module (gnu services shepherd)
#:use-module (gnu packages admin)
+ #:use-module (gnu packages base)
#:use-module (gnu packages security-token)
#:use-module (gnu system shadow)
#:use-module (guix gexp)
@@ -62,14 +63,33 @@
(define pcscd-activation
(match-lambda
(($ pcsc-lite usb-drivers)
- #~(begin
- (use-modules (guix build utils))
- (mkdir-p "/var/lib")
- (symlink #$(directory-union
- "pcsc"
- (map (cut file-append <> "/pcsc")
- usb-drivers))
- "/var/lib/pcsc")))))
+ (with-imported-modules (source-module-closure
+ '((guix build utils)))
+ #~(begin
+ (use-modules (guix build utils))
+ ;; This switch-symlinks procedure was copied from (guix utils). It
+ ;; would be nice to re-use the procedure from that module, but if
+ ;; we add that module to this gexp's imported modules and try to
+ ;; use it, then this activation gexp can fail when it runs. To be
+ ;; specific, if you try to use (guix utils) and then build a VM
+ ;; with a pcscd-service-type using "guix system vm-image", then
+ ;; when you boot the VM, it will fail. It fails because (guix
+ ;; utils) dynamically links glibc's strverscmp function when
+ ;; defining the version-compare procedure, and for some reason
+ ;; strverscmp can't be found. Perhaps there's a way to fix or
+ ;; avoid this, but since we don't need the version-compare
+ ;; procedure here, anyway, it's simpler to just define our own
+ ;; switch-symlinks procedure instead.
+ (define (switch-symlinks link target)
+ (let ((pivot (string-append link ".new")))
+ (symlink target pivot)
+ (rename-file pivot link)))
+ (mkdir-p "/var/lib")
+ (switch-symlinks "/var/lib/pcsc"
+ #$(directory-union
+ "pcsc"
+ (map (cut file-append <> "/pcsc")
+ usb-drivers))))))))
(define pcscd-service-type
(service-type
--
2.18.0