unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
blob 5f6733cf9ff4a9ce5f6e05463594ffc59c568f91 10105 bytes (raw)
name: guix/scripts/pull.scm 	 # note: path name is non-authoritative(*)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
 
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2013, 2014, 2015, 2017 Ludovic Courtès <ludo@gnu.org>
;;; Copyright © 2017 Marius Bakke <mbakke@fastmail.com>
;;;
;;; This file is part of GNU Guix.
;;;
;;; GNU Guix is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; GNU Guix is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.

(define-module (guix scripts pull)
  #:use-module (guix ui)
  #:use-module (guix utils)
  #:use-module (guix scripts)
  #:use-module (guix store)
  #:use-module (guix config)
  #:use-module (guix packages)
  #:use-module (guix derivations)
  #:use-module (guix download)
  #:use-module (guix gexp)
  #:use-module (guix monads)
  #:use-module (guix git)
  #:use-module (git)
  #:use-module (guix scripts build)
  #:use-module ((guix build utils)
                #:select (with-directory-excursion delete-file-recursively))
  #:use-module ((guix build download)
                #:select (%x509-certificate-directory))
  #:use-module (gnu packages base)
  #:use-module (gnu packages guile)
  #:use-module ((gnu packages bootstrap)
                #:select (%bootstrap-guile))
  #:use-module ((gnu packages certs) #:select (le-certs))
  #:use-module (gnu packages compression)
  #:use-module (gnu packages gnupg)
  #:use-module (srfi srfi-1)
  #:use-module (srfi srfi-11)
  #:use-module (srfi srfi-34)
  #:use-module (srfi srfi-35)
  #:use-module (srfi srfi-37)
  #:use-module (ice-9 ftw)
  #:use-module (ice-9 match)
  #:export (guix-pull))

(define %repository-url
  "https://git.savannah.gnu.org/git/guix.git")

\f
;;;
;;; Command-line options.
;;;

(define %default-options
  ;; Alist of default option values.
  `((repository-url . ,%repository-url)
    (ref . (branch . "origin/master"))
    (system . ,(%current-system))
    (substitutes? . #t)
    (graft? . #t)
    (max-silent-time . 3600)
    (verbosity . 0)))

(define (show-help)
  (display (G_ "Usage: guix pull [OPTION]...
Download and deploy the latest version of Guix.\n"))
  (display (G_ "
      --verbose          produce verbose output"))
  (display (G_ "
      --url=URL          download from the Git repository at URL"))
  (display (G_ "
      --commit=COMMIT    download the specified COMMIT"))
  (display (G_ "
      --branch=BRANCH    download the tip of the specified BRANCH"))
  (display (G_ "
      --bootstrap        use the bootstrap Guile to build the new Guix"))
  (newline)
  (show-build-options-help)
  (display (G_ "
  -h, --help             display this help and exit"))
  (display (G_ "
  -V, --version          display version information and exit"))
  (newline)
  (show-bug-report-information))

(define %options
  ;; Specifications of the command-line options.
  (cons* (option '("verbose") #f #f
                 (lambda (opt name arg result)
                   (alist-cons 'verbose? #t result)))
         (option '("url") #t #f
                 (lambda (opt name arg result)
                   (alist-cons 'repository-url arg
                               (alist-delete 'repository-url result))))
         (option '("commit") #t #f
                 (lambda (opt name arg result)
                   (alist-cons 'ref `(commit . ,arg) result)))
         (option '("branch") #t #f
                 (lambda (opt name arg result)
                   (alist-cons 'ref `(branch . ,(string-append "origin/" arg))
                               result)))
         (option '(#\n "dry-run") #f #f
                 (lambda (opt name arg result)
                   (alist-cons 'dry-run? #t (alist-cons 'graft? #f result))))
         (option '("bootstrap") #f #f
                 (lambda (opt name arg result)
                   (alist-cons 'bootstrap? #t result)))

         (option '(#\h "help") #f #f
                 (lambda args
                   (show-help)
                   (exit 0)))
         (option '(#\V "version") #f #f
                 (lambda args
                   (show-version-and-exit "guix pull")))

         %standard-build-options))

(define what-to-build
  (store-lift show-what-to-build))
(define indirect-root-added
  (store-lift add-indirect-root))

(define %self-build-file
  ;; The file containing code to build Guix.  This serves the same purpose as
  ;; a makefile, and, similarly, is intended to always keep this name.
  "build-aux/build-self.scm")

(define* (build-from-source source #:key verbose?)
  "Return a derivation to build Guix from SOURCE, using the self-build script
contained therein."
  ;; Running the self-build script makes it easier to update the build
  ;; procedure: the self-build script of the Guix-to-be-installed contains the
  ;; right dependencies, build procedure, etc., which the Guix-in-use may not
  ;; be know.
  (let* ((script (string-append source "/" %self-build-file))
         (build  (primitive-load script)))
    ;; BUILD must be a monadic procedure of at least one argument: the source
    ;; tree.
    (build source #:verbose? verbose?)))

(define* (build-and-install source config-dir
                            #:key verbose?)
  "Build the tool from SOURCE, and install it in CONFIG-DIR."
  (mlet* %store-monad ((source        (build-from-source source
                                                         #:verbose? verbose?))
                       (source-dir -> (derivation->output-path source))
                       (to-do?        (what-to-build (list source)))
                       (built?        (built-derivations (list source))))
    ;; Always update the 'latest' symlink, regardless of whether SOURCE was
    ;; already built or not.
    (if built?
        (mlet* %store-monad
            ((latest -> (string-append config-dir "/latest"))
             (done      (indirect-root-added latest)))
          (if (and (file-exists? latest)
                   (string=? (readlink latest) source-dir))
              (begin
                (display (G_ "Guix already up to date\n"))
                (return #t))
              (begin
                (switch-symlinks latest source-dir)
                (format #t
                        (G_ "updated ~a successfully deployed under `~a'~%")
                        %guix-package-name latest)
                (return #t))))
        (leave (G_ "failed to update Guix, check the build log~%")))))

(define (honor-lets-encrypt-certificates! store)
  "Tell Guile-Git to use the Let's Encrypt certificates."
  (let* ((drv   (package-derivation store le-certs))
         (certs (string-append (derivation->output-path drv)
                               "/etc/ssl/certs")))
    (build-derivations store (list drv))

    ;; In the past Guile-Git would not provide this procedure.
    (if (module-defined? (resolve-interface '(git))
                         'set-tls-certificate-locations!)
        (set-tls-certificate-locations! certs)
        (begin
          ;; In this case we end up using whichever certificates OpenSSL
          ;; chooses to use: $SSL_CERT_FILE, $SSL_CERT_DIR, or /etc/ssl/certs.
          (warning (G_ "cannot enforce use of the Let's Encrypt \
certificates~%"))
          (warning (G_ "please upgrade Guile-Git~%"))))))

(define (report-git-error error)
  "Report the given Guile-Git error."
  ;; Prior to Guile-Git commit b6b2760c2fd6dfaa5c0fedb43eeaff06166b3134,
  ;; errors would be represented by integers.
  (match error
    ((? integer? error)                           ;old Guile-Git
     (leave (G_ "Git error ~a~%") error))
    ((? git-error? error)                         ;new Guile-Git
     (leave (G_ "Git error: ~a~%") (git-error-message error)))))

(define-syntax-rule (with-git-error-handling body ...)
  (catch 'git-error
    (lambda ()
      body ...)
    (lambda (key err)
      (report-git-error err))))

\f
(define (guix-pull . args)
  (define (use-le-certs? url)
    (string-prefix? "https://git.savannah.gnu.org/" url))

  (with-error-handling
    (with-git-error-handling
     (let* ((opts  (parse-command-line args %options
                                       (list %default-options)))
            (url   (assoc-ref opts 'repository-url))
            (ref   (assoc-ref opts 'ref))
            (cache (string-append (cache-directory) "/pull")))
       (unless (assoc-ref opts 'dry-run?)         ;XXX: not very useful
         (with-store store
           (set-build-options-from-command-line store opts)

           ;; For reproducibility, always refer to the LE certificates when we
           ;; know we're talking to Savannah.
           (when (use-le-certs? url)
             (honor-lets-encrypt-certificates! store))

           (format (current-error-port)
                   (G_ "updating from Git repository at '~a'...~%")
                   url)

           (let-values (((checkout commit)
                         (latest-repository-commit store url
                                                   #:ref ref
                                                   #:cache-directory cache)))

             (format (current-error-port)
                     (G_ "building from Git commit ~a...~%")
                     commit)
             (parameterize ((%guile-for-build
                             (package-derivation store
                                                 (if (assoc-ref opts 'bootstrap?)
                                                     %bootstrap-guile
                                                     (canonical-package guile-2.0)))))
               (run-with-store store
                 (build-and-install checkout (config-directory)
                                    #:verbose? (assoc-ref opts 'verbose?)))))))))))

;;; pull.scm ends here

debug log:

solving 5f6733cf9 ...
found 5f6733cf9 in https://yhetil.org/guix-patches/20170728204539.21879-2-ludo@gnu.org/
found 58b87d4df in https://git.savannah.gnu.org/cgit/guix.git
preparing index
index prepared:
100644 58b87d4df4c0eef315eb4d76260687f8c20cb334	guix/scripts/pull.scm

applying [1/1] https://yhetil.org/guix-patches/20170728204539.21879-2-ludo@gnu.org/
diff --git a/guix/scripts/pull.scm b/guix/scripts/pull.scm
index 58b87d4df..5f6733cf9 100644

Checking patch guix/scripts/pull.scm...
Applied patch guix/scripts/pull.scm cleanly.

index at:
100644 5f6733cf9ff4a9ce5f6e05463594ffc59c568f91	guix/scripts/pull.scm

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).