[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Extending Guix without using the Guile load path

From: Ricardo Wurmus
Subject: Re: Extending Guix without using the Guile load path
Date: Sat, 31 Oct 2020 23:53:36 +0100
User-agent: mu4e 1.4.13; emacs 27.1

Ludovic Courtès <> writes:

> Hello!
> Ricardo Wurmus <> skribis:
>> I think it’s a bit difficult to install the Guix Workflow Language at
>> this point and I’d like to change that.
>> Currently, new sub-commands for Guix are looked up by module name on the
>> Guile load path.  When installing the “gwl” package, though, the Guile
>> load path is not automatically altered, so users need to set it up by
>> themselves.  The load path is only altered automatically when users
>> install the “guile” package.  This is not a good recommendation because
>> users may have Guile 2.2 in their profile, and not Guile 3.0 or whatever
>> version may be needed by the extension.
>> I wonder if we can make this a little nicer by letting Guix look for
>> sub-command scripts in directories that are listed in an environment
>> variable, such as GUIX_EXTENSIONS_PATH.  The “guix” package would set
>> this search path and packages wanting to provide a sub-command (such as
>> “guix workflow” or “guix home”) would arrange to have their scripts
>> placed in that sub-directory of their outputs.
>> What do you think?
> GUIX_EXTENSIONS_PATH sounds like a good idea.  I suppose it could be
> implemented pretty much like GUIX_PACKAGE_PATH?
> That would also allow us to consider Guix Home a package rather than a
> channel, like you did for GWL.

Below is a draft that adds Guile modules from GUIX_EXTENSIONS_PATH to
the %load-path and %load-compiled-path.

I think this implementation is not good, but I’d like to provoke some
comments about the following thoughts:

* what happens to the Guile dependencies of an extension?  Those would
  not be added to the load path.  Should the extension take care of this
  by manually augmenting the load path?

* The draft simply uses the same directories that GUILE_LOAD_PATH and
  GUILE_LOAD_COMPILED_PATH use.  Is this a bad idea?  Would it not be
  better to have a new directory prefix (such as “lib/guix/extensions”)?

* The search path on the “guix” package does not distinguish between
  compiled modules and source modules; it simply looks for all the
  conventional directories and puts them on the GUIX_EXTENSIONS_PATH,
  while (guix ui) adds them to both %load-path and %load-compiled-path.

All these points could be solved by only requiring the *entry points* to
be on the GUIX_EXTENSIONS_PATH.  Say for example that we have the
“workflows” extension (provided by the GWL), which is a Guile entry
point script at “libexec/guix/workflows.scm”.  That script would augment
the %load-path and %load-compiled-path with all its modules (in the
conventional Guile directories) and load the extension from those

What do you think?


>From a6bdaee8a8cf403ea0cc76426e595afc36c9f559 Mon Sep 17 00:00:00 2001
From: Ricardo Wurmus <>
Date: Sat, 31 Oct 2020 23:42:12 +0100

 gnu/packages/package-management.scm | 14 +++++++++++++-
 guix/ui.scm                         | 11 ++++++++++-
 2 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/gnu/packages/package-management.scm 
index 1c02c342b1..b6c03acf15 100644
--- a/gnu/packages/package-management.scm
+++ b/gnu/packages/package-management.scm
@@ -400,6 +400,12 @@ $(prefix)/etc/init.d\n")))
          ("guile-git" ,guile-git)
          ("guile-zlib" ,guile-zlib)
          ("guile-lzlib" ,guile-lzlib)))
+      (native-search-paths
+       (list (search-path-specification
+              (variable "GUIX_EXTENSIONS_PATH")
+              (files '("share/guile/site/3.0"
+                       "lib/guile/3.0/site-ccache"
+                       "share/guile/site/3.0")))))
       (home-page "";)
       (synopsis "Functional package manager for installed software packages 
and versions")
@@ -496,7 +502,13 @@ the Nix package manager.")
        ("guile-json" ,guile2.2-json)
        ("guile-sqlite3" ,guile2.2-sqlite3)
        ("guile-ssh" ,guile2.2-ssh)
-       ("guile-git" ,guile2.2-git)))))
+       ("guile-git" ,guile2.2-git)))
+    (native-search-paths
+     (list (search-path-specification
+            (variable "GUIX_EXTENSIONS_PATH")
+            (files '("share/guile/site/2.2"
+                     "lib/guile/2.2/site-ccache"
+                     "share/guile/site/2.2")))))))
 (define-public guile3.0-guix
   (deprecated-package "guile3.0-guix" guix))
diff --git a/guix/ui.scm b/guix/ui.scm
index 8d7bc238bc..8dbcbe0fd6 100644
--- a/guix/ui.scm
+++ b/guix/ui.scm
@@ -10,7 +10,7 @@
 ;;; Copyright © 2016 Roel Janssen <>
 ;;; Copyright © 2016 Benz Schenk <>
 ;;; Copyright © 2018 Kyle Meyer <>
-;;; Copyright © 2018 Ricardo Wurmus <>
+;;; Copyright © 2018, 2020 Ricardo Wurmus <>
 ;;; Copyright © 2019 Chris Marusich <>
 ;;; Copyright © 2019 Tobias Geerinckx-Rice <>
 ;;; Copyright © 2019 Simon Tournier <>
@@ -61,6 +61,7 @@
                         ;; Avoid "overrides core binding" warning.
   #:use-module (srfi srfi-1)
+  #:use-module (srfi srfi-2)
   #:use-module (srfi srfi-9 gnu)
   #:use-module (srfi srfi-11)
   #:use-module (srfi srfi-19)
@@ -2125,6 +2126,14 @@ Unlike 'guix-main', this procedure assumes that locale, 
i18n support,
 and signal handling have already been set up."
   (define option? (cut string-prefix? "-" <>))
+  (and-let* ((path (getenv "GUIX_EXTENSIONS_PATH"))
+             (not-colon (char-set-complement (char-set #\:)))
+             (extensions (string-tokenize path not-colon)))
+    (set! %load-path
+          (append extensions %load-path))
+    (set! %load-compiled-path
+          (append extensions %load-compiled-path)))
   ;; The default %LOAD-EXTENSIONS includes the empty string, which doubles the
   ;; number of 'stat' calls per entry in %LOAD-PATH.  Shamelessly remove it.
   (set! %load-extensions '(".scm"))

reply via email to

[Prev in Thread] Current Thread [Next in Thread]