From: Alex Kost <alezost@gmail.com>
To: "Ludovic Courtès" <ludo@gnu.org>
Cc: guix-devel@gnu.org
Subject: Re: [PATCH 1/6] guix system: Export <boot-parameters> accessors.
Date: Thu, 14 Jan 2016 11:34:44 +0300 [thread overview]
Message-ID: <87y4bstv8b.fsf@gmail.com> (raw)
In-Reply-To: <87a8o9154u.fsf@gnu.org> ("Ludovic \=\?utf-8\?Q\?Court\=C3\=A8s\=22'\?\= \=\?utf-8\?Q\?s\?\= message of "Wed, 13 Jan 2016 23:33:37 +0100")
[-- Attachment #1: Type: text/plain, Size: 1484 bytes --]
Ludovic Courtès (2016-01-14 01:33 +0300) wrote:
> Alex Kost <alezost@gmail.com> skribis:
>
>> Ludovic Courtès (2016-01-12 23:25 +0300) wrote:
>>
>>> Alex Kost <alezost@gmail.com> skribis:
>>>
>>>> * guix/scripts/system.scm (read-boot-parameters, boot-parameters)
>>>> (boot-parameters?, boot-parameters-label, boot-parameters-root-device)
>>>> (boot-parameters-kernel, boot-parameters-kernel-arguments): Export.
>>>
>>> LGTM.
>>>
>>> Eventually (as a replacement of this patch or as a subsequent patch, as
>>> you prefer) we should move these to (gnu system) since this is where we
>>> create the ‘boot-parameters’ sexp.
>>
>> Great, I would like to make a replacement. OK for the attached patch?
>>
>> (I exported <boot-parameters> because it is used by (guix scripts system))
>
> I usually avoid exporting record type descriptors (RTDs) like
> <boot-parameters> because then, if you change the layout of fields, you
> have to update every ‘match’ clause out there, and it can be tedious and
> error-prone. Also, if the RTD is exported, then it’s trivial for other
> modules to forge records of that type.
>
> Could you instead rewrite the two occurrences in (guix system scripts)
> so they use the ‘boot-parameters-XYZ’ accessors instead of ‘match’? A
> bit more verbose, but safer.
>
> Sorry that I didn’t clarify this before!
Sure, I should have guessed to do it without clarifying. The updated
patch is attached.
[-- Attachment #2: 0001-Move-boot-parameters-to-gnu-system.patch --]
[-- Type: text/x-patch, Size: 7983 bytes --]
From df626fd61b5611b2174a792fd5736d696bd307c1 Mon Sep 17 00:00:00 2001
From: Alex Kost <alezost@gmail.com>
Date: Fri, 8 Jan 2016 02:48:17 +0300
Subject: [PATCH] Move <boot-parameters> to (gnu system).
* guix/scripts/system.scm (previous-grub-entries)
(display-system-generation): Use accessors instead of matching
<boot-parameters>.
(boot-parameters, boot-parameters?, boot-parameters-label)
(boot-parameters-root-device, boot-parameters-kernel)
(boot-parameters-kernel-arguments, read-boot-parameters): Move to...
* gnu/system.scm: ... here. Export them.
---
gnu/system.scm | 41 ++++++++++++++++++++++++
guix/scripts/system.scm | 85 ++++++++++++++++---------------------------------
2 files changed, 68 insertions(+), 58 deletions(-)
diff --git a/gnu/system.scm b/gnu/system.scm
index 4aedb7e..ee0280c 100644
--- a/gnu/system.scm
+++ b/gnu/system.scm
@@ -88,6 +88,14 @@
operating-system-locale-directory
operating-system-boot-script
+ boot-parameters
+ boot-parameters?
+ boot-parameters-label
+ boot-parameters-root-device
+ boot-parameters-kernel
+ boot-parameters-kernel-arguments
+ read-boot-parameters
+
local-host-aliases
%setuid-programs
%base-packages
@@ -709,4 +717,37 @@ this file is the reconstruction of GRUB menu entries for old configurations."
#$(operating-system-kernel-arguments os))
(initrd #$initrd)))))
+\f
+;;;
+;;; Boot parameters
+;;;
+
+(define-record-type* <boot-parameters>
+ boot-parameters make-boot-parameters boot-parameters?
+ (label boot-parameters-label)
+ (root-device boot-parameters-root-device)
+ (kernel boot-parameters-kernel)
+ (kernel-arguments boot-parameters-kernel-arguments))
+
+(define (read-boot-parameters port)
+ "Read boot parameters from PORT and return the corresponding
+<boot-parameters> object or #f if the format is unrecognized."
+ (match (read port)
+ (('boot-parameters ('version 0)
+ ('label label) ('root-device root)
+ ('kernel linux)
+ rest ...)
+ (boot-parameters
+ (label label)
+ (root-device root)
+ (kernel linux)
+ (kernel-arguments
+ (match (assq 'kernel-arguments rest)
+ ((_ args) args)
+ (#f '()))))) ;the old format
+ (x ;unsupported format
+ (warning (_ "unrecognized boot parameters for '~a'~%")
+ system)
+ #f)))
+
;;; system.scm ends here
diff --git a/guix/scripts/system.scm b/guix/scripts/system.scm
index 1407dc7..564ed02 100644
--- a/guix/scripts/system.scm
+++ b/guix/scripts/system.scm
@@ -1,5 +1,6 @@
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2014, 2015 Ludovic Courtès <ludo@gnu.org>
+;;; Copyright © 2016 Alex Kost <alezost@gmail.com>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -191,39 +192,6 @@ the ownership of '~a' may be incorrect!~%")
\f
;;;
-;;; Boot parameters
-;;;
-
-(define-record-type* <boot-parameters>
- boot-parameters make-boot-parameters boot-parameters?
- (label boot-parameters-label)
- (root-device boot-parameters-root-device)
- (kernel boot-parameters-kernel)
- (kernel-arguments boot-parameters-kernel-arguments))
-
-(define (read-boot-parameters port)
- "Read boot parameters from PORT and return the corresponding
-<boot-parameters> object or #f if the format is unrecognized."
- (match (read port)
- (('boot-parameters ('version 0)
- ('label label) ('root-device root)
- ('kernel linux)
- rest ...)
- (boot-parameters
- (label label)
- (root-device root)
- (kernel linux)
- (kernel-arguments
- (match (assq 'kernel-arguments rest)
- ((_ args) args)
- (#f '()))))) ;the old format
- (x ;unsupported format
- (warning (_ "unrecognized boot parameters for '~a'~%")
- system)
- #f)))
-
-\f
-;;;
;;; Reconfiguration.
;;;
@@ -285,22 +253,24 @@ it atomically, and then run OS's activation script."
"Return a list of 'menu-entry' for the generations of PROFILE."
(define (system->grub-entry system number time)
(unless-file-not-found
- (let ((file (string-append system "/parameters")))
- (match (call-with-input-file file read-boot-parameters)
- (($ <boot-parameters> label root kernel kernel-arguments)
- (menu-entry
- (label (string-append label " (#"
- (number->string number) ", "
- (seconds->string time) ")"))
- (linux kernel)
- (linux-arguments
- (cons* (string-append "--root=" root)
- #~(string-append "--system=" #$system)
- #~(string-append "--load=" #$system "/boot")
- kernel-arguments))
- (initrd #~(string-append #$system "/initrd"))))
- (#f ;invalid format
- #f)))))
+ (let* ((file (string-append system "/parameters"))
+ (params (call-with-input-file file
+ read-boot-parameters))
+ (label (boot-parameters-label params))
+ (root (boot-parameters-root-device params))
+ (kernel (boot-parameters-kernel params))
+ (kernel-arguments (boot-parameters-kernel-arguments params)))
+ (menu-entry
+ (label (string-append label " (#"
+ (number->string number) ", "
+ (seconds->string time) ")"))
+ (linux kernel)
+ (linux-arguments
+ (cons* (string-append "--root=" root)
+ #~(string-append "--system=" #$system)
+ #~(string-append "--load=" #$system "/boot")
+ kernel-arguments))
+ (initrd #~(string-append #$system "/initrd"))))))
(let* ((numbers (generation-numbers profile))
(systems (map (cut generation-file-name profile <>)
@@ -366,18 +336,17 @@ list of services."
(unless (zero? number)
(let* ((generation (generation-file-name profile number))
(param-file (string-append generation "/parameters"))
- (params (call-with-input-file param-file read-boot-parameters)))
+ (params (call-with-input-file param-file read-boot-parameters))
+ (label (boot-parameters-label params))
+ (root (boot-parameters-root-device params))
+ (kernel (boot-parameters-kernel params)))
(display-generation profile number)
(format #t (_ " file name: ~a~%") generation)
(format #t (_ " canonical file name: ~a~%") (readlink* generation))
- (match params
- (($ <boot-parameters> label root kernel)
- ;; TRANSLATORS: Please preserve the two-space indentation.
- (format #t (_ " label: ~a~%") label)
- (format #t (_ " root device: ~a~%") root)
- (format #t (_ " kernel: ~a~%") kernel))
- (_
- #f)))))
+ ;; TRANSLATORS: Please preserve the two-space indentation.
+ (format #t (_ " label: ~a~%") label)
+ (format #t (_ " root device: ~a~%") root)
+ (format #t (_ " kernel: ~a~%") kernel))))
(define* (list-generations pattern #:optional (profile %system-profile))
"Display in a human-readable format all the system generations matching
--
2.6.3
next prev parent reply other threads:[~2016-01-14 8:34 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-01-10 9:53 [PATCH 0/6] emacs: Add "M-x guix-system-generations" Alex Kost
2016-01-10 9:53 ` [PATCH 1/6] guix system: Export <boot-parameters> accessors Alex Kost
2016-01-12 20:25 ` Ludovic Courtès
2016-01-13 20:44 ` Alex Kost
2016-01-13 22:33 ` Ludovic Courtès
2016-01-14 8:34 ` Alex Kost [this message]
2016-01-14 13:25 ` Ludovic Courtès
2016-01-10 9:53 ` [PATCH 2/6] emacs: profiles: Add 'guix-system-profile' Alex Kost
2016-01-12 20:25 ` Ludovic Courtès
2016-01-10 9:53 ` [PATCH 3/6] emacs: Find packages in system profiles Alex Kost
2016-01-12 20:28 ` Ludovic Courtès
2016-01-13 20:45 ` Alex Kost
2016-01-13 22:42 ` Ludovic Courtès
2016-01-14 8:38 ` Alex Kost
2016-01-14 13:27 ` Ludovic Courtès
2016-01-10 9:53 ` [PATCH 4/6] emacs: Replace 'generation-diff' search with 'profile-diff' Alex Kost
2016-01-12 20:29 ` Ludovic Courtès
2016-01-10 9:53 ` [PATCH 5/6] emacs: Remove 'generation' search type Alex Kost
2016-01-12 20:31 ` Ludovic Courtès
2016-01-10 9:53 ` [PATCH 6/6] emacs: Add interface for system generations Alex Kost
2016-01-12 20:35 ` Ludovic Courtès
2016-01-13 20:56 ` Alex Kost
2016-01-13 22:44 ` Ludovic Courtès
2016-01-12 20:23 ` [PATCH 0/6] emacs: Add "M-x guix-system-generations" Ludovic Courtès
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87y4bstv8b.fsf@gmail.com \
--to=alezost@gmail.com \
--cc=guix-devel@gnu.org \
--cc=ludo@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/guix.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.