From 2a13d05e459946d4989e08461233d7f147f029f5 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Thu, 18 Sep 2014 22:51:48 +0200 Subject: system: Add support for swap devices. * gnu/services/base.scm (swap-service): New procedure. * gnu/system.scm ()[swap-devices]: New field. (swap-services): New procedure. (essential-services): Use it. --- gnu/services/base.scm | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'gnu/services') 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" " -- cgit v1.2.3