* 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
* Re: Question about scripts in guix-home
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
1 sibling, 1 reply; 8+ messages in thread
From: Edouard Klein @ 2021-10-16 10:22 UTC (permalink / raw)
To: Fredrik Salomonsson; +Cc: help-guix
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
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Question about scripts in guix-home
2021-10-16 10:22 ` Edouard Klein
@ 2021-10-16 20:30 ` Fredrik Salomonsson
0 siblings, 0 replies; 8+ messages in thread
From: Fredrik Salomonsson @ 2021-10-16 20:30 UTC (permalink / raw)
To: Edouard Klein; +Cc: help-guix
Edouard Klein <edou@rdklein.fr> writes:
> 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.
>
Yeah, not sure how I should invove it though. I tried doing
(chmod #$(local-file "files/waybar/modules-mic.sh") #o555)
In different gexp. But just getting operation not permitted:
#+begin_src text
In different gexp but just getting:
Backtrace:
2 (primitive-load "/gnu/store/w399i13mijh528x6ymlijh0k5fz?")
In ice-9/eval.scm:
619:8 1 (_ #f)
In unknown file:
0 (chmod "/gnu/store/kbarnh2z2zaljwy6bwfhni2h3jjihzyj-mo?" ?)
ERROR: In procedure chmod:
In procedure chmod: Operation not permitted
#+end_src
--
s/Fred[re]+i[ck]+/Fredrik/g
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Question about scripts in guix-home
2021-10-16 3:43 Question about scripts in guix-home Fredrik Salomonsson
2021-10-16 10:22 ` Edouard Klein
@ 2021-10-16 12:40 ` Oleg Pykhalov
2021-10-16 22:14 ` Fredrik Salomonsson
1 sibling, 1 reply; 8+ messages in thread
From: Oleg Pykhalov @ 2021-10-16 12:40 UTC (permalink / raw)
To: Fredrik Salomonsson; +Cc: help-guix
[-- Attachment #1: Type: text/plain, Size: 1123 bytes --]
Hi,
Fredrik Salomonsson <plattfot@posteo.net> writes:
> 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.
I use the following, which creates ~/.local/bin/shellcheck executable file:
--8<---------------cut here---------------start------------->8---
(home-environment
;; ...
(services
(list
(simple-service 'shellcheck-wrapper
home-files-service-type
(list `("local/bin/shellcheck"
,(computed-file
"shellcheck-wrapper"
#~(begin
(with-output-to-file #$output
(lambda ()
(format #t "\
#!/bin/sh
exec -a \"$0\" ~a/bin/shellcheck --shell=bash \"$@\"\n"
#$shellcheck)))
(chmod #$output #o555)))))))))
--8<---------------cut here---------------end--------------->8---
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 861 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Question about scripts in guix-home
2021-10-16 12:40 ` Oleg Pykhalov
@ 2021-10-16 22:14 ` Fredrik Salomonsson
2021-10-17 10:33 ` Oleg Pykhalov
0 siblings, 1 reply; 8+ messages in thread
From: Fredrik Salomonsson @ 2021-10-16 22:14 UTC (permalink / raw)
To: Oleg Pykhalov; +Cc: help-guix
Hi,
Oleg Pykhalov <go.wigust@gmail.com> writes:
> I use the following, which creates ~/.local/bin/shellcheck executable file:
> --8<---------------cut here---------------start------------->8---
> (home-environment
> ;; ...
> (services
> (list
> (simple-service 'shellcheck-wrapper
> home-files-service-type
> (list `("local/bin/shellcheck"
> ,(computed-file
> "shellcheck-wrapper"
> #~(begin
> (with-output-to-file #$output
> (lambda ()
> (format #t "\
> #!/bin/sh
> exec -a \"$0\" ~a/bin/shellcheck --shell=bash \"$@\"\n"
> #$shellcheck)))
> (chmod #$output #o555)))))))))
> --8<---------------cut here---------------end--------------->8---
Thanks, still issue with the execution bit though…
This is what I tried. Note that I only tested this on my mic.sh script
to see if it worked.
#+begin_src scheme
(define-public (get-services host)
"Return services for HOST."
(let ((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"
,(computed-file
"mic-wrapper"
#~(begin
(let ((script #$(local-file "files/waybar/modules-mic.sh")))
(with-output-to-file #$output
(lambda ()
(format #t "\
#!/bin/sh
exec -a \"$0\" ~a --shell=bash \"$@\"\n"
script)))
(chmod script #o555)) ;; <-- trying to chmod the script
(chmod #$output #o555))))
("config/waybar/modules/storage.sh"
,storage-script)
)))))
#+end_src
Without the (chmod script #o555), it builds but when I try and run it I
get:
#+begin_src bash
$ ~/.config/waybar/modules/mic.sh
/home/plattfot/.config/waybar/modules/mic.sh: line 2: /gnu/store/kbarnh2z2zaljwy6bwfhni2h3jjihzyj-modules-mic.sh: Permission denied
/home/plattfot/.config/waybar/modules/mic.sh: line 2: exec: /gnu/store/kbarnh2z2zaljwy6bwfhni2h3jjihzyj-modules-mic.sh: cannot execute: Permission denied
#+end_src
If I try and chmod the script, as shown in the example above, guix home
fails with:
#+begin_src bash
$ guix home reconfigure -L ~/.files ~/.files/plt/home/configs/surt.scm 1
substitute: updating substitutes from 'https://ci.guix.gnu.org'... 100.0%
substitute: updating substitutes from 'https://bordeaux.guix.gnu.org'... 100.0%
The following derivations will be built:
/gnu/store/mn3ii78ri2bsi47rjc5qwnjc7hrd0znn-home.drv
/gnu/store/3fwk9l6xjgkac702figgn4ppfmlli5xh-files.drv
/gnu/store/jydir36k5b53n6wqnjzbkgkjz7wjw1g8-mic-wrapper.drv
building /gnu/store/jydir36k5b53n6wqnjzbkgkjz7wjw1g8-mic-wrapper.drv...
Backtrace:
2 (primitive-load "/gnu/store/w399i13mijh528x6ymlijh0k5fz?")
In ice-9/eval.scm:
619:8 1 (_ #f)
In unknown file:
0 (chmod "/gnu/store/kbarnh2z2zaljwy6bwfhni2h3jjihzyj-mo?" ?)
ERROR: In procedure chmod:
In procedure chmod: Operation not permitted
builder for `/gnu/store/jydir36k5b53n6wqnjzbkgkjz7wjw1g8-mic-wrapper.drv' failed with exit code 1
build of /gnu/store/jydir36k5b53n6wqnjzbkgkjz7wjw1g8-mic-wrapper.drv failed
View build log at '/var/log/guix/drvs/jy/dir36k5b53n6wqnjzbkgkjz7wjw1g8-mic-wrapper.drv.bz2'.
cannot build derivation `/gnu/store/3fwk9l6xjgkac702figgn4ppfmlli5xh-files.drv': 1 dependencies couldn't be built
cannot build derivation `/gnu/store/mn3ii78ri2bsi47rjc5qwnjc7hrd0znn-home.drv': 1 dependencies couldn't be built
guix home: error: build of `/gnu/store/mn3ii78ri2bsi47rjc5qwnjc7hrd0znn-home.drv' failed
#+end_src
I ended up just package them up and that seems to be working
#+begin_src scheme
(define-module (plt home waybar)
#:use-module (gnu home services)
#:use-module (gnu packages bash)
#:use-module (gnu packages wm)
#:use-module (gnu services)
#:use-module (guix build-system copy)
#:use-module (guix gexp)
#:use-module (guix packages)
#:use-module (guix utils)
#:use-module ((guix licenses) #:prefix license:)
#:use-module (ice-9 format))
(define %source-dir (current-source-directory))
(define plt-waybar-custom-script
(package
(name "plt-waybar-custom-script")
(version "1.0.0")
(source (local-file (string-append %source-dir "/files/waybar")
#:recursive? #t
#:select? (lambda (file stat)
(string-suffix? ".sh" file))))
(build-system copy-build-system)
(arguments
`(#:install-plan
'(("modules-storage.sh" "bin/waybar-custom-storage")
("modules-mic.sh" "bin/waybar-custom-mic"))))
(native-inputs `())
(inputs `(("bash" ,bash))) ;; needs pactl
(propagated-inputs `())
(synopsis "Simple script to check the mic status")
(description
"Uses @code{pactl} to fetch the microphone status and return the status in a
form @code{waybar} understands.")
(home-page "")
(license license:gpl3+)))
(define-public packages
(list
waybar
plt-waybar-custom-script
))
(define-public (get-services host)
"Return services for HOST."
(let ((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/storage.sh"
,storage-script)
)))))
#+end_src
--
s/Fred[re]+i[ck]+/Fredrik/g
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Question about scripts in guix-home
2021-10-16 22:14 ` Fredrik Salomonsson
@ 2021-10-17 10:33 ` Oleg Pykhalov
2021-10-17 18:45 ` Fredrik Salomonsson
0 siblings, 1 reply; 8+ messages in thread
From: Oleg Pykhalov @ 2021-10-17 10:33 UTC (permalink / raw)
To: Fredrik Salomonsson; +Cc: help-guix
[-- Attachment #1: Type: text/plain, Size: 2887 bytes --]
Fredrik Salomonsson <plattfot@posteo.net> writes:
[…]
> This is what I tried. Note that I only tested this on my mic.sh script
> to see if it worked.
>
> #+begin_src scheme
> (define-public (get-services host)
> "Return services for HOST."
> (let ((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"
> ,(computed-file
> "mic-wrapper"
> #~(begin
> (let ((script #$(local-file "files/waybar/modules-mic.sh")))
> (with-output-to-file #$output
> (lambda ()
> (format #t "\
> #!/bin/sh
> exec -a \"$0\" ~a --shell=bash \"$@\"\n"
> script)))
> (chmod script #o555)) ;; <-- trying to chmod the script
> (chmod #$output #o555))))
> ("config/waybar/modules/storage.sh"
> ,storage-script)
> )))))
> #+end_src
Well, if you don't want to put the content of
files/waybar/modules-mic.sh file inside a Scheme string, then you need
to read the file to a string, e.g.:
--8<---------------cut here---------------start------------->8---
(simple-service 'shellcheck-wrapper
home-files-service-type
(list `("local/bin/shellcheck"
,(computed-file
"shellcheck-wrapper"
#~(begin
(use-modules (ice-9 rdelim))
(with-output-to-file #$output
(lambda ()
(display #$(with-input-from-file "/tmp/foo" read-string))))
(chmod #$output #o555))))))
--8<---------------cut here---------------end--------------->8---
Note that it's just an example which you should change according to your
needs. ;-) Also, it creates not an executable but a symlink to an
executable in a store, which I missed in a previous answer.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 861 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Question about scripts in guix-home
2021-10-17 10:33 ` Oleg Pykhalov
@ 2021-10-17 18:45 ` Fredrik Salomonsson
2021-10-21 9:58 ` Oleg Pykhalov
0 siblings, 1 reply; 8+ messages in thread
From: Fredrik Salomonsson @ 2021-10-17 18:45 UTC (permalink / raw)
To: Oleg Pykhalov; +Cc: help-guix
Oleg Pykhalov <go.wigust@gmail.com> writes:
> Well, if you don't want to put the content of
> files/waybar/modules-mic.sh file inside a Scheme string, then you need
> to read the file to a string, e.g.:
> --8<---------------cut here---------------start------------->8---
> (simple-service 'shellcheck-wrapper
> home-files-service-type
> (list `("local/bin/shellcheck"
> ,(computed-file
> "shellcheck-wrapper"
> #~(begin
> (use-modules (ice-9 rdelim))
> (with-output-to-file #$output
> (lambda ()
> (display #$(with-input-from-file "/tmp/foo" read-string))))
> (chmod #$output #o555))))))
> --8<---------------cut here---------------end--------------->8---
I'm a bit confused, "Scheme string" and string aren't they the same
thing?
> Note that it's just an example which you should change according to your
> needs. ;-) Also, it creates not an executable but a symlink to an
> executable in a store, which I missed in a previous answer.
Thank you for the example! This looks like what I was looking for.
--
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
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/guix.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.