system: Move 'luks-device-mapping' to (gnu system mapped-devices).
[jackhill/guix/guix.git] / gnu / system / mapped-devices.scm
CommitLineData
060d62a7
LC
1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2014, 2015, 2016 Ludovic Courtès <ludo@gnu.org>
3;;;
4;;; This file is part of GNU Guix.
5;;;
6;;; GNU Guix is free software; you can redistribute it and/or modify it
7;;; under the terms of the GNU General Public License as published by
8;;; the Free Software Foundation; either version 3 of the License, or (at
9;;; your option) any later version.
10;;;
11;;; GNU Guix is distributed in the hope that it will be useful, but
12;;; WITHOUT ANY WARRANTY; without even the implied warranty of
13;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14;;; GNU General Public License for more details.
15;;;
16;;; You should have received a copy of the GNU General Public License
17;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
18
19(define-module (gnu system mapped-devices)
374f14c2 20 #:use-module (guix gexp)
060d62a7 21 #:use-module (guix records)
374f14c2 22 #:autoload (gnu packages cryptsetup) (cryptsetup)
060d62a7
LC
23 #:export (mapped-device
24 mapped-device?
25 mapped-device-source
26 mapped-device-target
27 mapped-device-type
28
29 mapped-device-kind
30 mapped-device-kind?
31 mapped-device-kind-open
374f14c2
LC
32 mapped-device-kind-close
33
34 luks-device-mapping))
060d62a7
LC
35
36;;; Commentary:
37;;;
38;;; This module supports "device mapping", a concept implemented by Linux's
39;;; device-mapper.
40;;;
41;;; Code:
42
43(define-record-type* <mapped-device> mapped-device
44 make-mapped-device
45 mapped-device?
46 (source mapped-device-source) ;string
47 (target mapped-device-target) ;string
48 (type mapped-device-type)) ;<mapped-device-kind>
49
50(define-record-type* <mapped-device-type> mapped-device-kind
51 make-mapped-device-kind
52 mapped-device-kind?
53 (open mapped-device-kind-open) ;source target -> gexp
54 (close mapped-device-kind-close ;source target -> gexp
55 (default (const #~(const #f)))))
56
374f14c2
LC
57\f
58;;;
59;;; Common device mappings.
60;;;
61
62(define (open-luks-device source target)
63 "Return a gexp that maps SOURCE to TARGET as a LUKS device, using
64'cryptsetup'."
65 #~(zero? (system* (string-append #$cryptsetup "/sbin/cryptsetup")
66 "open" "--type" "luks"
67 #$source #$target)))
68
69(define (close-luks-device source target)
70 "Return a gexp that closes TARGET, a LUKS device."
71 #~(zero? (system* (string-append #$cryptsetup "/sbin/cryptsetup")
72 "close" #$target)))
73
74(define luks-device-mapping
75 ;; The type of LUKS mapped devices.
76 (mapped-device-kind
77 (open open-luks-device)
78 (close close-luks-device)))
79
060d62a7 80;;; mapped-devices.scm ends here