Ludovic Courtès <[email protected]> writes:

> 宋文武 <[email protected]> skribis:
>
>> * gnu/services/xorg.scm (%default-xsessions): New variable.
>>   (xsessions-directory): New procedure.
>>   (slim-service): Add #:sessions parameter.
>>   [slim.cfg]: Honor #:sessions.
>>   (xinitrc): Adjust accordingly.
>
> Nice!
>
>> -        ;; Then try a pre-configured session type.
>> -        (let ((ratpoison (string-append #$ratpoison "/bin/ratpoison"))
>> -              (wmaker    (string-append #$windowmaker "/bin/wmaker")))
>> -          (match (command-line)
>> -            ((_ "ratpoison")
>> -             (exec-from-login-shell ratpoison))
>> -            (_
>> -             (exec-from-login-shell wmaker))))))
>> -
>> +        ;; Then run the selected session.
>> +        (exec-from-login-shell (cadr command-line))))
>
> Please keep ‘match’ instead of ‘cadr’.
OK.
>
> Also, the line above should be (cadr (command-line)) instead of (cadr
> command-line).
>
> Lastly, there’s a problem when #:auto-login? is #t because
> (command-line) returns a 1-element list.  This will be naturally fixed
> when the ‘match’ form above is reinstated.
Thanks for pointing out.

I want to make this auto-login-session configurable too, so I endup
with add it as a parameter to slim-service.
>
>> +(define %default-xsessions
>> +  (list (text-file* "wmaker.desktop" "
>
> Add a comment below ‘%default-xsessions’, like
>
>   ;; List of monadic values denoting for .desktop files blah blah
>
>> +(define (xsessions-directory sessions)
>> +  "Return a directory contains SESSIONS, which should be a list of monadic
>
> s/contains/containing/
>
> Other than that, it looks fine to me.  Could you send an updated
> version?
>From 144bf00b86f6884615d986598ccc62a3c4747eef Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=AE=8B=E6=96=87=E6=AD=A6?= <[email protected]>
Date: Tue, 16 Dec 2014 00:21:46 +0800
Subject: [PATCH] services: xorg: Make SLiM sessions configurable.

* gnu/services/xorg.scm (%default-xsessions): New variable.
  (xsessions-directory): New procedure.
  (slim-service): Add #:sessions and #:auto-login-session parameters.
  [slim.cfg]: Honor #:sessions.
  (xinitrc): Adjust accordingly.
---
 gnu/services/xorg.scm | 71 ++++++++++++++++++++++++++++++++++++---------------
 1 file changed, 50 insertions(+), 21 deletions(-)

diff --git a/gnu/services/xorg.scm b/gnu/services/xorg.scm
index fbf96c7..37f3753 100644
--- a/gnu/services/xorg.scm
+++ b/gnu/services/xorg.scm
@@ -36,7 +36,7 @@
   #:use-module (srfi srfi-26)
   #:use-module (ice-9 match)
   #:export (xorg-start-command
-
+            %default-xsessions
             %default-slim-theme
             %default-slim-theme-name
             slim-service))
@@ -136,9 +136,10 @@ EndSection
 
 (define* (xinitrc #:key
                   (guile (canonical-package guile-2.0))
-                  (ratpoison ratpoison)
-                  (windowmaker windowmaker))
-  "Return a system-wide xinitrc script that starts the specified X session."
+                  fallback-session)
+  "Return a system-wide xinitrc script that starts the specified X session,
+which should be passed to this script as the first argument.  If not, the
+FALLBACK-SESSION will be used."
   (define builder
     #~(begin
         (use-modules (ice-9 match))
@@ -155,20 +156,14 @@ EndSection
               (execl shell shell "--login" "-c"
                      (string-join (cons command args))))))
 
-        ;; First, try to run ~/.xsession.
-        (let* ((home     (getenv "HOME"))
-               (xsession (string-append home "/.xsession")))
-          (exec-from-login-shell xsession))
-
-        ;; Then try a pre-configured session type.
-        (let ((ratpoison (string-append #$ratpoison "/bin/ratpoison"))
-              (wmaker    (string-append #$windowmaker "/bin/wmaker")))
-          (match (command-line)
-            ((_ "ratpoison")
-             (exec-from-login-shell ratpoison))
-            (_
-             (exec-from-login-shell wmaker))))))
-
+        (let ((home (getenv "HOME"))
+              (session (match (command-line)
+                         ((_ x) x)
+                         (_     #$fallback-session))))
+          ;; First, try to run ~/.xinitrc with the specified session.
+          (exec-from-login-shell (string-append home "/.xinitrc") session)
+          ;; Then starts the specified session directly.
+          (exec-from-login-shell session))))
   (gexp->script "xinitrc" builder))
 

@@ -176,6 +171,35 @@ EndSection
 ;;; SLiM log-in manager.
 ;;;
 
+(define %default-xsessions
+  ;; Default xsessions available for log-in manager, representing as a list of
+  ;; monadic desktop entries.
+  (list (text-file* "wmaker.desktop" "
+[Desktop Entry]
+Name=Window Maker
+Exec=" windowmaker "/bin/wmaker
+Type=Application
+")
+        (text-file* "ratpoison.desktop" "
+[Desktop Entry]
+Name=Ratpoison
+Exec=" ratpoison "/bin/ratpoison
+Type=Application
+")))
+
+(define (xsessions-directory sessions)
+  "Return a directory containing SESSIONS, which should be a list of monadic
+desktop entries."
+  (mlet %store-monad ((sessions (sequence %store-monad sessions)))
+    (define builder
+      #~(begin
+          (mkdir #$output)
+          (for-each (lambda (session)
+                      (symlink session (string-append #$output "/"
+                                                      (basename session))))
+                    '#$sessions)))
+    (gexp->derivation "xsessions-dir" builder)))
+
 (define %default-slim-theme
   ;; Theme based on work by Felipe López.
   #~(string-append #$%artwork-repository "/slim"))
@@ -191,6 +215,9 @@ EndSection
                        (theme %default-slim-theme)
                        (theme-name %default-slim-theme-name)
                        (xauth xauth) (dmd dmd) (bash bash)
+                       (sessions %default-xsessions)
+                       (auto-login-session #~(string-append #$windowmaker
+                                                            "/bin/wmaker"))
                        startx)
   "Return a service that spawns the SLiM graphical login manager, which in
 turn starts the X display server with @var{startx}, a command as returned by
@@ -198,7 +225,7 @@ turn starts the X display server with @var{startx}, a command as returned by
 
 When @var{allow-empty-passwords?} is true, allow logins with an empty
 password.  When @var{auto-login?} is true, log in automatically as
-@var{default-user}.
+@var{default-user} with @var{auto-login-session}.
 
 If @var{theme} is @code{#f}, the use the default log-in theme; otherwise
 @var{theme} must be a gexp denoting the name of a directory containing the
@@ -207,7 +234,9 @@ theme."
 
   (define (slim.cfg)
     (mlet %store-monad ((startx  (or startx (xorg-start-command)))
-                        (xinitrc (xinitrc)))
+                        (xinitrc (xinitrc #:fallback-session
+                                          auto-login-session))
+                        (sessiondir (xsessions-directory sessions)))
       (text-file* "slim.cfg"  "
 default_path /run/current-system/profile/bin
 default_xserver " startx "
@@ -218,7 +247,7 @@ authfile /var/run/slim.auth
 # The login command.  '%session' is replaced by the chosen session name, one
 # of the names specified in the 'sessions' setting: 'wmaker', 'xfce', etc.
 login_cmd  exec " xinitrc " %session
-sessions   wmaker,ratpoison
+sessiondir " sessiondir "
 
 halt_cmd " dmd "/sbin/halt
 reboot_cmd " dmd "/sbin/reboot
-- 
2.1.2

In additation, I pass session to ~/.xinitrc (replace ~/.xsession, since
it's what to expect from slim according to [1][2]).

So user can use ~/.xinitrc to custom the selected session:

  #!/bin/sh
  export LANG=zh_CN.UTF-8
  setxkbmap dvorak
  
  exec $1

[1] https://wiki.archlinux.org/index.php/Slim#Environments
[2] https://lists.gnu.org/archive/html/guix-devel/2014-12/msg00282.html

>
> Thanks!
>
> Ludo’.

Reply via email to