aboutsummaryrefslogtreecommitdiff
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2019 David Thompson <davet@gnu.org>
;;; Copyright © 2019 Jakob L. Kreuze <zerodaysfordays@sdf.org>
;;;
;;; 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 (gnu machine)
  #:use-module (gnu system)
  #:use-module (guix derivations)
  #:use-module (guix monads)
  #:use-module (guix records)
  #:use-module (guix store)
  #:use-module ((guix diagnostics) #:select (source-properties->location))
  #:use-module (srfi srfi-35)
  #:export (environment-type
            environment-type?
            environment-type-name
            environment-type-description
            environment-type-location

            machine
            machine?

            machine-operating-system
            machine-environment
            machine-configuration
            machine-display-name

            deploy-machine
            roll-back-machine
            machine-remote-eval

            &deploy-error
            deploy-error?
            deploy-error-should-roll-back
            deploy-error-captured-args))

;;; Commentary:
;;;
;;; This module provides the types used to declare individual machines in a
;;; heterogeneous Guix deployment. The interface allows users to specify system
;;; configurations and the means by which resources should be provisioned on a
;;; per-host basis.
;;;
;;; Code:


;;;
;;; Declarations for resources that can be provisioned.
;;;

(define-record-type* <environment-type> environment-type
  make-environment-type
  environment-type?

  ;; Interface to the environment type's deployment code. Each procedure
  ;; should take the same arguments as the top-level procedure of this file
  ;; that shares the same name. For example, 'machine-remote-eval' should be
  ;; of the form '(machine-remote-eval machine exp)'.
  (machine-remote-eval environment-type-machine-remote-eval) ; procedure
  (deploy-machine      environment-type-deploy-machine)      ; procedure
  (roll-back-machine   environment-type-roll-back-machine)   ; procedure

  ;; Metadata.
  (name        environment-type-name)       ; symbol
  (description environment-type-description ; string
               (default #f))
  (location    environment-type-location    ; <location>
               (default (and=> (current-source-location)
                               source-properties->location))
               (innate)))


;;;
;;; Declarations for machines in a deployment.
;;;

(define-record-type* <machine> machine make-machine
  machine?
  (operating-system %machine-operating-system); <operating-system>
  (environment      machine-environment)      ; symbol
  (configuration    machine-configuration     ; configuration object
                    (default #f)))            ; specific to environment

(define (machine-operating-system machine)
  "Return the operating system of MACHINE."
  (operating-system-with-provenance
   (%machine-operating-system machine)))

(define (machine-display-name machine)
  "Return the host-name identifying MACHINE."
  (operating-system-host-name (machine-operating-system machine)))

(define (machine-remote-eval machine exp)
  "Evaluate EXP, a gexp, on MACHINE. Ensure that all the elements EXP refers to
are built and deployed to MACHINE beforehand."
  (let ((environment (machine-environment machine)))
    ((environment-type-machine-remote-eval environment) machine exp)))

(define (deploy-machine machine)
  "Monadic procedure transferring the new system's OS closure to the remote
MACHINE, activating it on MACHINE and switching MACHINE to the new generation."
  (let ((environment (machine-environment machine)))
    ((environment-type-deploy-machine environment) machine)))

(define (roll-back-machine machine)
  "Monadic procedure rolling back to the previous system generation on
MACHINE. Return the number of the generation that was current before switching
and the new generation number."
  (let ((environment (machine-environment machine)))
    ((environment-type-roll-back-machine environment) machine)))


;;;
;;; Error types.
;;;

(define-condition-type &deploy-error &error
  deploy-error?
  (should-roll-back deploy-error-should-roll-back)
  (captured-args deploy-error-captured-args))
sharlatanus@gmail.com> Change-Id: I90653554a6f0640718892622f76c0c1be138687c Fries 2024-03-21gnu: universal-ctags: Update to 6.1.20240317.0....* gnu/packages/code.scm (universal-ctags): Update to 6.1.20240317.0. Change-Id: I035bc73702fbe9951820e176f09bde16bd9049c6 Efraim Flashner 2024-03-21gnu: global: Update to 6.6.12....* gnu/packages/code.scm (global): Update to 6.6.12. Change-Id: If073f74f55199bfbc9f29b95e9e3db3a6cf00548 Efraim Flashner 2024-02-22gnu: universal-ctags: Update to 6.1.20240218.0....* gnu/packages/code.scm (universal-ctags): Update to 6.1.20240218.0. Change-Id: I3d4b19d0ba002d809cb5e659899965d3f62e8e1a Efraim Flashner 2023-11-08gnu: Have vim packages use vim-build-system....* gnu/packages/vim.scm (vim-neocomplete, vim-neocomplete-snippets, vim-neosnippet, vim-scheme, vim-luna, vim-fugitive, vim-airline, vim-airline-themes, vim-syntastic, neovim-syntastic, vim-solarized, vim-rainbow, editorconfig-vim, neovim-packer, vim-guix-vim, vim-asyncrun, vim-dispatch, vim-gemini-vim, vim-eunuch, vim-slime, vim-vlime, vim-paredit, vim-surround, vim-gnupg, vim-ctrlp, vim-mucomplete, vim-gitgutter, vim-characterize, vim-tagbar, vim-nerdtree, vim-nerdcommander): [build-system]: Switch to vim-build-system. [arguments]: Adjust accordingly. * gnu/packages/code.scm (global)[arguments]: Move vim files to their new location. * gnu/packages/lisp.scm (txr), * gnu/packages/mail.scm (msmtp), * gnu/packages/rust-apps.scm (skim), * gnu/packages/vim.scm (vifm), * gnu/packages/wm.scm (fluxbox): Same. Co-authored-by: Efraim Flashner <efraim@flashner.co.il> Signed-off-by: Efraim Flashner <efraim@flashner.co.il> Change-Id: I8b3e5d65d76a100c3dbddc1ae562b72966c2b304 Jonathan Scoresby 2023-10-05gnu: universal-ctags: Update to 6.0.20231001.0....* gnu/packages/code.scm (universal-ctags): Update to 6.0.20231001.0. Efraim Flashner 2023-09-24gnu: kcov: Clean up build phase....* gnu/packages/code.scm (kcov)[arguments]: Use SEARCH-INPUT-FILE and remove a vestigial LET from the 'fix-/bin/bash-references phase. Tobias Geerinckx-Rice 2023-09-24gnu: kcov: Update to 42....* gnu/packages/code.scm (kcov): Update to 42. Tobias Geerinckx-Rice 2023-09-24gnu: astyle: Don't build static or debug libraries....* gnu/packages/code.scm (astyle)[arguments]: Build only the "release" and "shared" targets we actually care about. Tobias Geerinckx-Rice 2023-09-24gnu: astyle: Use G-expressions....* gnu/packages/code.scm (astyle)[arguments]: Rewrite as G-expressions. Tobias Geerinckx-Rice 2023-09-24gnu: astyle: Omit static libraries....* gnu/packages/code.scm (astyle)[arguments]: Improve the buggy regexp in the 'install-libs phase to install only dynamic libraries. Tobias Geerinckx-Rice 2023-09-24gnu: astyle: Update to 3.4.8....* gnu/packages/code.scm (astyle): Update to 3.4.8. [arguments]: Don't explicitly return #t from phases. Tobias Geerinckx-Rice 2023-09-10gnu: indent: Update to 2.2.13....* gnu/packages/code.scm (indent): Finish update to 2.2.13, partially pushed in commit 4c4ff2e1f077786d85c47ceeec10340a864e17f1. Tobias Geerinckx-Rice 2023-09-10gnu: vsftpd: Fix build with recent OpenSSL....* gnu/packages/ftp.scm (vsftpd)[arguments]: Add "-Wno-deprecated-declarations" to CFLAGS. Reported by helioscultist in #guix. Tobias Geerinckx-Rice 2023-09-14gnu: uncrustify: use new style and gexp....* gnu/packages/code.scm (uncrustify): use new style and gexp. [native-inputs]: remove label. [arguments]: use gexp and remove tail #t. Signed-off-by: Ludovic Courtès <ludo@gnu.org> Zheng Junjie 2023-09-14gnu: uncrustify: Update to 0.77.1....* gnu/packages/code.scm (uncrustify): Update to 0.77.1. Signed-off-by: Ludovic Courtès <ludo@gnu.org> Zheng Junjie 2023-09-14gnu: makefile2graph: fix cross-compile....* gnu/packages/code.scm (makefile2graph): fix cross-compile. [arguments]: Use gexp and CC-FOR-TARGET. Signed-off-by: Ludovic Courtès <ludo@gnu.org> Zheng Junjie 2023-09-09gnu: global: Fix ctags creation using pygments....* gnu/packages/code.scm (global)[arguments]: Adjust configure-flags to use a specific python interpreter. Efraim Flashner