unofficial mirror of help-guix@gnu.org 
 help / color / mirror / Atom feed
From: Fredrik Salomonsson <plattfot@posteo.net>
To: help-guix <help-guix@gnu.org>
Subject: Question about scripts in guix-home
Date: Sat, 16 Oct 2021 03:43:34 +0000	[thread overview]
Message-ID: <87r1clfxcp.fsf@posteo.net> (raw)


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


             reply	other threads:[~2021-10-16  3:44 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-16  3:43 Fredrik Salomonsson [this message]
2021-10-16 10:22 ` Question about scripts in guix-home 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87r1clfxcp.fsf@posteo.net \
    --to=plattfot@posteo.net \
    --cc=help-guix@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).