1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2016 Andy Wingo <wingo@pobox.com>
3 ;;; Copyright © 2017 Clément Lassieur <clement@lassieur.org>
4 ;;; Copyright © 2018 Ricardo Wurmus <rekado@elephly.net>
6 ;;; This file is part of GNU Guix.
8 ;;; GNU Guix is free software; you can redistribute it and/or modify it
9 ;;; under the terms of the GNU General Public License as published by
10 ;;; the Free Software Foundation; either version 3 of the License, or (at
11 ;;; your option) any later version.
13 ;;; GNU Guix is distributed in the hope that it will be useful, but
14 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;;; GNU General Public License for more details.
18 ;;; You should have received a copy of the GNU General Public License
19 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
21 (define-module (gnu services cups)
22 #:use-module (gnu services)
23 #:use-module (gnu services shepherd)
24 #:use-module (gnu services configuration)
25 #:use-module (gnu system shadow)
26 #:use-module (gnu packages admin)
27 #:use-module (gnu packages cups)
28 #:use-module (gnu packages tls)
29 #:use-module (guix packages)
30 #:use-module (guix records)
31 #:use-module (guix gexp)
32 #:use-module (ice-9 match)
33 #:use-module ((srfi srfi-1) #:select (append-map))
34 #:export (cups-service-type
36 opaque-cups-configuration
40 location-access-control
41 operation-access-control
42 method-access-control))
46 ;;; Service defininition for the CUPS printing system.
50 (define %cups-accounts
51 (list (user-group (name "lp") (system? #t))
52 (user-group (name "lpadmin") (system? #t))
57 (comment "System user for invoking printing helper programs")
58 (home-directory "/var/empty")
59 (shell (file-append shadow "/sbin/nologin")))))
61 (define (uglify-field-name field-name)
62 (let ((str (symbol->string field-name)))
65 (string-split (if (string-suffix? "?" str)
66 (substring str 0 (1- (string-length str)))
70 (define (serialize-field field-name val)
71 (format #t "~a ~a\n" (uglify-field-name field-name) val))
73 (define (serialize-string field-name val)
74 (serialize-field field-name val))
76 (define (multiline-string-list? val)
79 (and (string? x) (not (string-index x #\space))))
81 (define (serialize-multiline-string-list field-name val)
82 (for-each (lambda (str) (serialize-field field-name str)) val))
84 (define (space-separated-string-list? val)
87 (and (string? x) (not (string-index x #\space))))
89 (define (serialize-space-separated-string-list field-name val)
90 (serialize-field field-name (string-join val " ")))
92 (define (space-separated-symbol-list? val)
93 (and (list? val) (and-map symbol? val)))
94 (define (serialize-space-separated-symbol-list field-name val)
95 (serialize-field field-name (string-join (map symbol->string val) " ")))
97 (define (file-name? val)
99 (string-prefix? "/" val)))
100 (define (serialize-file-name field-name val)
101 (serialize-string field-name val))
103 (define (serialize-boolean field-name val)
104 (serialize-string field-name (if val "yes" "no")))
106 (define (non-negative-integer? val)
107 (and (exact-integer? val) (not (negative? val))))
108 (define (serialize-non-negative-integer field-name val)
109 (serialize-field field-name val))
111 (define-syntax define-enumerated-field-type
113 (define (id-append ctx . parts)
114 (datum->syntax ctx (apply symbol-append (map syntax->datum parts))))
116 ((_ name (option ...))
118 (define (#,(id-append #'name #'name #'?) x)
119 (memq x '(option ...)))
120 (define (#,(id-append #'name #'serialize- #'name) field-name val)
121 (serialize-field field-name val)))))))
123 (define-enumerated-field-type access-log-level
124 (config actions all))
125 (define-enumerated-field-type browse-local-protocols
127 (define-enumerated-field-type default-auth-type
129 (define-enumerated-field-type default-encryption
130 (Never IfRequested Required))
131 (define-enumerated-field-type error-policy
132 (abort-job retry-job retry-this-job stop-printer))
133 (define-enumerated-field-type log-level
134 (none emerg alert crit error warn notice info debug debug2))
135 (define-enumerated-field-type log-time-format
137 (define-enumerated-field-type server-tokens
138 (None ProductOnly Major Minor Minimal OS Full))
139 (define-enumerated-field-type method
140 (DELETE GET HEAD OPTIONS POST PUT TRACE))
141 (define-enumerated-field-type sandboxing
144 (define (method-list? val)
145 (and (list? val) (and-map method? val)))
146 (define (serialize-method-list field-name val)
147 (serialize-field field-name (string-join (map symbol->string val) " ")))
149 (define (host-name-lookups? val)
150 (memq val '(#f #t 'double)))
151 (define (serialize-host-name-lookups field-name val)
152 (serialize-field field-name
153 (match val (#f "No") (#t "Yes") ('double "Double"))))
155 (define (host-name-list-or-*? x)
157 (and (list? x) (and-map string? x))))
158 (define (serialize-host-name-list-or-* field-name val)
159 (serialize-field field-name (match val
161 (names (string-join names " ")))))
163 (define (boolean-or-non-negative-integer? x)
164 (or (boolean? x) (non-negative-integer? x)))
165 (define (serialize-boolean-or-non-negative-integer field-name x)
167 (serialize-boolean field-name x)
168 (serialize-non-negative-integer field-name x)))
170 (define (ssl-options? x)
172 (and-map (lambda (elt) (memq elt '(AllowRC4 AllowSSL3))) x)))
173 (define (serialize-ssl-options field-name val)
174 (serialize-field field-name
177 (opts (string-join (map symbol->string opts) " ")))))
179 (define (serialize-access-control x)
182 (define (serialize-access-control-list field-name val)
183 (for-each serialize-access-control val))
184 (define (access-control-list? val)
185 (and (list? val) (and-map string? val)))
187 (define-configuration operation-access-control
189 (space-separated-symbol-list '())
190 "IPP operations to which this access control applies.")
192 (access-control-list '())
193 "Access control directives, as a list of strings. Each string should be one directive, such as \"Order allow,deny\"."))
195 (define-configuration method-access-control
198 "If @code{#t}, apply access controls to all methods except the listed
199 methods. Otherwise apply to only the listed methods.")
202 "Methods to which this access control applies.")
204 (access-control-list '())
205 "Access control directives, as a list of strings. Each string should be one directive, such as \"Order allow,deny\"."))
207 (define (serialize-operation-access-control x)
208 (format #t "<Limit ~a>\n"
209 (string-join (map symbol->string
210 (operation-access-control-operations x)) " "))
211 (serialize-configuration
213 (filter (lambda (field)
214 (not (eq? (configuration-field-name field) 'operations)))
215 operation-access-control-fields))
216 (format #t "</Limit>\n"))
218 (define (serialize-method-access-control x)
219 (let ((limit (if (method-access-control-reverse? x) "LimitExcept" "Limit")))
220 (format #t "<~a ~a>\n" limit
221 (string-join (map symbol->string
222 (method-access-control-methods x)) " "))
223 (serialize-configuration
225 (filter (lambda (field)
226 (case (configuration-field-name field)
227 ((reverse? methods) #f)
229 method-access-control-fields))
230 (format #t "</~a>\n" limit)))
232 (define (operation-access-control-list? val)
233 (and (list? val) (and-map operation-access-control? val)))
234 (define (serialize-operation-access-control-list field-name val)
235 (for-each serialize-operation-access-control val))
237 (define (method-access-control-list? val)
238 (and (list? val) (and-map method-access-control? val)))
239 (define (serialize-method-access-control-list field-name val)
240 (for-each serialize-method-access-control val))
242 (define-configuration location-access-control
244 (file-name (configuration-missing-field 'location-access-control 'path))
245 "Specifies the URI path to which the access control applies.")
247 (access-control-list '())
248 "Access controls for all access to this path, in the same format as the
249 @code{access-controls} of @code{operation-access-control}.")
250 (method-access-controls
251 (method-access-control-list '())
252 "Access controls for method-specific access to this path."))
254 (define (serialize-location-access-control x)
255 (format #t "<Location ~a>\n" (location-access-control-path x))
256 (serialize-configuration
258 (filter (lambda (field)
259 (not (eq? (configuration-field-name field) 'path)))
260 location-access-control-fields))
261 (format #t "</Location>\n"))
263 (define (location-access-control-list? val)
264 (and (list? val) (and-map location-access-control? val)))
265 (define (serialize-location-access-control-list field-name val)
266 (for-each serialize-location-access-control val))
268 (define-configuration policy-configuration
270 (string (configuration-missing-field 'policy-configuration 'name))
271 "Name of the policy.")
273 (string "@OWNER @SYSTEM")
274 "Specifies an access list for a job's private values. @code{@@ACL} maps to
275 the printer's requesting-user-name-allowed or requesting-user-name-denied
276 values. @code{@@OWNER} maps to the job's owner. @code{@@SYSTEM} maps to the
277 groups listed for the @code{system-group} field of the @code{files-config}
278 configuration, which is reified into the @code{cups-files.conf(5)} file.
279 Other possible elements of the access list include specific user names, and
280 @code{@@@var{group}} to indicate members of a specific group. The access list
281 may also be simply @code{all} or @code{default}.")
283 (string (string-join '("job-name" "job-originating-host-name"
284 "job-originating-user-name" "phone")))
285 "Specifies the list of job values to make private, or @code{all},
286 @code{default}, or @code{none}.")
288 (subscription-private-access
289 (string "@OWNER @SYSTEM")
290 "Specifies an access list for a subscription's private values.
291 @code{@@ACL} maps to the printer's requesting-user-name-allowed or
292 requesting-user-name-denied values. @code{@@OWNER} maps to the job's owner.
293 @code{@@SYSTEM} maps to the groups listed for the @code{system-group} field of
294 the @code{files-config} configuration, which is reified into the
295 @code{cups-files.conf(5)} file. Other possible elements of the access list
296 include specific user names, and @code{@@@var{group}} to indicate members of a
297 specific group. The access list may also be simply @code{all} or
299 (subscription-private-values
300 (string (string-join '("notify-events" "notify-pull-method"
301 "notify-recipient-uri" "notify-subscriber-user-name"
304 "Specifies the list of job values to make private, or @code{all},
305 @code{default}, or @code{none}.")
308 (operation-access-control-list '())
309 "Access control by IPP operation."))
311 (define (serialize-policy-configuration x)
312 (format #t "<Policy ~a>\n" (policy-configuration-name x))
313 (serialize-configuration
315 (filter (lambda (field)
316 (not (eq? (configuration-field-name field) 'name)))
317 policy-configuration-fields))
318 (format #t "</Policy>\n"))
320 (define (policy-configuration-list? x)
321 (and (list? x) (and-map policy-configuration? x)))
322 (define (serialize-policy-configuration-list field-name x)
323 (for-each serialize-policy-configuration x))
325 (define (log-location? x)
329 (define (serialize-log-location field-name x)
331 (serialize-file-name field-name x)
332 (serialize-field field-name x)))
334 (define-configuration files-configuration
336 (log-location "/var/log/cups/access_log")
337 "Defines the access log filename. Specifying a blank filename disables
338 access log generation. The value @code{stderr} causes log entries to be sent
339 to the standard error file when the scheduler is running in the foreground, or
340 to the system log daemon when run in the background. The value @code{syslog}
341 causes log entries to be sent to the system log daemon. The server name may
342 be included in filenames using the string @code{%s}, as in
343 @code{/var/log/cups/%s-access_log}.")
345 (file-name "/var/cache/cups")
346 "Where CUPS should cache data.")
349 "Specifies the permissions for all configuration files that the scheduler
352 Note that the permissions for the printers.conf file are currently masked to
353 only allow access from the scheduler user (typically root). This is done
354 because printer device URIs sometimes contain sensitive authentication
355 information that should not be generally known on the system. There is no way
356 to disable this security feature.")
357 ;; Not specifying data-dir and server-bin options as we handle these
358 ;; manually. For document-root, the CUPS package has that path
361 (log-location "/var/log/cups/error_log")
362 "Defines the error log filename. Specifying a blank filename disables
363 access log generation. The value @code{stderr} causes log entries to be sent
364 to the standard error file when the scheduler is running in the foreground, or
365 to the system log daemon when run in the background. The value @code{syslog}
366 causes log entries to be sent to the system log daemon. The server name may
367 be included in filenames using the string @code{%s}, as in
368 @code{/var/log/cups/%s-error_log}.")
370 (string "all -browse")
371 "Specifies which errors are fatal, causing the scheduler to exit. The kind
377 All of the errors below are fatal.
379 Browsing initialization errors are fatal, for example failed connections to
382 Configuration file syntax errors are fatal.
384 Listen or Port errors are fatal, except for IPv6 failures on the loopback or
385 @code{any} addresses.
387 Log file creation or write errors are fatal.
389 Bad startup file permissions are fatal, for example shared TLS certificate and
390 key files with world-read permissions.
394 "Specifies whether the file pseudo-device can be used for new printer
395 queues. The URI @url{file:///dev/null} is always allowed.")
398 "Specifies the group name or ID that will be used when executing external
402 "Specifies the permissions for all log files that the scheduler writes.")
404 (log-location "/var/log/cups/page_log")
405 "Defines the page log filename. Specifying a blank filename disables
406 access log generation. The value @code{stderr} causes log entries to be sent
407 to the standard error file when the scheduler is running in the foreground, or
408 to the system log daemon when run in the background. The value @code{syslog}
409 causes log entries to be sent to the system log daemon. The server name may
410 be included in filenames using the string @code{%s}, as in
411 @code{/var/log/cups/%s-page_log}.")
414 "Specifies the username that is associated with unauthenticated accesses by
415 clients claiming to be the root user. The default is @code{remroot}.")
417 (file-name "/var/spool/cups")
418 "Specifies the directory that contains print jobs and other HTTP request
422 "Specifies the level of security sandboxing that is applied to print
423 filters, backends, and other child processes of the scheduler; either
424 @code{relaxed} or @code{strict}. This directive is currently only
425 used/supported on macOS.")
427 (file-name "/etc/cups/ssl")
428 "Specifies the location of TLS certificates and private keys. CUPS will
429 look for public and private keys in this directory: a @code{.crt} files for
430 PEM-encoded certificates and corresponding @code{.key} files for PEM-encoded
433 (file-name "/etc/cups")
434 "Specifies the directory containing the server configuration files.")
437 "Specifies whether the scheduler calls fsync(2) after writing configuration
440 (space-separated-string-list '("lpadmin" "wheel" "root"))
441 "Specifies the group(s) to use for @code{@@SYSTEM} group authentication.")
443 (file-name "/var/spool/cups/tmp")
444 "Specifies the directory where temporary files are stored.")
447 "Specifies the user name or ID that is used when running external
450 (define (serialize-files-configuration field-name val)
453 (define (environment-variables? vars)
454 (space-separated-string-list? vars))
455 (define (serialize-environment-variables field-name vars)
457 (serialize-space-separated-string-list field-name vars)))
459 (define (package-list? val)
460 (and (list? val) (and-map package? val)))
461 (define (serialize-package-list field-name val)
464 (define-configuration cups-configuration
469 (package-list (list cups-filters))
470 "Drivers and other extensions to the CUPS package.")
472 (files-configuration (files-configuration))
473 "Configuration of where to write logs, what directories to use for print
474 spools, and related privileged configuration parameters.")
476 (access-log-level 'actions)
477 "Specifies the logging level for the AccessLog file. The @code{config}
478 level logs when printers and classes are added, deleted, or modified and when
479 configuration files are accessed or updated. The @code{actions} level logs
480 when print jobs are submitted, held, released, modified, or canceled, and any
481 of the conditions for @code{config}. The @code{all} level logs all
485 "Specifies whether to purge job history data automatically when it is no
486 longer required for quotas.")
487 (browse-local-protocols
488 (browse-local-protocols 'dnssd)
489 "Specifies which protocols to use for local printer sharing.")
492 "Specifies whether the CUPS web interface is advertised.")
495 "Specifies whether shared printers are advertised.")
498 "Specifies the security classification of the server.
499 Any valid banner name can be used, including \"classified\", \"confidential\",
500 \"secret\", \"topsecret\", and \"unclassified\", or the banner can be omitted
501 to disable secure printing functions.")
504 "Specifies whether users may override the classification (cover page) of
505 individual print jobs using the @code{job-sheets} option.")
507 (default-auth-type 'Basic)
508 "Specifies the default type of authentication to use.")
510 (default-encryption 'Required)
511 "Specifies whether encryption will be used for authenticated requests.")
514 "Specifies the default language to use for text and web content.")
517 "Specifies the default paper size for new print queues. @samp{\"Auto\"}
518 uses a locale-specific default, while @samp{\"None\"} specifies there is no
519 default paper size. Specific size names are typically @samp{\"Letter\"} or
523 "Specifies the default access policy to use.")
526 "Specifies whether local printers are shared by default.")
527 (dirty-clean-interval
528 (non-negative-integer 30)
529 "Specifies the delay for updating of configuration and state files, in
530 seconds. A value of 0 causes the update to happen as soon as possible,
531 typically within a few milliseconds.")
533 (error-policy 'stop-printer)
534 "Specifies what to do when an error occurs. Possible values are
535 @code{abort-job}, which will discard the failed print job; @code{retry-job},
536 which will retry the job at a later time; @code{retry-this-job}, which retries
537 the failed job immediately; and @code{stop-printer}, which stops the
540 (non-negative-integer 0)
541 "Specifies the maximum cost of filters that are run concurrently, which can
542 be used to minimize disk, memory, and CPU resource problems. A limit of 0
543 disables filter limiting. An average print to a non-PostScript printer needs
544 a filter limit of about 200. A PostScript printer needs about half
545 that (100). Setting the limit below these thresholds will effectively limit
546 the scheduler to printing a single job at any time.")
548 (non-negative-integer 0)
549 "Specifies the scheduling priority of filters that are run to print a job.
550 The nice value ranges from 0, the highest priority, to 19, the lowest
552 ;; Add this option if the package is built with Kerberos support.
555 ;; "Specifies the service name when using Kerberos authentication.")
557 (host-name-lookups #f)
558 "Specifies whether to do reverse lookups on connecting clients.
559 The @code{double} setting causes @code{cupsd} to verify that the hostname
560 resolved from the address matches one of the addresses returned for that
561 hostname. Double lookups also prevent clients with unregistered addresses
562 from connecting to your server. Only set this option to @code{#t} or
563 @code{double} if absolutely required.")
564 ;; Add this option if the package is built with launchd/systemd support.
565 ;; (idle-exit-timeout
566 ;; (non-negative-integer 60)
567 ;; "Specifies the length of time to wait before shutting down due to
568 ;; inactivity. Note: Only applicable when @code{cupsd} is run on-demand
569 ;; (e.g., with @code{-l}).")
571 (non-negative-integer 30)
572 "Specifies the number of seconds to wait before killing the filters and
573 backend associated with a canceled or held job.")
575 (non-negative-integer 30)
576 "Specifies the interval between retries of jobs in seconds. This is
577 typically used for fax queues but can also be used with normal print queues
578 whose error policy is @code{retry-job} or @code{retry-current-job}.")
580 (non-negative-integer 5)
581 "Specifies the number of retries that are done for jobs. This is typically
582 used for fax queues but can also be used with normal print queues whose error
583 policy is @code{retry-job} or @code{retry-current-job}.")
586 "Specifies whether to support HTTP keep-alive connections.")
588 (non-negative-integer 30)
589 "Specifies how long an idle client connection remains open, in seconds.")
591 (non-negative-integer 0)
592 "Specifies the maximum size of print files, IPP requests, and HTML form
593 data. A limit of 0 disables the limit check.")
595 (multiline-string-list '("localhost:631" "/var/run/cups/cups.sock"))
596 "Listens on the specified interfaces for connections. Valid values are of
597 the form @var{address}:@var{port}, where @var{address} is either an IPv6
598 address enclosed in brackets, an IPv4 address, or @code{*} to indicate all
599 addresses. Values can also be file names of local UNIX domain sockets. The
600 Listen directive is similar to the Port directive but allows you to restrict
601 access to specific interfaces or networks.")
603 (non-negative-integer 128)
604 "Specifies the number of pending connections that will be allowed. This
605 normally only affects very busy servers that have reached the MaxClients
606 limit, but can also be triggered by large numbers of simultaneous connections.
607 When the limit is reached, the operating system will refuse additional
608 connections until the scheduler can accept the pending ones.")
609 (location-access-controls
610 (location-access-control-list
611 (list (location-access-control
613 (access-controls '("Order allow,deny"
615 (location-access-control
617 (access-controls '("Order allow,deny"
619 (location-access-control
621 (access-controls '("Order allow,deny"
623 "Require user @SYSTEM"
624 "Allow localhost")))))
625 "Specifies a set of additional access controls.")
627 (non-negative-integer 100)
628 "Specifies the number of debugging messages that are retained for logging
629 if an error occurs in a print job. Debug messages are logged regardless of
630 the LogLevel setting.")
633 "Specifies the level of logging for the ErrorLog file. The value
634 @code{none} stops all logging while @code{debug2} logs everything.")
636 (log-time-format 'standard)
637 "Specifies the format of the date and time in the log files. The value
638 @code{standard} logs whole seconds while @code{usecs} logs microseconds.")
640 (non-negative-integer 100)
641 "Specifies the maximum number of simultaneous clients that are allowed by
643 (max-clients-per-host
644 (non-negative-integer 100)
645 "Specifies the maximum number of simultaneous clients that are allowed from
648 (non-negative-integer 9999)
649 "Specifies the maximum number of copies that a user can print of each
652 (non-negative-integer 0)
653 "Specifies the maximum time a job may remain in the @code{indefinite} hold
654 state before it is canceled. A value of 0 disables cancellation of held
657 (non-negative-integer 500)
658 "Specifies the maximum number of simultaneous jobs that are allowed. Set
659 to 0 to allow an unlimited number of jobs.")
660 (max-jobs-per-printer
661 (non-negative-integer 0)
662 "Specifies the maximum number of simultaneous jobs that are allowed per
663 printer. A value of 0 allows up to MaxJobs jobs per printer.")
665 (non-negative-integer 0)
666 "Specifies the maximum number of simultaneous jobs that are allowed per
667 user. A value of 0 allows up to MaxJobs jobs per user.")
669 (non-negative-integer 10800)
670 "Specifies the maximum time a job may take to print before it is canceled,
671 in seconds. Set to 0 to disable cancellation of \"stuck\" jobs.")
673 (non-negative-integer 1048576)
674 "Specifies the maximum size of the log files before they are rotated, in
675 bytes. The value 0 disables log rotation.")
676 (multiple-operation-timeout
677 (non-negative-integer 300)
678 "Specifies the maximum amount of time to allow between files in a multiple
679 file print job, in seconds.")
682 "Specifies the format of PageLog lines. Sequences beginning with
683 percent (@samp{%}) characters are replaced with the corresponding information,
684 while all other characters are copied literally. The following percent
685 sequences are recognized:
689 insert a single percent character
691 insert the value of the specified IPP attribute
693 insert the number of copies for the current page
695 insert the current page number
697 insert the current date and time in common log format
701 insert the printer name
706 A value of the empty string disables page logging. The string @code{%p %u %j
707 %T %P %C %@{job-billing@} %@{job-originating-host-name@} %@{job-name@}
708 %@{media@} %@{sides@}} creates a page log with the standard items.")
709 (environment-variables
710 (environment-variables '())
711 "Passes the specified environment variable(s) to child processes; a list of
714 (policy-configuration-list
715 (list (policy-configuration
719 (operation-access-control
722 Send-URI Hold-Job Release-Job Restart-Job Purge-Jobs
723 Cancel-Job Close-Job Cancel-My-Jobs Set-Job-Attributes
724 Create-Job-Subscription Renew-Subscription
725 Cancel-Subscription Get-Notifications
726 Reprocess-Job Cancel-Current-Job Suspend-Current-Job
727 Resume-Job CUPS-Move-Job Validate-Job
729 (access-controls '("Require user @OWNER @SYSTEM"
730 "Order deny,allow")))
731 (operation-access-control
735 Resume-Printer Set-Printer-Attributes Enable-Printer
736 Disable-Printer Pause-Printer-After-Current-Job
737 Hold-New-Jobs Release-Held-New-Jobs Deactivate-Printer
738 Activate-Printer Restart-Printer Shutdown-Printer
739 Startup-Printer Promote-Job Schedule-Job-After
740 CUPS-Authenticate-Job CUPS-Add-Printer
741 CUPS-Delete-Printer CUPS-Add-Class CUPS-Delete-Class
742 CUPS-Accept-Jobs CUPS-Reject-Jobs CUPS-Set-Default))
743 (access-controls '("AuthType Basic"
744 "Require user @SYSTEM"
745 "Order deny,allow")))
746 (operation-access-control
748 (access-controls '("Order deny,allow"))))))))
749 "Specifies named access control policies.")
752 (non-negative-integer 631)
753 "Listens to the specified port number for connections.")
755 (boolean-or-non-negative-integer 86400)
756 "Specifies whether job files (documents) are preserved after a job is
757 printed. If a numeric value is specified, job files are preserved for the
758 indicated number of seconds after printing. Otherwise a boolean value applies
760 (preserve-job-history
761 (boolean-or-non-negative-integer #t)
762 "Specifies whether the job history is preserved after a job is printed.
763 If a numeric value is specified, the job history is preserved for the
764 indicated number of seconds after printing. If @code{#t}, the job history is
765 preserved until the MaxJobs limit is reached.")
767 (non-negative-integer 30)
768 "Specifies the amount of time to wait for job completion before restarting
772 "Specifies the maximum amount of memory to use when converting documents into bitmaps for a printer.")
774 (string "root@localhost.localdomain")
775 "Specifies the email address of the server administrator.")
777 (host-name-list-or-* '*)
778 "The ServerAlias directive is used for HTTP Host header validation when
779 clients connect to the scheduler from external interfaces. Using the special
780 name @code{*} can expose your system to known browser-based DNS rebinding
781 attacks, even when accessing sites through a firewall. If the auto-discovery
782 of alternate names does not work, we recommend listing each alternate name
783 with a ServerAlias directive instead of using @code{*}.")
786 "Specifies the fully-qualified host name of the server.")
788 (server-tokens 'Minimal)
789 "Specifies what information is included in the Server header of HTTP
790 responses. @code{None} disables the Server header. @code{ProductOnly}
791 reports @code{CUPS}. @code{Major} reports @code{CUPS 2}. @code{Minor}
792 reports @code{CUPS 2.0}. @code{Minimal} reports @code{CUPS 2.0.0}. @code{OS}
793 reports @code{CUPS 2.0.0 (@var{uname})} where @var{uname} is the output of the
794 @code{uname} command. @code{Full} reports @code{CUPS 2.0.0 (@var{uname})
797 (string "variable value")
798 "Set the specified environment variable to be passed to child processes.")
800 (multiline-string-list '())
801 "Listens on the specified interfaces for encrypted connections. Valid
802 values are of the form @var{address}:@var{port}, where @var{address} is either
803 an IPv6 address enclosed in brackets, an IPv4 address, or @code{*} to indicate
807 "Sets encryption options.
808 By default, CUPS only supports encryption using TLS v1.0 or higher using known
809 secure cipher suites. The @code{AllowRC4} option enables the 128-bit RC4
810 cipher suites, which are required for some older clients that do not implement
811 newer ones. The @code{AllowSSL3} option enables SSL v3.0, which is required
812 for some older clients that do not support TLS v1.0.")
815 (non-negative-integer 631)
816 "Listens on the specified port for encrypted connections.")
819 "Specifies whether the scheduler requires clients to strictly adhere to the
820 IPP specifications.")
822 (non-negative-integer 300)
823 "Specifies the HTTP request timeout, in seconds.")
826 "Specifies whether the web interface is enabled."))
828 (define-configuration opaque-cups-configuration
834 "Drivers and other extensions to the CUPS package.")
836 (string (configuration-missing-field 'opaque-cups-configuration
838 "The contents of the @code{cupsd.conf} to use.")
840 (string (configuration-missing-field 'opaque-cups-configuration
842 "The contents of the @code{cups-files.conf} to use."))
844 (define %cups-activation
846 (with-imported-modules '((guix build utils))
848 (use-modules (guix build utils))
849 (define (mkdir-p/perms directory owner perms)
851 (chown "/var/run/cups" (passwd:uid owner) (passwd:gid owner))
852 (chmod directory perms))
853 (define (build-subject parameters)
856 (let ((k (car pair)) (v (cdr pair)))
857 (define (escape-char str chr)
858 (string-join (string-split str chr) (string #\\ chr)))
859 (string-append "/" k "="
860 (escape-char (escape-char v #\=) #\/))))
861 (filter (lambda (pair) (cdr pair)) parameters))))
862 (define* (create-self-signed-certificate-if-absent
863 #:key private-key public-key (owner (getpwnam "root"))
864 (common-name (gethostname))
865 (organization-name "Guix")
866 (organization-unit-name "Default Self-Signed Certificate")
867 (subject-parameters `(("CN" . ,common-name)
868 ("O" . ,organization-name)
869 ("OU" . ,organization-unit-name)))
870 (subject (build-subject subject-parameters)))
871 ;; Note that by default, OpenSSL outputs keys in PEM format. This
873 (unless (file-exists? private-key)
875 ((zero? (system* (string-append #$openssl "/bin/openssl")
876 "genrsa" "-out" private-key "2048"))
877 (chown private-key (passwd:uid owner) (passwd:gid owner))
878 (chmod private-key #o400))
880 (format (current-error-port)
881 "Failed to create private key at ~a.\n" private-key))))
882 (unless (file-exists? public-key)
884 ((zero? (system* (string-append #$openssl "/bin/openssl")
885 "req" "-new" "-x509" "-key" private-key
886 "-out" public-key "-days" "3650"
887 "-batch" "-subj" subject))
888 (chown public-key (passwd:uid owner) (passwd:gid owner))
889 (chmod public-key #o444))
891 (format (current-error-port)
892 "Failed to create public key at ~a.\n" public-key)))))
893 (let ((user (getpwnam "lp")))
894 (mkdir-p/perms "/var/run/cups" user #o755)
895 (mkdir-p/perms "/var/spool/cups" user #o755)
896 (mkdir-p/perms "/var/spool/cups/tmp" user #o755)
897 (mkdir-p/perms "/var/log/cups" user #o755)
898 (mkdir-p/perms "/etc/cups" user #o755)
899 (mkdir-p/perms "/etc/cups/ssl" user #o700)
900 ;; This certificate is used for HTTPS connections to the CUPS web
902 (create-self-signed-certificate-if-absent
903 #:private-key "/etc/cups/ssl/localhost.key"
904 #:public-key "/etc/cups/ssl/localhost.crt"
905 #:owner (getpwnam "root")
906 #:common-name (format #f "CUPS service on ~a" (gethostname)))))))
908 (define (union-directory name packages paths)
911 (with-imported-modules '((guix build utils))
913 (use-modules (guix build utils)
922 (let* ((tail (substring src (string-length package)))
923 (dst (string-append #$output tail)))
924 (mkdir-p (dirname dst))
925 ;; CUPS currently symlinks in some data from cups-filters
926 ;; to its output dir. Probably we should stop doing this
927 ;; and instead rely only on the CUPS service to union the
928 ;; relevant set of CUPS packages.
929 (if (file-exists? dst)
930 (format (current-error-port) "warning: ~a exists\n" dst)
932 (find-files (string-append package path) #:stat stat)))
937 (define (cups-server-bin-directory extensions)
938 "Return the CUPS ServerBin directory, containing binaries for CUPS and all
939 extensions that it uses."
940 (union-directory "cups-server-bin" extensions
942 '("/lib/cups" "/share/ppd" "/share/cups")))
944 (define (cups-shepherd-service config)
945 "Return a list of <shepherd-service> for CONFIG."
946 (let* ((cupsd.conf-str
948 ((opaque-cups-configuration? config)
949 (opaque-cups-configuration-cupsd.conf config))
951 (with-output-to-string
953 (serialize-configuration config
954 cups-configuration-fields))))))
957 ((opaque-cups-configuration? config)
958 (opaque-cups-configuration-cups-files.conf config))
960 (with-output-to-string
962 (serialize-configuration
963 (cups-configuration-files-configuration config)
964 files-configuration-fields))))))
965 (cups (if (opaque-cups-configuration? config)
966 (opaque-cups-configuration-cups config)
967 (cups-configuration-cups config)))
969 (cups-server-bin-directory
972 ((opaque-cups-configuration? config)
973 (opaque-cups-configuration-extensions config))
975 (cups-configuration-extensions config))))))
976 ;;"SetEnv PATH " server-bin "/bin" "\n"
978 (plain-file "cupsd.conf" cupsd.conf-str))
983 "CacheDir /var/cache/cups\n"
984 "StateDir /var/run/cups\n"
985 "DataDir " server-bin "/share/cups" "\n"
986 "ServerBin " server-bin "/lib/cups" "\n")))
987 (list (shepherd-service
988 (documentation "Run the CUPS print server.")
990 (requirement '(networking))
991 (start #~(make-forkexec-constructor
992 (list (string-append #$cups "/sbin/cupsd")
993 "-f" "-c" #$cupsd.conf "-s" #$cups-files.conf)))
994 (stop #~(make-kill-destructor))))))
996 (define cups-service-type
997 (service-type (name 'cups)
999 (list (service-extension shepherd-root-service-type
1000 cups-shepherd-service)
1001 (service-extension activation-service-type
1002 (const %cups-activation))
1003 (service-extension account-service-type
1004 (const %cups-accounts))))
1006 ;; Extensions consist of lists of packages (representing CUPS
1007 ;; drivers, etc) that we just concatenate.
1010 ;; Add extension packages by augmenting the cups-configuration
1011 ;; 'extensions' field.
1013 (lambda (config extensions)
1015 ((cups-configuration? config)
1019 (append (cups-configuration-extensions config)
1022 (opaque-cups-configuration
1025 (append (opaque-cups-configuration-extensions config)
1028 (default-value (cups-configuration))
1030 "Run the CUPS print server.")))
1032 ;; A little helper to make it easier to document all those fields.
1033 (define (generate-cups-documentation)
1034 (generate-documentation
1035 `((cups-configuration
1036 ,cups-configuration-fields
1037 (files-configuration files-configuration)
1038 (policies policy-configuration)
1039 (location-access-controls location-access-controls))
1040 (files-configuration ,files-configuration-fields)
1041 (policy-configuration
1042 ,policy-configuration-fields
1043 (operation-access-controls operation-access-controls))
1044 (location-access-controls
1045 ,location-access-control-fields
1046 (method-access-controls method-access-controls))
1047 (operation-access-controls ,operation-access-control-fields)
1048 (method-access-controls ,method-access-control-fields))
1049 'cups-configuration))