aboutsummaryrefslogtreecommitdiff
path: root/gnu/services
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2014-09-18 22:51:48 +0200
committerLudovic Courtès <ludo@gnu.org>2014-09-18 22:52:01 +0200
commit2a13d05e459946d4989e08461233d7f147f029f5 (patch)
tree648676170ffd849fca28d245093b30206035a715 /gnu/services
parent715fc9d44d284a0c5e1ded45091eaf979aa5ecd4 (diff)
downloadpatches-2a13d05e459946d4989e08461233d7f147f029f5.tar
patches-2a13d05e459946d4989e08461233d7f147f029f5.tar.gz
system: Add support for swap devices.
* gnu/services/base.scm (swap-service): New procedure. * gnu/system.scm (<operating-system>)[swap-devices]: New field. (swap-services): New procedure. (essential-services): Use it.
Diffstat (limited to 'gnu/services')
-rw-r--r--gnu/services/base.scm22
1 files changed, 22 insertions, 0 deletions
diff --git a/gnu/services/base.scm b/gnu/services/base.scm
index f2de85f410..b38d3e3765 100644
--- a/gnu/services/base.scm
+++ b/gnu/services/base.scm
@@ -39,6 +39,7 @@
#:export (root-file-system-service
file-system-service
device-mapping-service
+ swap-service
user-processes-service
host-name-service
console-font-service
@@ -614,6 +615,27 @@ gexp, to open it, and evaluate @var{close} to close it."
(stop #~(lambda _ (not #$close)))
(respawn? #f)))))
+(define (swap-service device)
+ "Return a service that uses @var{device} as a swap device."
+ (define requirement
+ (if (string-prefix? "/dev/mapper/" device)
+ (list (symbol-append 'device-mapping-
+ (string->symbol (basename device))))
+ '()))
+
+ (with-monad %store-monad
+ (return (service
+ (provision (list (symbol-append 'swap- (string->symbol device))))
+ (requirement `(udev ,@requirement))
+ (documentation "Enable the given swap device.")
+ (start #~(lambda ()
+ (swapon #$device)
+ #t))
+ (stop #~(lambda _
+ (swapoff #$device)
+ #f))
+ (respawn? #f)))))
+
(define %base-services
;; Convenience variable holding the basic services.
(let ((motd (text-file "motd" "