help-guix
[Top][All Lists]
Advanced

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

Re: Question about scripts in guix-home


From: Edouard Klein
Subject: Re: Question about scripts in guix-home
Date: Sat, 16 Oct 2021 12:22:13 +0200
User-agent: mu4e 1.6.5; emacs 27.2

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 via email to

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