[bug#33753,1/3] gnu: Add stumpwm-contrib.

Message ID 20181215020600.2713-1-namn@berkeley.edu
State Accepted
Headers show
Series [bug#33753,1/3] gnu: Add stumpwm-contrib. | expand

Checks

Context Check Description
cbaines/applying patch success Successfully applied
cbaines/applying patch success Successfully applied
cbaines/applying patch success Successfully applied

Commit Message

Nam Nguyen Dec. 15, 2018, 2:06 a.m. UTC
* gnu/packages/lisp.scm (stumpwm-contrib): New variable.
---
 gnu/packages/lisp.scm | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

Comments

Nam Nguyen Dec. 15, 2018, 2:50 a.m. UTC | #1
I am trying to make stumpwm-contrib less of a "grab bag" and more modular
and well-tested by breaking all the stumpwm extensions/modules into
separate recipes.

stumpwm-contrib deletes the source code and child
recipes copies their source code from their directory to
$(out)/share/common-lisp/stumpwm-contrib.

To test this, install stumpwm and stumpwm-cpu.

~/.stumpwmrc
********************************************************************************
(set-module-dir "~/.guix-profile/share/common-lisp/sbcl-bundle-systems")
(load-module "cpu")

(setf *screen-mode-line-format* '("%c %C %t %f [%n] %W"))

;; %c (CPU usage as %)
;; %C (CPU usage as bar graph)
;; %t (CPU temperature)
;; %f (CPU frequency)
********************************************************************************

To toggle the mode-line:
C-t semicolon mode-line <RET>

I violated the "Don't Repeat Yourself" (DRY) principle and have
stumpwm-{battery-portable,cpu,mem,pinentry,winner-mode} all tested and
working. I will postpone submission of those until stumpwm-cpu has been
accepted. All these submodules are nearly identical with only different
cat and mod variables. pinentry has some additional inputs. This results
in a lot of repeated code that looks nearly identical to stumpwm-cpu.

Another concern I had was for ~/.stumpwmrc, including sbcl-bundle-systems
(which contains symlinks to the compiled code) is necessary for
stumpwm-pinentry to work correctly. The other plugins can just use the
stumpwm-contrib directory I created.

;; (set-module-dir "~/.guix-profile/share/common-lisp/stumpwm-contrib")
(set-module-dir "~/.guix-profile/share/common-lisp/sbcl-bundle-systems")

Documentation (org-mode files) can be found in the stumpwm-contrib
directory.

Here is the general directory structure:
********************************************************************************
/home/user/.guix-profile/share/common-lisp:
 .
 ..
 sbcl-bundle-systems
 stumpwm-contrib

/home/user/.guix-profile/share/common-lisp/sbcl-bundle-systems:
 .
 ..
 battery-portable.asd -> /gnu/store/...-stumpwm-battery-portable-0.0.1-1.bd47cec/share/common-lisp/sbcl-bundle-systems/battery-portable.asd
 cpu.asd -> /gnu/store/...-stumpwm-cpu-0.0.1-1.bd47cec/share/common-lisp/sbcl-bundle-systems/cpu.asd
 mem.asd -> /gnu/store/...-stumpwm-mem-0.0.1-1.bd47cec/share/common-lisp/sbcl-bundle-systems/mem.asd
 pinentry.asd -> /gnu/store/...-stumpwm-pinentry-0.0.1-1.bd47cec/share/common-lisp/sbcl-bundle-systems/pinentry.asd
 swm-gaps.asd -> /gnu/store/...-stumpwm-gaps-0.0.1-1.bd47cec/share/common-lisp/sbcl-bundle-systems/swm-gaps.asd
 winner-mode.asd -> /gnu/store/...-stumpwm-winner-mode-0.0.1-1.bd47cec/share/common-lisp/sbcl-bundle-systems/winner-mode.asd

/home/user/.guix-profile/share/common-lisp/stumpwm-contrib:
 .
 ..
 battery-portable -> /gnu/store/...-stumpwm-battery-portable-0.0.1-1.bd47cec/share/common-lisp/stumpwm-contrib/battery-portable
 cpu -> /gnu/store/...-stumpwm-cpu-0.0.1-1.bd47cec/share/common-lisp/stumpwm-contrib/cpu
 mem -> /gnu/store/...-stumpwm-mem-0.0.1-1.bd47cec/share/common-lisp/stumpwm-contrib/mem
 pinentry -> /gnu/store/...-stumpwm-pinentry-0.0.1-1.bd47cec/share/common-lisp/stumpwm-contrib/pinentry
 swm-gaps -> /gnu/store/...-stumpwm-gaps-0.0.1-1.bd47cec/share/common-lisp/stumpwm-contrib/swm-gaps
 winner-mode -> /gnu/store/...-stumpwm-winner-mode-0.0.1-1.bd47cec/share/common-lisp/stumpwm-contrib/winner-mode

/home/user/.guix-profile/share/common-lisp/stumpwm-contrib/cpu:
 .
 ..
 cpu.asd
 cpu.lisp
 package.lisp
 README.org
********************************************************************************

Summary of questions:
1. Should the entire repository be bundled together instead of breaking
it into individual modules?
2. Should asdf-build-system/source be used instead of sbcl?  I had initially
copied the entire repository with all the source code, and it still worked.
3. Is there a way to by more DRY?
4. Should the stumpwm-contrib directory be named sbcl-sources (can't
recall the default directory of asdf-build-system/source)?
Ludovic Courtès Dec. 21, 2018, 5:06 p.m. UTC | #2
Hello!

Pierre, Chris: could you provide feedback to Nam?  I don’t use Stump
(yet!) so I wouldn’t know what to suggest.

  https://issues.guix.info/issue/33753

Thanks,
Ludo’.

Nam Nguyen <namn@berkeley.edu> skribis:

> I am trying to make stumpwm-contrib less of a "grab bag" and more modular
> and well-tested by breaking all the stumpwm extensions/modules into
> separate recipes.
>
> stumpwm-contrib deletes the source code and child
> recipes copies their source code from their directory to
> $(out)/share/common-lisp/stumpwm-contrib.
>
> To test this, install stumpwm and stumpwm-cpu.
>
> ~/.stumpwmrc
> ********************************************************************************
> (set-module-dir "~/.guix-profile/share/common-lisp/sbcl-bundle-systems")
> (load-module "cpu")
>
> (setf *screen-mode-line-format* '("%c %C %t %f [%n] %W"))
>
> ;; %c (CPU usage as %)
> ;; %C (CPU usage as bar graph)
> ;; %t (CPU temperature)
> ;; %f (CPU frequency)
> ********************************************************************************
>
> To toggle the mode-line:
> C-t semicolon mode-line <RET>
>
> I violated the "Don't Repeat Yourself" (DRY) principle and have
> stumpwm-{battery-portable,cpu,mem,pinentry,winner-mode} all tested and
> working. I will postpone submission of those until stumpwm-cpu has been
> accepted. All these submodules are nearly identical with only different
> cat and mod variables. pinentry has some additional inputs. This results
> in a lot of repeated code that looks nearly identical to stumpwm-cpu.
>
> Another concern I had was for ~/.stumpwmrc, including sbcl-bundle-systems
> (which contains symlinks to the compiled code) is necessary for
> stumpwm-pinentry to work correctly. The other plugins can just use the
> stumpwm-contrib directory I created.
>
> ;; (set-module-dir "~/.guix-profile/share/common-lisp/stumpwm-contrib")
> (set-module-dir "~/.guix-profile/share/common-lisp/sbcl-bundle-systems")
>
> Documentation (org-mode files) can be found in the stumpwm-contrib
> directory.
>
> Here is the general directory structure:
> ********************************************************************************
> /home/user/.guix-profile/share/common-lisp:
>  .
>  ..
>  sbcl-bundle-systems
>  stumpwm-contrib
>
> /home/user/.guix-profile/share/common-lisp/sbcl-bundle-systems:
>  .
>  ..
>  battery-portable.asd -> /gnu/store/...-stumpwm-battery-portable-0.0.1-1.bd47cec/share/common-lisp/sbcl-bundle-systems/battery-portable.asd
>  cpu.asd -> /gnu/store/...-stumpwm-cpu-0.0.1-1.bd47cec/share/common-lisp/sbcl-bundle-systems/cpu.asd
>  mem.asd -> /gnu/store/...-stumpwm-mem-0.0.1-1.bd47cec/share/common-lisp/sbcl-bundle-systems/mem.asd
>  pinentry.asd -> /gnu/store/...-stumpwm-pinentry-0.0.1-1.bd47cec/share/common-lisp/sbcl-bundle-systems/pinentry.asd
>  swm-gaps.asd -> /gnu/store/...-stumpwm-gaps-0.0.1-1.bd47cec/share/common-lisp/sbcl-bundle-systems/swm-gaps.asd
>  winner-mode.asd -> /gnu/store/...-stumpwm-winner-mode-0.0.1-1.bd47cec/share/common-lisp/sbcl-bundle-systems/winner-mode.asd
>
> /home/user/.guix-profile/share/common-lisp/stumpwm-contrib:
>  .
>  ..
>  battery-portable -> /gnu/store/...-stumpwm-battery-portable-0.0.1-1.bd47cec/share/common-lisp/stumpwm-contrib/battery-portable
>  cpu -> /gnu/store/...-stumpwm-cpu-0.0.1-1.bd47cec/share/common-lisp/stumpwm-contrib/cpu
>  mem -> /gnu/store/...-stumpwm-mem-0.0.1-1.bd47cec/share/common-lisp/stumpwm-contrib/mem
>  pinentry -> /gnu/store/...-stumpwm-pinentry-0.0.1-1.bd47cec/share/common-lisp/stumpwm-contrib/pinentry
>  swm-gaps -> /gnu/store/...-stumpwm-gaps-0.0.1-1.bd47cec/share/common-lisp/stumpwm-contrib/swm-gaps
>  winner-mode -> /gnu/store/...-stumpwm-winner-mode-0.0.1-1.bd47cec/share/common-lisp/stumpwm-contrib/winner-mode
>
> /home/user/.guix-profile/share/common-lisp/stumpwm-contrib/cpu:
>  .
>  ..
>  cpu.asd
>  cpu.lisp
>  package.lisp
>  README.org
> ********************************************************************************
>
> Summary of questions:
> 1. Should the entire repository be bundled together instead of breaking
> it into individual modules?
> 2. Should asdf-build-system/source be used instead of sbcl?  I had initially
> copied the entire repository with all the source code, and it still worked.
> 3. Is there a way to by more DRY?
> 4. Should the stumpwm-contrib directory be named sbcl-sources (can't
> recall the default directory of asdf-build-system/source)?
Pierre Neidhardt Dec. 21, 2018, 6:18 p.m. UTC | #3
Hi Nam,

Well, I don't use StumpWM (I'm on EXWM) but I know the ASDF build system, so
maybe I can help a bit.

> : 1. Should the entire repository be bundled together instead of breaking
> : it into individual modules?

One package per .asd.

> : 2. Should asdf-build-system/source be used instead of sbcl?  I had initially
> : copied the entire repository with all the source code, and it still worked.

No, since StumpWM only supports sbcl, stick to the sbcl build system.

> : 3. Is there a way to by more DRY?

I haven't looked into the details, but you could probably use a a function /
macro to define those packages.
Lots of other packages do this, e.g. linux, gcc, clang, etc.

> : 4. Should the stumpwm-contrib directory be named sbcl-sources (can't
> : recall the default directory of asdf-build-system/source)?

Sorry, which directory exactly?
Nam Nguyen Dec. 24, 2018, 10:01 a.m. UTC | #4
Hi all,

> you could probably use a a function / macro to define those packages

Thank you for pointing me to examples. This helped me refactor.

> : 4. Should the stumpwm-contrib directory be named sbcl-sources (can't
> : recall the default directory of asdf-build-system/source)?

> Sorry, which directory exactly?

If I use asdf-build-system/source instead of sbcl I get the sources for
cpu stored in:
~/.guix-profile/share/common-lisp/source/cpu

Instead, I arbitrarily created stumpwm-contrib to store the sources:
~/.guix-profile/share/common-lisp/stumpwm-contrib/cpu

To rephrase question #4: Should I rename stumpwm-contrib to be "source"
to be more consistent with the "default" naming, or is stumpwm-contrib
sufficient?

As noted before, ~/.stumpwmrc will have to contain the precompiled code in:
(set-module-dir "~/.guix-profile/share/common-lisp/sbcl-bundle-systems")
in order to work with the more advanced plugins like pinentry.

AIUI, stumpwm-contrib/cpu contains the source code and documentation
org-mode files, and sbcl-bundle-systems contains the precompiled code.

This time, I included all the modules for review, as refactoring helped
to shorten the patches.
Pierre Neidhardt Dec. 24, 2018, 10:14 a.m. UTC | #5
> If I use asdf-build-system/source instead of sbcl I get the sources for
> cpu stored in:
> ~/.guix-profile/share/common-lisp/source/cpu

But you should not use asdf-build-system/source for StumpWM since it's not
supported by any Lisp other than SBCL, right?

> As noted before, ~/.stumpwmrc will have to contain the precompiled code in:
> (set-module-dir "~/.guix-profile/share/common-lisp/sbcl-bundle-systems")
> in order to work with the more advanced plugins like pinentry.

And then you would not need this line either if I'm not mistaken.

> AIUI,

What is AIUI? :/

> stumpwm-contrib/cpu contains the source code and documentation
> org-mode files, and sbcl-bundle-systems contains the precompiled code.

Both are included with asdf-build-system/sbcl.  Is this OK in this context?

Sorry, no time for testing at the moment.
Efraim Flashner Dec. 24, 2018, 10:20 a.m. UTC | #6
On Mon, Dec 24, 2018 at 11:14:20AM +0100, Pierre Neidhardt wrote:
> 
> > AIUI,
> 
> What is AIUI? :/
> 

as i understand it
Nam Nguyen Dec. 25, 2018, 9:01 a.m. UTC | #7
> Sorry, no time for testing at the moment.
No worries. Thanks for letting me know.

> Both are included with asdf-build-system/sbcl.  Is this OK in this context?

In this context, the entire repo is contained in sbcl-source. 
COPYING  media/  minor-mode/  modeline/  README.org  update-readme.sh  util/

I've resorted to a clunky way of deleting everything but the util/cpu
subdirectory that I care about retaining.
cp -r sbcl-source/util/cpu out/cpu
rm -rf sbcl-source
cp -r out/cpu sbcl-source/cpu

I have cleaned up the code a bit in these latest two patches so that
there is only one phase that does this. The directories look like so:

---8<------------------------------------------------------------
~/.guix-profile/share/common-lisp/sbcl-source$ ls
battery-portable  cpu  hostname  mem  pinentry  swm-gaps  winner-mode

~/.guix-profile/share/common-lisp/sbcl-bundle-systems$ ls
battery-portable.asd  cpu.asd  hostname.asd  mem.asd  pinentry.asd  swm-gaps.asd  winner-mode.asd
---8<------------------------------------------------------------

> (set-module-dir "~/.guix-profile/share/common-lisp/sbcl-bundle-systems")
> And then you would not need this line either if I'm not mistaken.

I referred to the documentation[1], and it seems that module-dir can be set.

In order not to set module-dir at runtime, perhaps the stumpwm recipe
can be configured[2] with the correct module-dir?

I suppose it would be more user-friendly to not have to use set-module-dir
and just use the modules directly (like how emacs works with guix). If
this is option is more desired, I can try configuring stumpwm and will
report back.

---8<------------------------------------------------------------
(defvar *load-path* nil
  "A list of paths in which modules can be found, by default it is
  populated by any asdf systems found in `*module-dir*' set from the
  configure script when StumpWM was built, or later by the user using
  `add-to-load-path'")
---8<------------------------------------------------------------

[1] https://github.com/stumpwm/stumpwm/wiki/Modules
[2] https://github.com/stumpwm/stumpwm/blob/master/module.lisp
Nam Nguyen Dec. 26, 2018, 7:13 a.m. UTC | #8
I did some investigating by querying within stumpwm.

C-t ; brings up a stumpwm prompt.
---8<------------------------------------------------------------
eval-line (print *module-dir*)

/gnu/store/...stumpwm-18.11-lib/.stumpwm.d/modules/
---8<------------------------------------------------------------

It seems to set *module-dir* at build time to be
/gnu/store/...stumpwm-18.11-lib/.stumpwm.d/modules/. However, this .stump.d
doesn't exist and it was created when stumpwm was compiled. There are
also potentially a FHS assumption with (getenv "HOME") and it happens to
evaluate to the /gnu/store item.

StumpWM gives option #1 of setting module-dir at build time of
StumpWM. I could try patching
---8<------------------------------------------------------------
> (pathname-as-directory (concat (getenv "HOME") "/.stumpwm.d/modules"))
---8<------------------------------------------------------------
in order to store the modules at some standard, system-wide location? Hard
coding it as /var/guix/profiles/per-user/user/guix-profile/share/common-lisp
is incorrect because guix won't build as the user. Maybe I can force stumpwm
and the stumpwm-contrib modules to use the same stumpwm library. This seems
tricky/impossible, though, since they are all individual modules.

StumpWM also offers option #2 of calling set-module-dir to set this
variable at run-time in ~/.stumpwmrc. This is how it currently works and
it seems more simple.
---8<-------------------  ~/.stumpwmrc --------------------------
(set-module-dir "~/.guix-profile/share/common-lisp/sbcl-bundle-systems")
---8<------------------------------------------------------------

*module-dir* is essentially a seed for *load-path*, which is where the
files like cpu.asd and cpu--system.fasl are. With the current setup,
load-path is populated correctly.
---8<------------------------------------------------------------
eval-line (print *load-path*)

/gnu/store/stumpwm-cpu/lib/sbcl/"
...
/gnu/store/stumpwm-mem/lib/sbcl/"
---8<------------------------------------------------------------

Option #3 is to use "add-to-load-path", but that seems similar to
Option #1. I suppose this is a matter of investigating how stumpwm
handles its modules/extensions. What I know thus far points me to err
toward setting module-dir at run-time, since it is a one-liner.

Relevant snippets from module.lisp
(https://github.com/stumpwm/stumpwm/blob/master/module.lisp)

---8<------------------------------------------------------------
(defvar *module-dir*
  (pathname-as-directory (concat (getenv "HOME") "/.stumpwm.d/modules"))
  "The location of the contrib modules on your system.")

(defun build-load-path (path)
  "Maps subdirectories of path, returning a list of all subdirs in the
  path which contain any files ending in .asd"
  ...

(defvar *load-path* nil
  "A list of paths in which modules can be found, by default it is
  populated by any asdf systems found in `*module-dir*' set from the
  configure script when StumpWM was built, or later by the user using
  `add-to-load-path'")

(defun set-module-dir (dir)
  "Sets the location of the for StumpWM to find modules"
  (when (stringp dir)
    (setf dir (pathname (concat dir "/"))))
  (setf *module-dir* dir)
  (init-load-path *module-dir*))
---8<------------------------------------------------------------
Pierre Neidhardt Dec. 27, 2018, 10:51 a.m. UTC | #9
OK, thanks for the details.  I'll look into this later.
Oleg Pykhalov March 23, 2020, 7:16 a.m. UTC | #10
Hello.  I wish to push the following if you don't mind.  We probably could
make a better solution later, but I think it's good enough for now.  WDYT?

This patch series allows you to use ttf-fonts module in StumpWM.

Oleg Pykhalov (3):
  gnu: Add sbcl-clx-truetype.
  gnu: emacs-stumpwm-mode: Update to 0.0.1-1.dd5b037.
  gnu: Add sbcl-stumpwm-ttf-fonts.

 doc/guix-cookbook.texi     | 41 +++++++++++++++++++++++++++++++++++++-
 gnu/packages/emacs-xyz.scm |  4 ++--
 gnu/packages/lisp-xyz.scm  | 35 ++++++++++++++++++++++++++++++++
 gnu/packages/wm.scm        | 33 +++++++++++++++++++++++++++++-
 4 files changed, 109 insertions(+), 4 deletions(-)

Patch

diff --git a/gnu/packages/lisp.scm b/gnu/packages/lisp.scm
index d1c0a2ef3..b9e6c0e42 100644
--- a/gnu/packages/lisp.scm
+++ b/gnu/packages/lisp.scm
@@ -12,6 +12,7 @@ 
 ;;; Copyright © 2018 Alex Vong <alexvong1995@gmail.com>
 ;;; Copyright © 2018 Pierre Neidhardt <mail@ambrevar.xyz>
 ;;; Copyright © 2018 Pierre Langlois <pierre.langlois@gmx.com>
+;;; Copyright © 2018 Nam Nguyen <namn@berkeley.edu>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -991,6 +992,41 @@  productive, customizable lisp based systems.")
     (inherit (sbcl-package->cl-source-package stumpwm))
     (name "cl-stumpwm")))
 
+(define stumpwm-contrib
+  (let ((commit "bd47cec14f7299711ac29468d2e1364d38a81bee")
+        (revision "1"))
+    (package
+      (name "stumpwm-contrib")
+      (version (git-version "0.0.1" revision commit))
+      (source
+       (origin
+         (method git-fetch)
+         (uri (git-reference
+               (url "https://github.com/stumpwm/stumpwm-contrib.git")
+               (commit commit)))
+         (file-name (string-append name "-" version "-checkout"))
+         (sha256
+          (base32 "0kh9vpmxssjvxgvl6ihpn0qh4l660n64iq80ivhagdvr8s045ddj"))))
+      (inputs
+       `(("stumpwm" ,stumpwm "lib")))
+      (build-system asdf-build-system/sbcl)
+      (arguments
+       '(#:phases
+         ;; Make stumpwm-contrib more modular.  Child modules must copy
+         ;; their source to $(out)/share/common-lisp/stumpwm-contrib.
+         (modify-phases %standard-phases
+           (add-after 'check 'delete-plugins
+             (lambda* (#:key outputs #:allow-other-keys)
+               (delete-file-recursively
+                (string-append (assoc-ref outputs "out")
+                               "/share/common-lisp/sbcl-source"))
+               #t)))))
+      (home-page "https://github.com/stumpwm/stumpwm-contrib")
+      (synopsis "Collection of StumpWM modules")
+      (description "Modules are a way to extend StumpWM using Lisp
+code.")
+      (license (list license:gpl2+ license:gpl3+ license:bsd-2)))))
+
 ;; The slynk that users expect to install includes all of slynk's contrib
 ;; modules.  Therefore, we build the base module and all contribs first; then
 ;; we expose the union of these as `sbcl-slynk'.  The following variable