all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Trev <trev@trevdev.ca>
To: Fabio Natali <me@fabionatali.com>, help-guix@gnu.org
Subject: Re: Guix Home, .local/bin executable scripts
Date: Sat, 24 Sep 2022 15:49:21 -0700	[thread overview]
Message-ID: <874jww2xse.fsf@codinator.mail-host-address-is-not-set> (raw)
In-Reply-To: <87r100czb9.fsf@reckondigital.com>

[-- Attachment #1: Type: text/plain, Size: 2790 bytes --]

> 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

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 251 bytes --]

  reply	other threads:[~2022-09-24 22:49 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-24 20:06 Guix Home, .local/bin executable scripts Fabio Natali
2022-09-24 22:49 ` Trev [this message]
2022-09-25 13:27   ` Fabio Natali

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=874jww2xse.fsf@codinator.mail-host-address-is-not-set \
    --to=trev@trevdev.ca \
    --cc=help-guix@gnu.org \
    --cc=me@fabionatali.com \
    /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.
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.