unofficial mirror of help-guix@gnu.org 
 help / color / mirror / Atom feed
From: Edouard Klein <edou@rdklein.fr>
To: Fredrik Salomonsson <plattfot@posteo.net>
Cc: help-guix@gnu.org
Subject: Re: Question about scripts in guix-home
Date: Sat, 16 Oct 2021 12:22:13 +0200	[thread overview]
Message-ID: <874k9hz2q3.fsf@rdklein.fr> (raw)
In-Reply-To: <87r1clfxcp.fsf@posteo.net>

Hi,

Sorry I can't be more precise due to lack of time, but maybe invoking
chmod on the .sh files in a gexp would work ?

https://www.gnu.org/software/guile/manual/html_node/File-System.html

#+begin_quote

Scheme Procedure: chmod object mode
C Function: scm_chmod (object, mode)

    Changes the permissions of the file referred to by object. object
    can be a string containing a file name or a port or integer file
    descriptor which is open on a file (in which case fchmod is used as
    the underlying system call). mode specifies the new permissions as a
    decimal number, e.g., (chmod "foo" #o755). The return value is
    unspecified.

#+end_quote.


Fredrik Salomonsson <plattfot@posteo.net> writes:

> 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



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

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-16  3:43 Question about scripts in guix-home Fredrik Salomonsson
2021-10-16 10:22 ` Edouard Klein [this message]
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=874k9hz2q3.fsf@rdklein.fr \
    --to=edou@rdklein.fr \
    --cc=help-guix@gnu.org \
    --cc=plattfot@posteo.net \
    /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).