| 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 | (define-module (gnu machine)
|
| 30 | #:use-module (gnu system)
|
| 31 | #:use-module (guix derivations)
|
| 32 | #:use-module (guix monads)
|
| 33 | #:use-module (guix records)
|
| 34 | #:use-module (guix store)
|
| 35 | #:use-module ((guix diagnostics) #:select (source-properties->location))
|
| 36 | #:use-module (srfi srfi-35)
|
| 37 | #:export (environment-type
|
| 38 | environment-type?
|
| 39 | environment-type-name
|
| 40 | environment-type-description
|
| 41 | environment-type-location
|
| 42 |
|
| 43 | machine
|
| 44 | machine?
|
| 45 |
|
| 46 | machine-operating-system
|
| 47 | machine-environment
|
| 48 | machine-configuration
|
| 49 | machine-display-name
|
| 50 |
|
| 51 | deploy-machine
|
| 52 | roll-back-machine
|
| 53 | machine-remote-eval
|
| 54 |
|
| 55 | &deploy-error
|
| 56 | deploy-error?
|
| 57 | deploy-error-should-roll-back
|
| 58 | deploy-error-captured-args))
|
| 59 |
|
| 60 |
|
| 61 | |
| 62 | |
| 63 | |
| 64 |
|
| 65 | (define-record-type* <environment-type> environment-type
|
| 66 | make-environment-type
|
| 67 | environment-type?
|
| 68 |
|
| 69 | |
| 70 | |
| 71 | |
| 72 | |
| 73 | (machine-remote-eval environment-type-machine-remote-eval) |
| 74 | (deploy-machine environment-type-deploy-machine) |
| 75 | (roll-back-machine environment-type-roll-back-machine) |
| 76 |
|
| 77 | |
| 78 | (name environment-type-name) |
| 79 | (description environment-type-description |
| 80 | (default #f))
|
| 81 | (location environment-type-location |
| 82 | (default (and=> (current-source-location)
|
| 83 | source-properties->location))
|
| 84 | (innate)))
|
| 85 |
|
| 86 |
|
| 87 | |
| 88 | |
| 89 | |
| 90 |
|
| 91 | (define-record-type* <machine> machine make-machine
|
| 92 | machine?
|
| 93 | (operating-system %machine-operating-system) |
| 94 | (environment machine-environment) |
| 95 | (configuration machine-configuration |
| 96 | (default #f))) |
| 97 |
|
| 98 | (define (machine-operating-system machine)
|
| 99 | "Return the operating system of MACHINE."
|
| 100 | (operating-system-with-provenance
|
| 101 | (%machine-operating-system machine)))
|
| 102 |
|
| 103 | (define (machine-display-name machine)
|
| 104 | "Return the host-name identifying MACHINE."
|
| 105 | (operating-system-host-name (machine-operating-system machine)))
|
| 106 |
|
| 107 | (define (machine-remote-eval machine exp)
|
| 108 | "Evaluate EXP, a gexp, on MACHINE. Ensure that all the elements EXP refers to
|
| 109 | are built and deployed to MACHINE beforehand."
|
| 110 | (let ((environment (machine-environment machine)))
|
| 111 | ((environment-type-machine-remote-eval environment) machine exp)))
|
| 112 |
|
| 113 | (define (deploy-machine machine)
|
| 114 | "Monadic procedure transferring the new system's OS closure to the remote
|
| 115 | MACHINE, activating it on MACHINE and switching MACHINE to the new generation."
|
| 116 | (let ((environment (machine-environment machine)))
|
| 117 | ((environment-type-deploy-machine environment) machine)))
|
| 118 |
|
| 119 | (define (roll-back-machine machine)
|
| 120 | "Monadic procedure rolling back to the previous system generation on
|
| 121 | MACHINE. Return the number of the generation that was current before switching
|
| 122 | and the new generation number."
|
| 123 | (let ((environment (machine-environment machine)))
|
| 124 | ((environment-type-roll-back-machine environment) machine)))
|
| 125 |
|
| 126 |
|
| 127 | |
| 128 | |
| 129 | |
| 130 |
|
| 131 | (define-condition-type &deploy-error &error
|
| 132 | deploy-error?
|
| 133 | (should-roll-back deploy-error-should-roll-back)
|
| 134 | (captured-args deploy-error-captured-args))
|