Mirror of GNU Guix
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

107 lines
3.8 KiB

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