services: etc: Detect and report duplicate entries.

Fixes <https://bugs.gnu.org/40729>.
Reported by Christopher Baines <mail@cbaines.net>.

* gnu/services.scm (files->etc-directory)[assert-no-duplicates]: New
procedure.
Use it.
This commit is contained in:
Ludovic Courtès 2020-04-20 22:31:38 +02:00
parent b25ecfa2e0
commit a322e9d16b
No known key found for this signature in database
GPG key ID: 090B11993D9AEBB5

View file

@ -632,6 +632,23 @@ (define (etc-directory service)
(files->etc-directory (service-value service)))
(define (files->etc-directory files)
(define (assert-no-duplicates files)
(let loop ((files files)
(seen (set)))
(match files
(() #t)
(((file _) rest ...)
(when (set-contains? seen file)
(raise (condition
(&message
(message (format #f (G_ "duplicate '~a' entry for /etc")
file))))))
(loop rest (set-insert file seen))))))
;; Detect duplicates early instead of letting them through, eventually
;; leading to a build failure of "etc.drv".
(assert-no-duplicates files)
(file-union "etc" files))
(define (etc-entry files)