time-machine.scm 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2019 Konrad Hinsen <konrad.hinsen@fastmail.net>
  3. ;;; Copyright © 2019, 2020 Ludovic Courtès <ludo@gnu.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. (define-module (guix scripts time-machine)
  20. #:use-module (guix ui)
  21. #:use-module (guix scripts)
  22. #:use-module (guix inferior)
  23. #:use-module (guix channels)
  24. #:use-module (guix store)
  25. #:use-module (guix status)
  26. #:use-module ((guix git)
  27. #:select (with-git-error-handling))
  28. #:use-module ((guix utils)
  29. #:select (%current-system))
  30. #:use-module ((guix scripts pull)
  31. #:select (channel-list))
  32. #:use-module ((guix scripts build)
  33. #:select (%standard-build-options
  34. show-build-options-help
  35. set-build-options-from-command-line))
  36. #:use-module (ice-9 match)
  37. #:use-module (srfi srfi-1)
  38. #:use-module (srfi srfi-11)
  39. #:use-module (srfi srfi-26)
  40. #:use-module (srfi srfi-37)
  41. #:export (guix-time-machine))
  42. ;;;
  43. ;;; Command-line options.
  44. ;;;
  45. (define (show-help)
  46. (display (G_ "Usage: guix time-machine [OPTION] -- COMMAND ARGS...
  47. Execute COMMAND ARGS... in an older version of Guix.\n"))
  48. (display (G_ "
  49. -C, --channels=FILE deploy the channels defined in FILE"))
  50. (display (G_ "
  51. --url=URL use the Git repository at URL"))
  52. (display (G_ "
  53. --commit=COMMIT use the specified COMMIT"))
  54. (display (G_ "
  55. --branch=BRANCH use the tip of the specified BRANCH"))
  56. (display (G_ "
  57. --disable-authentication
  58. disable channel authentication"))
  59. (newline)
  60. (show-build-options-help)
  61. (newline)
  62. (display (G_ "
  63. -h, --help display this help and exit"))
  64. (display (G_ "
  65. -V, --version display version information and exit"))
  66. (newline)
  67. (show-bug-report-information))
  68. (define %options
  69. ;; Specifications of the command-line options.
  70. (cons* (option '(#\C "channels") #t #f
  71. (lambda (opt name arg result)
  72. (alist-cons 'channel-file arg result)))
  73. (option '("url") #t #f
  74. (lambda (opt name arg result)
  75. (alist-cons 'repository-url arg
  76. (alist-delete 'repository-url result))))
  77. (option '("commit") #t #f
  78. (lambda (opt name arg result)
  79. (alist-cons 'ref `(commit . ,arg) result)))
  80. (option '("branch") #t #f
  81. (lambda (opt name arg result)
  82. (alist-cons 'ref `(branch . ,arg) result)))
  83. (option '("disable-authentication") #f #f
  84. (lambda (opt name arg result)
  85. (alist-cons 'authenticate-channels? #f result)))
  86. (option '(#\h "help") #f #f
  87. (lambda args
  88. (show-help)
  89. (exit 0)))
  90. (option '(#\V "version") #f #f
  91. (lambda args
  92. (show-version-and-exit "guix time-machine")))
  93. %standard-build-options))
  94. (define %default-options
  95. ;; Alist of default option values.
  96. `((system . ,(%current-system))
  97. (substitutes? . #t)
  98. (offload? . #t)
  99. (print-build-trace? . #t)
  100. (print-extended-build-trace? . #t)
  101. (multiplexed-build-output? . #t)
  102. (authenticate-channels? . #t)
  103. (graft? . #t)
  104. (debug . 0)
  105. (verbosity . 1)))
  106. (define (parse-args args)
  107. "Parse the list of command line arguments ARGS."
  108. ;; The '--' token is used to separate the command to run from the rest of
  109. ;; the operands.
  110. (let-values (((args command) (break (cut string=? "--" <>) args)))
  111. (let ((opts (parse-command-line args %options
  112. (list %default-options))))
  113. (match command
  114. (() opts)
  115. (("--") opts)
  116. (("--" command ...) (alist-cons 'exec command opts))))))
  117. ;;;
  118. ;;; Entry point.
  119. ;;;
  120. (define-command (guix-time-machine . args)
  121. (synopsis "run commands from a different revision")
  122. (with-error-handling
  123. (with-git-error-handling
  124. (let* ((opts (parse-args args))
  125. (channels (channel-list opts))
  126. (command-line (assoc-ref opts 'exec))
  127. (authenticate? (assoc-ref opts 'authenticate-channels?)))
  128. (when command-line
  129. (let* ((directory
  130. (with-store store
  131. (with-status-verbosity (assoc-ref opts 'verbosity)
  132. (set-build-options-from-command-line store opts)
  133. (cached-channel-instance store channels
  134. #:authenticate? authenticate?))))
  135. (executable (string-append directory "/bin/guix")))
  136. (apply execl (cons* executable executable command-line))))))))