unofficial mirror of help-guix@gnu.org 
 help / color / mirror / Atom feed
* Question about scripts in guix-home
@ 2021-10-16  3:43 Fredrik Salomonsson
  2021-10-16 10:22 ` Edouard Klein
  2021-10-16 12:40 ` Oleg Pykhalov
  0 siblings, 2 replies; 8+ messages in thread
From: Fredrik Salomonsson @ 2021-10-16  3:43 UTC (permalink / raw)
  To: help-guix


Hi guix,

I decided to try out guix home. But I hit a bit of a snag. I'm trying to
port my waybar config over to it, but cannot figure out how to set the
execution bit on my two custom scripts I have.

This is what I currently have:

#+begin_src scheme
  (define-module (plt home waybar)
    #:use-module (gnu services)
    #:use-module (gnu home services)
    #:use-module (gnu packages wm)
    #:use-module (guix gexp)
    #:use-module (guix utils)
    #:use-module (ice-9 format))

  (define-public packages
    (list
     waybar
     ))

  (define %source-dir (current-source-directory))

  (define-public (get-services host)
    "Return services for HOST."
    (list
     (simple-service 'plt-waybar-config
                     home-files-service-type
                     `(
                       ("config/waybar/config"
                        ,(local-file (format #f "~a/files/waybar/~a.conf" %source-dir host)))
                       ("config/waybar/style.css"
                        ,(local-file (format #f "~a/files/waybar/~a-style.css" %source-dir host)))
                       ("config/waybar/modules/mic.sh"
                        ,(local-file "files/waybar/modules-mic.sh"))
                       ("config/waybar/modules/storage.sh"
                        ,(local-file "files/waybar/modules-storage.sh"))
                       ))))
#+end_src

Which generates the config but the mic.sh and storage.sh bash scripts
are missing their execution bit.

The bash scripts are really basic, for example here's the mic.sh:

#+begin_src bash
  #! /usr/bin/env bash

  mic_mute=$(pactl get-source-mute @DEFAULT_SOURCE@| cut -d" " -f2)
  if [[ "$mic_mute" == "yes" ]]
  then
      echo '{"text": "",  "class": "muted", "percentage": 0 }'
  else
      echo '{"text": "",  "class": "unmuted", "percentage": 100}'
  fi
#+end_src

I played around with gexp but didn't get anything working. Closest I got
what by using program-file

#+begin_src scheme
  (define-public (get-services host)
    "Return services for HOST."
    (let ((mic-script (program-file
                       "mic.sh"
                       #~(execl #$(local-file "files/waybar/modules-mic.sh") "mic.sh")))
          (storage-script (program-file
                           "storage.sh"
                           #~(execl #$(local-file "files/waybar/modules-storage.sh") "storage.sh"))))
      (list
       (simple-service 'plt-waybar-config
                       home-files-service-type
                       `(
                         ("config/waybar/config"
                          ,(local-file (format #f "~a/files/waybar/~a.conf" %source-dir host)))
                         ("config/waybar/style.css"
                          ,(local-file (format #f "~a/files/waybar/~a-style.css" %source-dir host)))
                         ("config/waybar/modules/mic.sh"
                          ,mic-script)
                         ("config/waybar/modules/storage.sh"
                          ,storage-script)
                         )))))
#+end_src

But it's still trying to execute the original scripts and fail due to
the execution bit.

I'm probably missing something obvious, but I haven't used gexp before.

How do you set the execution bit on a file-like object? 

Or is there a better approach for dealing with these? Package them up
perhaps? As I just realized when writing this that I also need to patch
the shebang to point to the bash guix-home is using.

Thanks

-- 
s/Fred[re]+i[ck]+/Fredrik/g


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-10-21  9:59 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-16  3:43 Question about scripts in guix-home Fredrik Salomonsson
2021-10-16 10:22 ` Edouard Klein
2021-10-16 20:30   ` Fredrik Salomonsson
2021-10-16 12:40 ` Oleg Pykhalov
2021-10-16 22:14   ` Fredrik Salomonsson
2021-10-17 10:33     ` Oleg Pykhalov
2021-10-17 18:45       ` Fredrik Salomonsson
2021-10-21  9:58         ` Oleg Pykhalov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).