> Dear All, > > I've recently started exploring Guix Home. I was able to create a few > simple services for some of my apps, e.g. Emacs. > > I've now come to a point where I'd like to add some executables to my > configuration, e.g. some of my `.local/bin' scripts. > > Consider this `hello.sh' script, for example: > > ,---- > | #!/bin/bash > | > | echo "Hello World" | sed "s/World/Guix/" > `---- > > The following service copies `hello.sh' to the expected destination and > does so while preserving the correct permissions (`#:recursive #t'), > i.e. the file is executable. >
If the thing is being moved to your store for any reason you may want to
explicitly update the permissions. I had to do this when I packaged PHP
composer for personal use. Things tend to go into the store as read-only.
> ,----
> | (define my/home-hello-service
> | (service
> | (service-type
> | (name 'home-hello)
> | (extensions
> | (list
> | (service-extension
> | home-files-service-type
> | (lambda (config)
> | `((".local/bin/hello.sh"
> | ,(local-file "scripts/hello.sh" #:recursive? #t)))))))
> | (default-value #f)
> | (description "My valuable Hello World script."))))
> `----
>
> The script shows up in my Guix Home but it won't work - I suppose that
> `/bin/bash' should be replaced with the correct Bash store path?
>
I would try to us a portable shebang such as #!/usr/bin/env bash. You
may also use a gexp to dynamically insert the true location of your
profile's bash path. This is the guix way, so far as I can tell. I am
not sure what the use of a #:recursive? keyword might be in the context
of a single script.
Check out the manual on Gexps. I find it to be pretty helpful.
> ,----
> | ~$ hello.sh
> | -bash: ~/.local/bin/hello.sh: /bin/bash: bad interpreter: No such file or
> directory
> `----
>
> I've been looking at the docs and found something that feels related to
> my problem (e.g. `computed-file', `substitute*', ...?) but I'd
> appreciate if someone could point me in the right direction.
>
You can patch a shebang or anything else with substitute by doing the
following from within a gexp where #$bash happens to be the bash package
reference so long as it is in the right lexical scope. See
(with-imported-modules) in the manual.
(substitute* "scripts/hello.sh"
("#!/bin/bash" (string-append #$bash "/bin/bash")))
Link to manual: https://guix.gnu.org/manual/en/html_node/G_002dExpressions.html
> Thanks, best, Fabio.
>
Good luck.
Full disclosure: I'm only just starting to get the hang of this
stuff. Anyone else is welcome with better advice.
--
Trev : 0FB7 D06B 4A2A F07E AD5B 1169 183B 6306 8AA1 D206
signature.asc
Description: PGP signature
