diff options
author | Sean Whitton <spwhitton@spwhitton.name> | 2021-05-24 17:08:50 -0700 |
---|---|---|
committer | Sean Whitton <spwhitton@spwhitton.name> | 2021-05-24 17:08:50 -0700 |
commit | bf9d7ed723517034449af5e4c2857897ccaddbfb (patch) | |
tree | b150b53b67d2820cdd65cfd26090d7ae6c257cc0 /src/property/container.lisp | |
parent | bedf3a65d844beaeae3f58b4818323926532cf74 (diff) | |
download | consfigurator-bf9d7ed723517034449af5e4c2857897ccaddbfb.tar.gz |
add CONSFIGURATOR.PROPERTY.CONTAINER
Signed-off-by: Sean Whitton <spwhitton@spwhitton.name>
Diffstat (limited to 'src/property/container.lisp')
-rw-r--r-- | src/property/container.lisp | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/src/property/container.lisp b/src/property/container.lisp new file mode 100644 index 0000000..2c06dbd --- /dev/null +++ b/src/property/container.lisp @@ -0,0 +1,69 @@ +;;; Consfigurator -- Lisp declarative configuration management system + +;;; Copyright (C) 2021 Sean Whitton <spwhitton@spwhitton.name> + +;;; This file 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, or (at your option) +;;; any later version. + +;;; This file 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 this program. If not, see <http://www.gnu.org/licenses/>. + +(in-package :consfigurator.property.container) +(named-readtables:in-readtable :consfigurator) + +;;;; Container-related hostattrs + +;;; The main purpose of these utilities is to permit conditionalising on what +;;; things are contained, to avoid affecting the host system outside the +;;; container in undesirable ways. For example, avoiding changing the host +;;; system's hostname because the chroot is for a system with a different +;;; hostname (but still updating /etc/hostname inside the chroot). + +(defprop contained :posix (&rest contained) + "Indicate that each of CONTAINED, a list of symbols, is isolated from the host +system of this container, and so may be changed without fear of affecting the +outside host. + +Also implicitly marks this host as a container, such that property combinators +which care about what's contained will not assume that they're running outside +of any container. + +This property is usually set by properties which establish containers, like +CHROOT:OS-BOOTSTRAPPED, rather than being added to DEFHOST forms." + (:desc (format nil "~{~(~S~)~^, ~} ~:*~1{~#[are~;is~:;are~]~} contained" + contained)) + (:hostattrs (apply #'push-hostattrs 'iscontained contained))) + +(defmacro when-contained ((&rest contained) &body propapps) + "Macro property combinator. Apply each of PROPAPPS only when outside of any +container, or when each of CONTAINED, a list of symbols, is contained by this +container type." + `(when-contained* + ',contained + ,(if (cdr propapps) `(eseqprops ,@propapps) (car propapps)))) + +(define-function-property-combinator when-contained* (contained propapp) + (macrolet ((check-contained (form) + `(let ((host-contained (get-hostattrs 'iscontained))) + (when (or (not host-contained) + (loop for factor in contained + always (member factor host-contained))) + ,form)))) + (:retprop :type (propapptype propapp) + :hostattrs (lambda (&rest ignore) + (declare (ignore ignore)) + (propappattrs propapp)) + :apply (lambda (&rest ignore) + (declare (ignore ignore)) + (check-contained (propappapply propapp))) + :unapply (lambda (&rest ignore) + (declare (ignore ignore)) + (check-contained (propappunapply propapp))) + :args (cdr propapp)))) |