From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Craven Subject: [PATCH 3/4] services: Add rngd-service. Date: Sun, 3 Jul 2016 20:25:09 +0200 Message-ID: <20160703182510.21181-3-david@craven.ch> References: <20160703014231.GA1178@jasmine> Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:54942) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bJm5a-0006Hs-18 for guix-devel@gnu.org; Sun, 03 Jul 2016 14:25:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bJm5W-0004ep-Od for guix-devel@gnu.org; Sun, 03 Jul 2016 14:25:53 -0400 Received: from so254-10.mailgun.net ([198.61.254.10]:47619) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bJm5V-0004eK-Hd for guix-devel@gnu.org; Sun, 03 Jul 2016 14:25:50 -0400 In-Reply-To: <20160703014231.GA1178@jasmine> List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org Sender: "Guix-devel" To: guix-devel@gnu.org Cc: David Craven * gnu/services/base.scm: New service. * doc/guix.texi: Add documentation. --- doc/guix.texi | 6 ++++++ gnu/services/base.scm | 43 +++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index 62c0d34..ce28182 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -7494,6 +7494,12 @@ created by @command{guix archive --generate-key} (@pxref{Invoking guix archive}). If that is not the case, the service will fail to start. @end deffn +@anchor{rngd-service} +@deffn {Scheme Procedure} rngd-service [#:rng-tools @var{rng-tools}] @ + [#:rng-device "/dev/hwrng"] +Return a service that adds @var{rng-device} to the kernel entropy pool. This +service will fail if if the device doesn't exist. +@end deffn @node Scheduled Job Execution @subsubsection Scheduled Job Execution diff --git a/gnu/services/base.scm b/gnu/services/base.scm index f304bf8..67f3961 100644 --- a/gnu/services/base.scm +++ b/gnu/services/base.scm @@ -31,7 +31,7 @@ #:use-module (gnu system mapped-devices) #:use-module (gnu packages admin) #:use-module ((gnu packages linux) - #:select (eudev kbd e2fsprogs lvm2 fuse alsa-utils crda gpm)) + #:select (alsa-utils crda eudev e2fsprogs fuse gpm kbd lvm2 rng-tools)) #:use-module ((gnu packages base) #:select (canonical-package glibc)) #:use-module (gnu packages package-management) @@ -97,6 +97,7 @@ urandom-seed-service-type urandom-seed-service + rngd-service %base-services)) @@ -486,7 +487,45 @@ stopped before 'kill' is called." (define (urandom-seed-service) (service urandom-seed-service-type #f)) - + +;;; +;;; Add hardware random number generator to entropy pool +;;; + +(define-record-type* + rngd-configuration make-rngd-configuration + rngd-configuration? + (rng-tools rngd-configuration-rng-tools) + (rng-device rngd-configuration-rngd-device)) + +(define rngd-service-type + (shepherd-service-type + 'rngd + (lambda (config) + (define rng-tools (rngd-configuration-rng-tools config)) + (define rng-device (rngd-configuration-rngd-device config)) + + (define rngd-command + (list #~(string-append #$rng-tools "/sbin/rngd") "-f" "-r" rng-device)) + + (shepherd-service + (documentation "Add TRNG to entropy pool.") + (requirement '(udev)) + (provision '(trng)) + (start #~(make-forkexec-constructor #$@rngd-command)) + (stop #~(make-kill-destructor)))))) + +(define* (rngd-service #:key + (rng-tools rng-tools) + (rng-device "/dev/hwrng")) + "Run the @command{rngd} program from @var{rng-tools} to add @var{rng-device} +to the kernel's entropy pool." + (service rngd-service-type + (rngd-configuration + (rng-tools rng-tools) + (rng-device rng-device)))) + + ;;; ;;; System-wide environment variables. ;;; -- 2.9.0