Commit | Line | Data |
---|---|---|
fa9edf09 JK |
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 (gnu machine) | |
21 | #:use-module (gnu system) | |
22 | #:use-module (guix derivations) | |
23 | #:use-module (guix monads) | |
24 | #:use-module (guix records) | |
25 | #:use-module (guix store) | |
26 | #:use-module ((guix utils) #:select (source-properties->location)) | |
27 | #:export (environment-type | |
28 | environment-type? | |
29 | environment-type-name | |
30 | environment-type-description | |
31 | environment-type-location | |
32 | ||
33 | machine | |
34 | machine? | |
35 | this-machine | |
36 | ||
37 | machine-system | |
38 | machine-environment | |
39 | machine-configuration | |
40 | machine-display-name | |
41 | ||
42 | deploy-machine | |
43 | machine-remote-eval)) | |
44 | ||
45 | ;;; Commentary: | |
46 | ;;; | |
47 | ;;; This module provides the types used to declare individual machines in a | |
48 | ;;; heterogeneous Guix deployment. The interface allows users of specify system | |
49 | ;;; configurations and the means by which resources should be provisioned on a | |
50 | ;;; per-host basis. | |
51 | ;;; | |
52 | ;;; Code: | |
53 | ||
54 | \f | |
55 | ;;; | |
56 | ;;; Declarations for resources that can be provisioned. | |
57 | ;;; | |
58 | ||
59 | (define-record-type* <environment-type> environment-type | |
60 | make-environment-type | |
61 | environment-type? | |
62 | ||
63 | ;; Interface to the environment type's deployment code. Each procedure | |
64 | ;; should take the same arguments as the top-level procedure of this file | |
65 | ;; that shares the same name. For example, 'machine-remote-eval' should be | |
66 | ;; of the form '(machine-remote-eval machine exp)'. | |
67 | (machine-remote-eval environment-type-machine-remote-eval) ; procedure | |
68 | (deploy-machine environment-type-deploy-machine) ; procedure | |
69 | ||
70 | ;; Metadata. | |
71 | (name environment-type-name) ; symbol | |
72 | (description environment-type-description ; string | |
73 | (default #f)) | |
74 | (location environment-type-location ; <location> | |
75 | (default (and=> (current-source-location) | |
76 | source-properties->location)) | |
77 | (innate))) | |
78 | ||
79 | \f | |
80 | ;;; | |
81 | ;;; Declarations for machines in a deployment. | |
82 | ;;; | |
83 | ||
84 | (define-record-type* <machine> machine | |
85 | make-machine | |
86 | machine? | |
87 | this-machine | |
88 | (system machine-system) ; <operating-system> | |
89 | (environment machine-environment) ; symbol | |
90 | (configuration machine-configuration ; configuration object | |
91 | (default #f))) ; specific to environment | |
92 | ||
93 | (define (machine-display-name machine) | |
94 | "Return the host-name identifying MACHINE." | |
95 | (operating-system-host-name (machine-system machine))) | |
96 | ||
97 | (define (machine-remote-eval machine exp) | |
98 | "Evaluate EXP, a gexp, on MACHINE. Ensure that all the elements EXP refers to | |
99 | are built and deployed to MACHINE beforehand." | |
100 | (let ((environment (machine-environment machine))) | |
101 | ((environment-type-machine-remote-eval environment) machine exp))) | |
102 | ||
103 | (define (deploy-machine machine) | |
104 | "Monadic procedure transferring the new system's OS closure to the remote | |
105 | MACHINE, activating it on MACHINE and switching MACHINE to the new generation." | |
106 | (let ((environment (machine-environment machine))) | |
107 | ((environment-type-deploy-machine environment) machine))) |