diff --git a/rekahsoft-gnu/services/ceph.scm b/rekahsoft-gnu/services/ceph.scm new file mode 100644 index 0000000..40b818d --- /dev/null +++ b/rekahsoft-gnu/services/ceph.scm @@ -0,0 +1,105 @@ +;;; Copyright © 2023 Collin J. Doering +;;; +;;; This file is part of the GNU Guix channel rekahsoft-guix +;;; +;;; The rekahsoft-guix channel for 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. +;;; +;;; The rekahsoft-guix channel for 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 the rekahsoft-guix channel for GNU Guix. If not, see +;;; . + +(define-module (rekahsoft-gnu services ceph) + #:use-module (gnu services configuration) + #:use-module (gnu packages storage) + #:use-module (guix packages) + #:use-module (ice-9 match) + #:use-module (gnu services shepherd) + #:use-module (gnu) + #:export (cephfs-configuration cephfs-configuration? cephfs-service-type)) + +(define-configuration/no-serialization cephfs-configuration + (package + (package ceph) + "The ceph package to use.") + (mount-point + (string) + "Mount point used for cephfs filesystem.") + (name + (string) + "The Rados client (user) name.") + (fsid + (string) + "The CephFS file-system id.") + (fs-name + (string) + "A symbolic name to use for the CephFS mount.") + (options + (string "rw,relatime,acl") + "File-system mount options. Defaults to 'rw,relatime,acl'") + (secret-file + (string) + "Secret file path to use for authentication.") + (monitors + (list-of-strings) + "A list of monitor addresses in the form of :.") + (subdir + (string "/") + "An optional subdirectory to mount (defaults to '/').") + (legacy-mount-syntax? + (boolean #f) + "Use the legacy mount.ceph syntax; see ceph.mount documentation for more details.")) + +(define cephfs-shepherd-service + (match-lambda + (($ package mount-point name fsid fs-name options secret-file monitors subdir legacy-mount-syntax?) + (list (shepherd-service + (provision (list (string->symbol (string-append "cephfs-" mount-point)))) + (documentation (string-append "Mount cephfs filesystem '" fsid "' (" mount-point ").")) + (requirement `(networking ,(string->symbol (string-append "file-system-" mount-point)))) + (start #~(make-system-constructor "/run/setuid-programs/mount /mnt/cephfs")) + (stop #~(make-system-constructor "/run/setuid-programs/umount /mnt/cephfs")) + (respawn? #f)))))) + +;; Mount syntax changed between ceph 16 and 17, however the old syntax is still supported +;; +;; 16.x Pacific - https://docs.ceph.com/en/pacific/man/8/mount.ceph/ +;; mount.ceph [mon1_socket,mon2_socket,…]:/[subdir] dir [-o options] +;; 17.x Quincy - https://docs.ceph.com/en/quincy/man/8/mount.ceph/ +;; mount.ceph name*@*fsid.*fs_name*=/[subdir] dir [-o options] +(define cephfs-file-systems + (match-lambda + (($ package mount-point name fsid fs-name options secret-file monitors subdir legacy-mount-syntax?) + (list (file-system + (device (if legacy-mount-syntax? + (string-append (string-join monitors ",") ":" subdir) + (string-append name "@" fsid "." fs-name "=" subdir))) + (options (string-append options "," + (if legacy-mount-syntax? + (string-append "name=" name) + (string-append "mon_addr=" (string-join monitors "/"))) + ",secretfile=" secret-file)) + ;; Filesystem cannot be mounted as its not a real device; instead a shepherd service is used to mount the file-system + (mount? #f) + (create-mount-point? #t) + (mount-point mount-point) + (type "ceph")))))) + +(define cephfs-profile + (compose list cephfs-configuration-package)) + +(define cephfs-service-type + (service-type + (name 'cephfs) + (description "Mount cephfs filesystems.") + (extensions + (list (service-extension shepherd-root-service-type cephfs-shepherd-service) + (service-extension file-system-service-type cephfs-file-systems) + (service-extension profile-service-type cephfs-profile)))))