Subject: [PATCH] services: Let cups-service-type reuse base lp group.

From: Leo Prikler <[email-masked]>
Date: Thu, 14 Jan 2021 14:06:11 +0100

* gnu/services/cups.scm (%cups-accounts): Try to use the lp group defined in
%base-groups.
* gnu/system/shadow.scm (account-activation): Delete duplicate (eq?) users
and groups before transforming them to specs and asserting, that names are
unique.
---
 gnu/services/cups.scm | 10 ++++++++--
 gnu/system/shadow.scm |  4 ++--
 2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/gnu/services/cups.scm b/gnu/services/cups.scm
index f10615e59e..17ed04e58b 100644
--- a/gnu/services/cups.scm
+++ b/gnu/services/cups.scm
@@ -32,7 +32,7 @@
   #:use-module (guix records)
   #:use-module (guix gexp)
   #:use-module (ice-9 match)
-  #:use-module ((srfi srfi-1) #:select (append-map))
+  #:use-module ((srfi srfi-1) #:select (append-map find))
   #:export (cups-service-type
             cups-configuration
             opaque-cups-configuration
@@ -50,7 +50,13 @@
 ;;; Code:
 
 (define %cups-accounts
-  (list (user-group (name "lp") (system? #t))
+  (list (or
+         ;; The "lp" group should already exist; try to reuse it.
+         (find (lambda (group)
+                 (and (user-group? group)
+                      (string=? (user-group-name group) "lp")))
+               %base-groups)
+         (user-group (name "lp") (system? #t)))
         (user-group (name "lpadmin") (system? #t))
         (user-account
          (name "lp")
diff --git a/gnu/system/shadow.scm b/gnu/system/shadow.scm
index 0538fb1a24..7c57222716 100644
--- a/gnu/system/shadow.scm
+++ b/gnu/system/shadow.scm
@@ -321,13 +321,13 @@ of user '~a' is undeclared")
 <user-group> objects.  Raise an error if a user account refers to a undefined
 group."
   (define accounts
-    (filter user-account? accounts+groups))
+    (delete-duplicates (filter user-account? accounts+groups) eq?))
 
   (define user-specs
     (map user-account->gexp accounts))
 
   (define groups
-    (filter user-group? accounts+groups))
+    (delete-duplicates (filter user-group? accounts+groups) eq?))
 
   (define group-specs
     (map user-group->gexp groups))
-- 
2.30.0