[Top][All Lists]

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

Re: Guix Home, .local/bin executable scripts

From: Trev
Subject: Re: Guix Home, .local/bin executable scripts
Date: Sat, 24 Sep 2022 15:49:21 -0700
User-agent: Notmuch/0.36 ( Emacs/28.1 (x86_64-pc-linux-gnu)

> 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 `' script, for example:
> ,----
> | #!/bin/bash
> | 
> | echo "Hello World" | sed "s/World/Guix/"
> `----
> The following service copies `' 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/"
> |             ,(local-file "scripts/" #: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.

> ,----
> | ~$
> | -bash: ~/.local/bin/ /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/"
  ("#!/bin/bash" (string-append #$bash "/bin/bash")))

Link to manual:

> 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

Attachment: signature.asc
Description: PGP signature

reply via email to

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