deploy: Do not quote error messages.
[jackhill/guix/guix.git] / guix / scripts / deploy.scm
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2019 David Thompson <davet@gnu.org>
3 ;;; Copyright © 2019 Jakob L. Kreuze <zerodaysfordays@sdf.lonestar.org>
4 ;;;
5 ;;; This file is part of GNU Guix.
6 ;;;
7 ;;; GNU Guix is free software; you can redistribute it and/or modify it
8 ;;; under the terms of the GNU General Public License as published by
9 ;;; the Free Software Foundation; either version 3 of the License, or (at
10 ;;; your option) any later version.
11 ;;;
12 ;;; GNU Guix is distributed in the hope that it will be useful, but
13 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;;; GNU General Public License for more details.
16 ;;;
17 ;;; You should have received a copy of the GNU General Public License
18 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
19
20 (define-module (guix scripts deploy)
21 #:use-module (gnu machine)
22 #:use-module (guix discovery)
23 #:use-module (guix scripts)
24 #:use-module (guix scripts build)
25 #:use-module (guix store)
26 #:use-module (guix ui)
27 #:use-module (guix utils)
28 #:use-module (guix grafts)
29 #:use-module (ice-9 format)
30 #:use-module (srfi srfi-1)
31 #:use-module (srfi srfi-34)
32 #:use-module (srfi srfi-35)
33 #:use-module (srfi srfi-37)
34 #:export (guix-deploy))
35
36 ;;; Commentary:
37 ;;;
38 ;;; This program provides a command-line interface to (gnu machine), allowing
39 ;;; users to perform remote deployments through specification files.
40 ;;;
41 ;;; Code:
42
43 \f
44
45 (define (show-help)
46 (display (G_ "Usage: guix deploy [OPTION] FILE...
47 Perform the deployment specified by FILE.\n"))
48 (show-build-options-help)
49 (newline)
50 (display (G_ "
51 -h, --help display this help and exit"))
52 (display (G_ "
53 -V, --version display version information and exit"))
54 (newline)
55 (show-bug-report-information))
56
57 (define %options
58 (cons* (option '(#\h "help") #f #f
59 (lambda args
60 (show-help)
61 (exit 0)))
62 (option '(#\s "system") #t #f
63 (lambda (opt name arg result)
64 (alist-cons 'system arg
65 (alist-delete 'system result eq?))))
66 %standard-build-options))
67
68 (define %default-options
69 `((substitutes? . #t)
70 (build-hook? . #t)
71 (graft? . #t)
72 (debug . 0)
73 (verbosity . 1)))
74
75 (define (load-source-file file)
76 "Load FILE as a user module."
77 (let* ((guix-path (dirname (search-path %load-path "guix.scm")))
78 (environment-modules (scheme-modules* guix-path "gnu/machine"))
79 (module (make-user-module (append '((gnu) (gnu machine))
80 environment-modules))))
81 (load* file module)))
82
83 (define (guix-deploy . args)
84 (define (handle-argument arg result)
85 (alist-cons 'file arg result))
86 (let* ((opts (parse-command-line args %options (list %default-options)
87 #:argument-handler handle-argument))
88 (file (assq-ref opts 'file))
89 (machines (or (and file (load-source-file file)) '())))
90 (with-store store
91 (set-build-options-from-command-line store opts)
92 (for-each (lambda (machine)
93 (info (G_ "deploying to ~a...~%")
94 (machine-display-name machine))
95 (parameterize ((%graft? (assq-ref opts 'graft?)))
96 (guard (c ((message-condition? c)
97 (report-error (G_ "failed to deploy ~a: ~a~%")
98 (machine-display-name machine)
99 (condition-message c)))
100 ((deploy-error? c)
101 (when (deploy-error-should-roll-back c)
102 (info (G_ "rolling back ~a...~%")
103 (machine-display-name machine))
104 (run-with-store store (roll-back-machine machine)))
105 (apply throw (deploy-error-captured-args c))))
106 (run-with-store store (deploy-machine machine)))))
107 machines))))