[Top][All Lists]

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

Home service that serializes into an executable file

From: Mario Forzanini
Subject: Home service that serializes into an executable file
Date: Tue, 28 Mar 2023 22:53:24 +0200
User-agent: Gnus/5.13 (Gnus v5.13)

Hello everyone!

I've recently tried to write a simple home service that serializes into
an ~/.xsession file. As someone pointed out in an older message on this
list, this file has to be executable; I used to achieve this including
an external file like: (local-file "xsession" #recursive? #t). Is there
a procedure that allows changing permission bits while generating a file
in the store?

This is still in a rough state, but here is the definition of the

    (define (serialize-string field-name val) val)

    (define (string-join strings delimiter)
      (if (null? strings)
          (fold (lambda (s so-far) (string-append so-far delimiter s))
                (car strings)
                (cdr strings))))

    (define (xsession-serialize-program program args)
      (if (pair? program)
           (string-join (cons* "try" (cdr program) args) " ")
           (string-join (cons* "try" (package-name program) args) " ")

    (define (serialize-xsession-programs field-name alist)
      (generic-serialize-alist string-append

    (define (serialize-xsession-window-manager field-name window-manager)
      (string-append "exec " (cdr window-manager) "\n"))

    (define-configuration home-xsession-configuration
       (pair `(,dwm . "dwm"))
       "Cons pair of window manager package and executable name."
       (alist '())
       "Alist of programs to start and arguments to such programs."
       (string "$HOME/.local/share/xsession.log")
       "Log file to store errors and info."))

    (define (xsession-filter-fields field)
      (filter-configuration-fields home-xsession-configuration-fields (list 

    (define (xsession-serialize-field config field)
      (serialize-configuration config (xsession-filter-fields field)))

    (define (xsession-file config)
      (define dot-xsession
        (mixed-text-file "xsession"
    try() {
    pgrep -q $1 || $@ 2>> "
         (xsession-serialize-field config 'log-file)
         (xsession-serialize-field config 'programs)
         (xsession-serialize-field config 'window-manager)))
      `((".xsession" ,dot-xsession)))

    (define (add-xsession-packages config)
       (car (home-xsession-configuration-window-manager config))
       (map (lambda (association)
              (if (pair? (car association))
                  (caar association)
                  (car association)))
            (home-xsession-configuration-programs config))))

    (define home-xsession-service-type
      (service-type (name 'xsession)
                     (list (service-extension
                    (compose identity)
                    (default-value (home-xsession-configuration))
                    (description "Configure the X session via ~/.xsession.")))

This serializes a configuration such as this:

    (service home-xsession-service-type
                 (window-manager `(,mf-dwm . "dwm"))
                  `((,picom . ())
                    (,dunst . ())
                    ((,blueman . "blueman-applet") . ())
                    (,pasystray . ())
                    ((,network-manager-applet . "nm-applet") . ())
                    (,mpd . ())
                    (,cbatticon . ("BAT0"))
                    (,cbatticon . ("BAT1"))
                    (,xsettingsd . ())
                    (,tmux . ("new-session" "-d"))
                    (,hsetroot . ("-cover" "$HOME/Pictures/forest.jpg"))
                    (,setxkbmap . ("-layout" "us" "-option" "compose:ralt"))
                    ((,emacs-next . "emacs") . ("--daemon"))))
                 (log-file "~/.local/share/xsession.log")))


    try() {
    pgrep -q $1 || $@ 2>> ~/.local/share/xsession.log
    try picom
    try dunst
    try blueman-applet
    try pasystray
    try nm-applet
    try mpd
    try cbatticon BAT0
    try cbatticon BAT1
    try xsettingsd
    try tmux new-session -d
    try hsetroot -cover $HOME/Pictures/forest.jpg
    try setxkbmap -layout us -option compose:ralt
    try emacs --daemon
    exec dwm

But the permissions are wrong:

    └(~) % ls -l ~/.xsession                                         
    lrwxrwxrwx 1 mario users 52 Mar 28 22:23 /home/mario/.xsession -> 
    └(~) % ls -l /gnu/store/p213clvznwrrrasr3mygb6iqqnqsg2ra-xsession 
    -r--r--r-- 1 root root 342 Jan  1  1970 

If you spot something wrong, let me know.

Thank you in advance :)

reply via email to

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