Re: [PATCH 6/6] emacs: Add interface for system generations.

2016-01-13 Thread Ludovic Courtès
Alex Kost  skribis:

> Ludovic Courtès (2016-01-12 23:35 +0300) wrote:
>
>> Alex Kost  skribis:
>>
>>> * emacs/guix-main.scm (system-generation-boot-parameters)
>>> (system-generation-param-alist, system-generation-sexps): New procedures.
>>> (entries): Add 'system-generation' entry type.
>>> * emacs/guix-messages.el (guix-result-message): Use the same messages
>>>   for 'generation' and 'system-generation' entry types.
>>> * emacs/guix-ui-system-generation.el: New file.
>>> * emacs.am (ELFILES): Add it.
>>> * doc/emacs.texi (Emacs Commands): Document new commands.
>>> * NEWS: Mention new interface.
>>
>> [...]
>>
>>> +Analogously on GuixSD you can also display system generations:
>>> +
>>> +@table @kbd
>>> +@item M-x guix-system-generations
>>> +@item M-x guix-last-system-generations
>>> +@item M-x guix-system-generations-by-time
>>> +@end table
>>
>> As simple as this.  :-)
>>
>> And I guess it’s also possible to select generations, delete them, and
>> switch to a specific one, as with M-x guix-generations?
>
> Well yes, but only if emacs was started with root privileges.  At first
> I was going to remove support for deleting/switching system generations
> because of this, but then I left it, as I thought there might exist
> users who run emacs from "root" for some reason, and such manipulating
> system generations may be useful for them.

Sounds reasonable.

>> Though maybe it would have to use
>> “sudo:localhost:/run/current-system/profile” (via Tramp) to be able to
>> modify things.  Maybe it could somehow offer to gain root privileges
>> when performing an action?
>
> I don't see how it can be done, since we use a guile REPL to perform
> such actions (for example, ‘delete-generations’ procedure from (guix
> scripts package) module).  But the REPL is started with the same
> privileges as emacs.

Oh right.  We could use elisp code to delete the symlink (that would
allow us to use Tramp), but it’s probably not worth bothering.

Thanks!

Ludo’.



Re: [PATCH 6/6] emacs: Add interface for system generations.

2016-01-13 Thread Alex Kost
Ludovic Courtès (2016-01-12 23:35 +0300) wrote:

> Alex Kost  skribis:
>
>> * emacs/guix-main.scm (system-generation-boot-parameters)
>> (system-generation-param-alist, system-generation-sexps): New procedures.
>> (entries): Add 'system-generation' entry type.
>> * emacs/guix-messages.el (guix-result-message): Use the same messages
>>   for 'generation' and 'system-generation' entry types.
>> * emacs/guix-ui-system-generation.el: New file.
>> * emacs.am (ELFILES): Add it.
>> * doc/emacs.texi (Emacs Commands): Document new commands.
>> * NEWS: Mention new interface.
>
> [...]
>
>> +Analogously on GuixSD you can also display system generations:
>> +
>> +@table @kbd
>> +@item M-x guix-system-generations
>> +@item M-x guix-last-system-generations
>> +@item M-x guix-system-generations-by-time
>> +@end table
>
> As simple as this.  :-)
>
> And I guess it’s also possible to select generations, delete them, and
> switch to a specific one, as with M-x guix-generations?

Well yes, but only if emacs was started with root privileges.  At first
I was going to remove support for deleting/switching system generations
because of this, but then I left it, as I thought there might exist
users who run emacs from "root" for some reason, and such manipulating
system generations may be useful for them.

> Though maybe it would have to use
> “sudo:localhost:/run/current-system/profile” (via Tramp) to be able to
> modify things.  Maybe it could somehow offer to gain root privileges
> when performing an action?

I don't see how it can be done, since we use a guile REPL to perform
such actions (for example, ‘delete-generations’ procedure from (guix
scripts package) module).  But the REPL is started with the same
privileges as emacs.

-- 
Alex



Re: [PATCH 6/6] emacs: Add interface for system generations.

2016-01-12 Thread Ludovic Courtès
Alex Kost  skribis:

> * emacs/guix-main.scm (system-generation-boot-parameters)
> (system-generation-param-alist, system-generation-sexps): New procedures.
> (entries): Add 'system-generation' entry type.
> * emacs/guix-messages.el (guix-result-message): Use the same messages
>   for 'generation' and 'system-generation' entry types.
> * emacs/guix-ui-system-generation.el: New file.
> * emacs.am (ELFILES): Add it.
> * doc/emacs.texi (Emacs Commands): Document new commands.
> * NEWS: Mention new interface.

[...]

> +Analogously on GuixSD you can also display system generations:
> +
> +@table @kbd
> +@item M-x guix-system-generations
> +@item M-x guix-last-system-generations
> +@item M-x guix-system-generations-by-time
> +@end table

As simple as this.  :-)

And I guess it’s also possible to select generations, delete them, and
switch to a specific one, as with M-x guix-generations?

Though maybe it would have to use
“sudo:localhost:/run/current-system/profile” (via Tramp) to be able to
modify things.  Maybe it could somehow offer to gain root privileges
when performing an action?

Ludo’.



[PATCH 6/6] emacs: Add interface for system generations.

2016-01-10 Thread Alex Kost
* emacs/guix-main.scm (system-generation-boot-parameters)
(system-generation-param-alist, system-generation-sexps): New procedures.
(entries): Add 'system-generation' entry type.
* emacs/guix-messages.el (guix-result-message): Use the same messages
  for 'generation' and 'system-generation' entry types.
* emacs/guix-ui-system-generation.el: New file.
* emacs.am (ELFILES): Add it.
* doc/emacs.texi (Emacs Commands): Document new commands.
* NEWS: Mention new interface.
---
 NEWS   |   1 +
 doc/emacs.texi |   8 +++
 emacs.am   |   1 +
 emacs/guix-main.scm|  36 +
 emacs/guix-messages.el |   5 +-
 emacs/guix-ui-system-generation.el | 105 +
 6 files changed, 155 insertions(+), 1 deletion(-)
 create mode 100644 emacs/guix-ui-system-generation.el

diff --git a/NEWS b/NEWS
index c35c7d6..0084394 100644
--- a/NEWS
+++ b/NEWS
@@ -14,6 +14,7 @@ Please send Guix bug reports to bug-g...@gnu.org.
 
 ** Package management
 
+*** Emacs interface for system generations
 *** Emacs interface for hydra.gnu.org
 *** Changes in Emacs interface variables
 In the following names, BUFFER-TYPE means "info" or "list";
diff --git a/doc/emacs.texi b/doc/emacs.texi
index ea340b1..b2a3d47 100644
--- a/doc/emacs.texi
+++ b/doc/emacs.texi
@@ -191,6 +191,14 @@ date/time prompt,,, org, The Org Manual}).
 
 @end table
 
+Analogously on GuixSD you can also display system generations:
+
+@table @kbd
+@item M-x guix-system-generations
+@item M-x guix-last-system-generations
+@item M-x guix-system-generations-by-time
+@end table
+
 You can also invoke the @command{guix pull} command (@pxref{Invoking
 guix pull}) from Emacs using:
 
diff --git a/emacs.am b/emacs.am
index 85165b9..d0d4dfb 100644
--- a/emacs.am
+++ b/emacs.am
@@ -47,6 +47,7 @@ ELFILES = \
   emacs/guix-ui.el \
   emacs/guix-ui-package.el \
   emacs/guix-ui-generation.el  \
+  emacs/guix-ui-system-generation.el   \
   emacs/guix-utils.el
 
 if HAVE_EMACS
diff --git a/emacs/guix-main.scm b/emacs/guix-main.scm
index 1199679..4baf2df 100644
--- a/emacs/guix-main.scm
+++ b/emacs/guix-main.scm
@@ -61,6 +61,7 @@
  (guix scripts lint)
  (guix scripts package)
  (guix scripts pull)
+ (guix scripts system)
  (gnu packages))
 
 (define-syntax-rule (first-or-false lst)
@@ -758,6 +759,38 @@ See 'entry-sexps' for details."
 params)))
 (map ->sexp generations)))
 
+(define system-generation-boot-parameters
+  (memoize
+   (lambda (profile generation)
+ "Return boot parameters for PROFILE's system GENERATION."
+ (let* ((gen-file   (generation-file-name profile generation))
+(param-file (string-append gen-file "/parameters")))
+   (call-with-input-file param-file read-boot-parameters)
+
+(define (system-generation-param-alist profile)
+  "Return an alist of system generation parameters and procedures for
+PROFILE."
+  (append (generation-param-alist profile)
+  `((label   . ,(lambda (gen)
+  (boot-parameters-label
+   (system-generation-boot-parameters
+profile gen
+(root-device . ,(lambda (gen)
+  (boot-parameters-root-device
+   (system-generation-boot-parameters
+profile gen
+(kernel  . ,(lambda (gen)
+  (boot-parameters-kernel
+   (system-generation-boot-parameters
+profile gen)))
+
+(define (system-generation-sexps profile params search-type search-vals)
+  "Return an alist with information about system generations."
+  (let ((generations (find-generations profile search-type search-vals))
+(->sexp (object-transformer (system-generation-param-alist profile)
+params)))
+(map ->sexp generations)))
+
 
 ;;; Getting package/output/generation entries (alists).
 
@@ -802,6 +835,9 @@ parameter/value pairs."
 ((generation)
  (generation-sexps profile params
search-type search-vals))
+((system-generation)
+ (system-generation-sexps profile params
+  search-type search-vals))
 (else (entry-type-error entry-type
 
 
diff --git a/emacs/guix-messages.el b/emacs/guix-messages.el
index 9f6d833..c4f15dc 100644
--- a/emacs/guix-messages.el
+++ b/emacs/guix-messages.el
@@ -186,7 +186,10 @@ Try \"M-x guix-search-by-name\"."
 search-type search-vals)
   "Display an appropriate message after displaying ENTRIES."
   (let* ((type-spec (guix-assq-value guix-messages
- entry-type search-type))
+