Subject: Re: [PATCH] home: services: Add 'home-sway-service-type'.

From: "pelzflorian (Florian Pelz)" <[email-masked]>
Date: Fri, 04 Oct 2024 22:17:20 +0200

Hello Arnaud.  I like a lot your sway-menu.scm.  For testing, I’ve
changed

(define sway-menu
  (computed-file
   "sway-menu.scm"

to

(define sway-menu
  (scheme-file
   "sway-menu.scm"

to use it like this:

(sway-configuration
 (variables
  `((menu  . ,#~(string-append
                 "guile " #$sway-menu))

Sorry for having proposed compiled-file previously.  At first I had
thought a compiled sway-menu.go would be appropriate, created in a
computed-file, which invokes `guild compile` on the .scm code, but
apparently this is not useful.  I do not know enough here and
gnu/services/shepherd.scm does it in the scm->go procedure.

Anyway, some feedback:

> (define (directory->files dir)
>   (define (executable-file? f)
>     ;; Cf. `(@@ (guix build utils) executable-file?)' for an
>     ;; explanation of `(zero? ...)'.

This is a comment anyway, but one @ in (@ (guix build utils)
executable-file?) would be enough, since the executable-file?
predicate is exported.

>     (and=> (stat f)
>            (lambda (s)

To reduce clutter in the wmenu suggestions more, I’d prefer

(and=> (and (not (eq? (string-ref f 0) #\.))
            (stat f))
       (lambda (s)

>              (not (or (zero? (logand (stat:mode s) #o100))
>                       (eq? (stat:type s) 'directory))))))
>   (with-directory-excursion dir
>     (scandir "." executable-file?)))
> 
> (let ((path (string-append (getenv "HOME")
>                            "/.guix-home/profile/bin"))
>       (wmenu #$(file-append wmenu "/bin/wmenu"))
>       (swaymsg #$(file-append sway "/bin/swaymsg")))
>   (receive (from to pid)
>       ((@@ (ice-9 popen) open-process) OPEN_BOTH wmenu)

Better use @ instead of @@.

>     (for-each
>      (lambda (c) (format to "~a~%" c))
>      (directory->files path))
>     (close to)
>     (let ((choice (read-line from)))
>       (close from)
>       (waitpid pid)
>       (execl swaymsg swaymsg "exec"
>              (string-append path "/" choice))))))))

Even though I like to get suggestions only for
~/.guix-home/profile/bin, if you do not prepend path,

(execl swaymsg swaymsg "exec"
       choice)))))))

then it will remain possible to write shell commands in wmenu such as

guix shell weston -- weston-flower

to run apps without installing them.

Thank you greatly, this will definitely become my menu and in my
opinion it is the best default.

Since you told me about wmenu-run, I also locally updated wmenu [1]
and tested the menu config

(menu  .  ,#~(string-append
             #$wmenu "/bin/wmenu-run"))

which would also work, but in my opinion the suggestions are better
when tied to .guix-home/profile.  The wmenu-run does not use exec but
a protocol called XDG_ACTIVATION_TOKEN.  But I do not see an advantage
to it.  It behaves like always.

I’d welcome if you, Arnaud, sent a patch calling your sway-menu script.

Also I’d be happy if more careful commiters would push it; I prefer to
restrict my commits to translation updates.

Also one more thing, in the commit message, you meant to write
flatmap instead of flatten.

Regards,
Florian

[1]
diff --git a/gnu/packages/wm.scm b/gnu/packages/wm.scm
index 38cb8cc717..9615054841 100644
--- a/gnu/packages/wm.scm
+++ b/gnu/packages/wm.scm
@@ -1865,16 +1865,16 @@ (define-public wl-mirror
 (define-public wmenu
   (package
     (name "wmenu")
-    (version "0.1.7")
+    (version "0.1.9")
     (source (origin
               (method git-fetch)
               (uri (git-reference
                     (url "https://git.sr.ht/~adnano/wmenu")
-                    (commit version)))
+                    (commit "12b8f83be447379eded03c6109fe944945cd48aa")))
               (file-name (git-file-name name version))
               (sha256
                (base32
-                "0wjn68r5cx4zvw7sby6sk2ip5h4fn0jbgb1nasm9nsgjpv63pnpm"))))
+                "06fgvss3grihm3a1g6pj99rvjq2y2p496gkr2ahcnia7vn0wpc6y"))))
     (build-system meson-build-system)
     (native-inputs (append (if (%current-target-system)
                                ;; for wayland-scanner