unofficial mirror of help-guix@gnu.org 
 help / color / mirror / Atom feed
* [beginner's question] How to write Guix scripts using GNU Emacs?
@ 2024-10-07  3:37 Rodrigo Morales
  0 siblings, 0 replies; only message in thread
From: Rodrigo Morales @ 2024-10-07  3:37 UTC (permalink / raw)
  To: help-guix


I want to write Guile scripts that use definitions from the guix repository using Emacs. When writing a script, I want to evaluate the sexp at point by pressing C-M-x and show its result in the minibuffer (as it is done when pressing C-M-x, bound to eval-defun, in an emacs-lisp-mode buffer). I haven't succeeded to get this behavior, I hope some Guix user can help me to accomplish this behavior.

* What i know: Execute Guile script using =guix repl=

I am aware that I can execute a Guile script using =guix repl=.

Consider the following sample Guile script:

#+HEADER: :tangle /tmp/a.scm
#+BEGIN_SRC scheme
(use-modules (gnu packages))
(format #t "~a~%" (specifications->packages (list "emacs")))
#+END_SRC

I can execute that script by running the command below.

#+HEADER: :prologue "exec 2>&1"
#+HEADER: :epilogue ":"
#+BEGIN_SRC sh
guix repl -- /tmp/a.scm ; echo Exit code: $?
#+END_SRC

#+RESULTS:
#+begin_example
((#<package emacs@29.4 gnu/packages/emacs.scm:446 7c5a09b99e70> out))
Exit code: 0
#+end_example

I should get the result shown above when evaluating the sexps inside Emacs.

* What I tried: Execute specific sexps from within Emacs

I removed the directory just to make sure that cached files don't interfer with the default behavior.

#+HEADER: :results silent
#+BEGIN_SRC sh
rm -rf ~/.cache/guile
#+END_SRC

I started Emacs using =emacs -Q=.

#+BEGIN_SRC elisp
(require 'geiser-guile)
#+END_SRC

[[https://guix.gnu.org/manual/en/html_node/The-Perfect-Setup.html][This guide]] suggests adding the directory containing the guix source code to the Emacs variable =geiser-guile-load-path=. I cloned the guix repository to the directory =/my-storage/miscellaneous/source-code-popular/guix=, so I evaluated the sexp shown below:

#+BEGIN_SRC elisp
(add-to-list 'geiser-guile-load-path "/my-storage/miscellaneous/source-code-popular/guix")
#+END_SRC

I pressed =M-x geiser-guile RET=. The buffer =*Geiser Guile REPL*= was opened.

I evaluated the sexp shown below in the buffer =*Geiser Guile REPL*=.

#+BEGIN_SRC scheme
(use-modules (gnu packages))
#+END_SRC

There were many warnings, some of them were "Unbound variable" and "compilation of xyz failed". You can see the entire output below.

#+BEGIN_SRC text
GNU Guile 3.0.9
Copyright (C) 1995-2023 Free Software Foundation, Inc.

Guile comes with ABSOLUTELY NO WARRANTY; for details type `,show w'.
This program is free software, and you are welcome to redistribute it
under certain conditions; type `,show c' for details.

Enter `,help' for help.
scheme@(guile-user)> (use-modules (gnu packages))
;;; compiling /my-storage/miscellaneous/source-code-popular/guix/gnu/packages.scm
;;; compiling /my-storage/miscellaneous/source-code-popular/guix/guix/packages.scm
;;; compiling /my-storage/miscellaneous/source-code-popular/guix/guix/utils.scm
;;; compiling /my-storage/miscellaneous/source-code-popular/guix/guix/config.scm
;;; guix/config.scm:65:16: warning: possibly unbound variable `@GUIX_CHANNEL_URL@'
;;; guix/config.scm:66:16: warning: possibly unbound variable `@GUIX_CHANNEL_COMMIT@'
;;; guix/config.scm:67:16: warning: possibly unbound variable `@GUIX_CHANNEL_INTRODUCTION@'
;;; compiled /home/rodrigo/.cache/guile/ccache/3.0-LE-8-4.6/mnt/b2fe7d61-8df8-43c1-9891-d3ebbb878a15/miscellaneous/source-code-popular/guix/guix/config.scm.go
;;; WARNING: compilation of /my-storage/miscellaneous/source-code-popular/guix/guix/utils.scm failed:
;;; Unbound variable: @GUIX_CHANNEL_URL@
;;; compiling /my-storage/miscellaneous/source-code-popular/guix/guix/memoization.scm
;;; compiling /my-storage/miscellaneous/source-code-popular/guix/guix/profiling.scm
;;; compiled /home/rodrigo/.cache/guile/ccache/3.0-LE-8-4.6/mnt/b2fe7d61-8df8-43c1-9891-d3ebbb878a15/miscellaneous/source-code-popular/guix/guix/profiling.scm.go
;;; compiled /home/rodrigo/.cache/guile/ccache/3.0-LE-8-4.6/mnt/b2fe7d61-8df8-43c1-9891-d3ebbb878a15/miscellaneous/source-code-popular/guix/guix/memoization.scm.go
;;; compiling /my-storage/miscellaneous/source-code-popular/guix/guix/diagnostics.scm
;;; compiling /my-storage/miscellaneous/source-code-popular/guix/guix/colors.scm
;;; compiled /home/rodrigo/.cache/guile/ccache/3.0-LE-8-4.6/mnt/b2fe7d61-8df8-43c1-9891-d3ebbb878a15/miscellaneous/source-code-popular/guix/guix/colors.scm.go
;;; compiling /my-storage/miscellaneous/source-code-popular/guix/guix/i18n.scm
;;; compiled /home/rodrigo/.cache/guile/ccache/3.0-LE-8-4.6/mnt/b2fe7d61-8df8-43c1-9891-d3ebbb878a15/miscellaneous/source-code-popular/guix/guix/i18n.scm.go
;;; WARNING: compilation of /my-storage/miscellaneous/source-code-popular/guix/guix/diagnostics.scm failed:
;;; Unbound variable: trivial-format-string?
;;; compiling /my-storage/miscellaneous/source-code-popular/guix/guix/build/utils.scm
;;; compiled /home/rodrigo/.cache/guile/ccache/3.0-LE-8-4.6/mnt/b2fe7d61-8df8-43c1-9891-d3ebbb878a15/miscellaneous/source-code-popular/guix/guix/build/utils.scm.go
;;; Failed to autoload make-zlib-input-port in (zlib):
;;; no code for module (zlib)
;;; Failed to autoload make-zlib-input-port in (zlib):
;;; no code for module (zlib)
;;; Failed to autoload make-zlib-output-port in (zlib):
;;; no code for module (zlib)
;;; Failed to autoload make-zlib-output-port in (zlib):
;;; no code for module (zlib)
;;; compiling /my-storage/miscellaneous/source-code-popular/guix/guix/read-print.scm
;;; compiled /home/rodrigo/.cache/guile/ccache/3.0-LE-8-4.6/mnt/b2fe7d61-8df8-43c1-9891-d3ebbb878a15/miscellaneous/source-code-popular/guix/guix/read-print.scm.go
;;; WARNING: compilation of /my-storage/miscellaneous/source-code-popular/guix/guix/packages.scm failed:
;;; Unbound variable: %system
;;; compiling /my-storage/miscellaneous/source-code-popular/guix/guix/records.scm
;;; compiled /home/rodrigo/.cache/guile/ccache/3.0-LE-8-4.6/mnt/b2fe7d61-8df8-43c1-9891-d3ebbb878a15/miscellaneous/source-code-popular/guix/guix/records.scm.go
;;; compiling /my-storage/miscellaneous/source-code-popular/guix/guix/store.scm
;;; compiling /my-storage/miscellaneous/source-code-popular/guix/guix/deprecation.scm
;;; compiled /home/rodrigo/.cache/guile/ccache/3.0-LE-8-4.6/mnt/b2fe7d61-8df8-43c1-9891-d3ebbb878a15/miscellaneous/source-code-popular/guix/guix/deprecation.scm.go
;;; compiling /my-storage/miscellaneous/source-code-popular/guix/guix/serialization.scm
;;; compiled /home/rodrigo/.cache/guile/ccache/3.0-LE-8-4.6/mnt/b2fe7d61-8df8-43c1-9891-d3ebbb878a15/miscellaneous/source-code-popular/guix/guix/serialization.scm.go
;;; compiling /my-storage/miscellaneous/source-code-popular/guix/guix/monads.scm
;;; compiled /home/rodrigo/.cache/guile/ccache/3.0-LE-8-4.6/mnt/b2fe7d61-8df8-43c1-9891-d3ebbb878a15/miscellaneous/source-code-popular/guix/guix/monads.scm.go
;;; compiling /my-storage/miscellaneous/source-code-popular/guix/guix/base16.scm
;;; compiled /home/rodrigo/.cache/guile/ccache/3.0-LE-8-4.6/mnt/b2fe7d61-8df8-43c1-9891-d3ebbb878a15/miscellaneous/source-code-popular/guix/guix/base16.scm.go
;;; compiling /my-storage/miscellaneous/source-code-popular/guix/guix/base32.scm
;;; compiled /home/rodrigo/.cache/guile/ccache/3.0-LE-8-4.6/mnt/b2fe7d61-8df8-43c1-9891-d3ebbb878a15/miscellaneous/source-code-popular/guix/guix/base32.scm.go
;;; Failed to autoload sha256 in (gcrypt hash):
;;; no code for module (gcrypt hash)
;;; Failed to autoload sha256 in (gcrypt hash):
;;; no code for module (gcrypt hash)
;;; Failed to autoload sha256 in (gcrypt hash):
;;; no code for module (gcrypt hash)
;;; compiling /my-storage/miscellaneous/source-code-popular/guix/guix/build/syscalls.scm
;;; guix/build/syscalls.scm:748:30: warning: possibly unbound variable `RB_AUTOBOOT'
;;; guix/build/syscalls.scm:1828:17: warning: possibly unbound variable `network-interface-flags'
;;; guix/build/syscalls.scm:1830:30: warning: possibly unbound variable `IFF_LOOPBACK'
;;; guix/build/syscalls.scm:1837:30: warning: possibly unbound variable `IFF_RUNNING'
;;; guix/build/syscalls.scm:1844:25: warning: possibly unbound variable `IFF_NOARP'
;;; guix/build/syscalls.scm:1936:9: warning: possibly unbound variable `set-network-interface-address'
;;; guix/build/syscalls.scm:1937:9: warning: possibly unbound variable `set-network-interface-flags'
;;; guix/build/syscalls.scm:1952:53: warning: possibly unbound variable `IFF_UP'
;;; compiled /home/rodrigo/.cache/guile/ccache/3.0-LE-8-4.6/mnt/b2fe7d61-8df8-43c1-9891-d3ebbb878a15/miscellaneous/source-code-popular/guix/guix/build/syscalls.scm.go
;;; Failed to autoload sha256 in (gcrypt hash):
;;; no code for module (gcrypt hash)
;;; Failed to autoload sha256 in (gcrypt hash):
;;; no code for module (gcrypt hash)
;;; guix/store.scm:1925:0: warning: shadows previous definition of `#{ mapm %store-monad instance}#' at guix/store.scm:1925:0
;;; guix/store.scm:1925:0: warning: shadows previous definition of `#{ sequence %store-monad instance}#' at guix/store.scm:1925:0
;;; guix/store.scm:1925:0: warning: shadows previous definition of `#{ anym %store-monad instance}#' at guix/store.scm:1925:0
;;; guix/store.scm:1925:0: warning: shadows previous definition of `#{ foldm %store-monad instance}#' at guix/store.scm:1925:0
;;; Failed to autoload sha256 in (gcrypt hash):
;;; no code for module (gcrypt hash)
;;; Failed to autoload sha256 in (gcrypt hash):
;;; no code for module (gcrypt hash)
;;; Failed to autoload sha256 in (gcrypt hash):
;;; no code for module (gcrypt hash)
;;; Failed to autoload sha256 in (gcrypt hash):
;;; no code for module (gcrypt hash)
;;; Failed to autoload sha256 in (gcrypt hash):
;;; no code for module (gcrypt hash)
;;; Failed to autoload sha256 in (gcrypt hash):
;;; no code for module (gcrypt hash)
;;; Failed to autoload sha256 in (gcrypt hash):
;;; no code for module (gcrypt hash)
;;; guix/store.scm:2278:13: warning: possibly unbound variable `sha256'
;;; Failed to autoload sha256 in (gcrypt hash):
;;; no code for module (gcrypt hash)
;;; Failed to autoload sha256 in (gcrypt hash):
;;; no code for module (gcrypt hash)
;;; Failed to autoload sha256 in (gcrypt hash):
;;; no code for module (gcrypt hash)
;;; compiled /home/rodrigo/.cache/guile/ccache/3.0-LE-8-4.6/mnt/b2fe7d61-8df8-43c1-9891-d3ebbb878a15/miscellaneous/source-code-popular/guix/guix/store.scm.go
;;; WARNING: compilation of /my-storage/miscellaneous/source-code-popular/guix/gnu/packages.scm failed:
;;; Unbound variable: %state-directory
;;; compiling /my-storage/miscellaneous/source-code-popular/guix/guix/ui.scm
;;; compiling /my-storage/miscellaneous/source-code-popular/guix/guix/gexp.scm
;;; compiling /my-storage/miscellaneous/source-code-popular/guix/guix/derivations.scm
;;; compiling /my-storage/miscellaneous/source-code-popular/guix/guix/combinators.scm
;;; compiled /home/rodrigo/.cache/guile/ccache/3.0-LE-8-4.6/mnt/b2fe7d61-8df8-43c1-9891-d3ebbb878a15/miscellaneous/source-code-popular/guix/guix/combinators.scm.go
;;; compiling /my-storage/miscellaneous/source-code-popular/guix/guix/sets.scm
;;; compiled /home/rodrigo/.cache/guile/ccache/3.0-LE-8-4.6/mnt/b2fe7d61-8df8-43c1-9891-d3ebbb878a15/miscellaneous/source-code-popular/guix/guix/sets.scm.go
;;; Failed to autoload sha256 in (gcrypt hash):
;;; no code for module (gcrypt hash)
;;; Failed to autoload sha256 in (gcrypt hash):
;;; no code for module (gcrypt hash)
;;; Failed to autoload sha256 in (gcrypt hash):
;;; no code for module (gcrypt hash)
;;; Failed to autoload sha256 in (gcrypt hash):
;;; no code for module (gcrypt hash)
;;; Failed to autoload sha256 in (gcrypt hash):
;;; no code for module (gcrypt hash)
;;; Failed to autoload sha256 in (gcrypt hash):
;;; no code for module (gcrypt hash)
;;; Failed to autoload sha256 in (gcrypt hash):
;;; no code for module (gcrypt hash)
;;; Failed to autoload sha256 in (gcrypt hash):
;;; no code for module (gcrypt hash)
;;; Failed to autoload sha256 in (gcrypt hash):
;;; no code for module (gcrypt hash)
;;; Failed to autoload sha256 in (gcrypt hash):
;;; no code for module (gcrypt hash)
;;; Failed to autoload sha256 in (gcrypt hash):
;;; no code for module (gcrypt hash)
;;; Failed to autoload sha256 in (gcrypt hash):
;;; no code for module (gcrypt hash)
;;; guix/store.scm:296:20: warning: possibly unbound variable `<substitutable>'
;;; guix/derivations.scm:391:33: warning: possibly unbound variable `%substitutable-references-procedure'
;;; Failed to autoload sha256 in (gcrypt hash):
;;; no code for module (gcrypt hash)
;;; guix/derivations.scm:776:8: warning: possibly unbound variable `sha256'
;;; Failed to autoload sha256 in (gcrypt hash):
;;; no code for module (gcrypt hash)
;;; guix/derivations.scm:1270:2: warning: possibly unbound variable `gexp->derivation'
;;; Failed to autoload sha256 in (gcrypt hash):
;;; no code for module (gcrypt hash)
;;; Failed to autoload sha256 in (gcrypt hash):
;;; no code for module (gcrypt hash)
;;; compiled /home/rodrigo/.cache/guile/ccache/3.0-LE-8-4.6/mnt/b2fe7d61-8df8-43c1-9891-d3ebbb878a15/miscellaneous/source-code-popular/guix/guix/derivations.scm.go
;;; WARNING: compilation of /my-storage/miscellaneous/source-code-popular/guix/guix/gexp.scm failed:
;;; Unbound variable: &store-error
;;; WARNING: compilation of /my-storage/miscellaneous/source-code-popular/guix/guix/ui.scm failed:
;;; Unbound variable: <derivation>
;;; compiling /my-storage/miscellaneous/source-code-popular/guix/guix/profiles.scm
;;; compiling /my-storage/miscellaneous/source-code-popular/guix/guix/search-paths.scm
;;; compiled /home/rodrigo/.cache/guile/ccache/3.0-LE-8-4.6/mnt/b2fe7d61-8df8-43c1-9891-d3ebbb878a15/miscellaneous/source-code-popular/guix/guix/search-paths.scm.go
;;; compiling /my-storage/miscellaneous/source-code-popular/guix/guix/modules.scm
;;; compiled /home/rodrigo/.cache/guile/ccache/3.0-LE-8-4.6/mnt/b2fe7d61-8df8-43c1-9891-d3ebbb878a15/miscellaneous/source-code-popular/guix/guix/modules.scm.go
;;; WARNING: compilation of /my-storage/miscellaneous/source-code-popular/guix/guix/profiles.scm failed:
;;; guix/profiles.scm:468:14: Unknown # object: "#~"
While compiling expression:
/my-storage/miscellaneous/source-code-popular/guix/guix/profiles.scm:468:14: Unknown # object: "#~"
scheme@(guile-user)> 
#+END_SRC

I could not call =specifications->packages=.

#+BEGIN_SRC text
scheme@(guile-user)> (specifications->packages (list "emacs"))
;;; <stdin>:11:1: warning: possibly unbound variable `specifications->packages'
ice-9/boot-9.scm:1685:16: In procedure raise-exception:
Unbound variable: specifications->packages

Entering a new prompt.  Type `,bt' for a backtrace or `,q' to continue.
scheme@(guile-user) [1]> 
#+END_SRC

* Question

When writing a Guile script that uses guix modules in Emacs, how to evaluate the sexp at point and show its result in the minibuffer?


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-10-07  3:38 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-07  3:37 [beginner's question] How to write Guix scripts using GNU Emacs? Rodrigo Morales

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).