From: david larsson <david.larsson@selfhosted.xyz>
To: pkill9 <pkill9@runbox.com>
Cc: guix-devel@gnu.org,
Guix-devel
<guix-devel-bounces+david.larsson=selfhosted.xyz@gnu.org>
Subject: Re: Make guix commands pipeable
Date: Sat, 20 Mar 2021 20:15:19 +0100 [thread overview]
Message-ID: <c6364b207e504c2fd60b89c0aee3b23d@selfhosted.xyz> (raw)
In-Reply-To: <20210320121353.0e568c7a@runbox.com>
On 2021-03-20 13:13, pkill9 wrote:
> I would like to be able to pipe files into guix commands.
>
> Specifically the `guix system build` command, so I can build a system
> configuration on a remote Guix system over SSH, i.e. `cat config.scm |
> ssh <remote-system> guix system build -`, or perhaps using the
> `--expression` flag which would make more sense, e.g. `cat config.scm |
> ssh <remote-system> guix system build -e -`.
>
> While you can currently just copy over a file and then use that, it
> would be a little cleaner and more stateless to use a pipe.
>
> What do other people think?
I like pipes and this would be nice to have. Though an easy way to wrap
things in bash and make them pipable at the same time is to use the -t
check like this:
f(){ [[ ! -t 0 ]] && mapfile -t Args ; if [[ -n "${Args[@]}" ]]; then
printf 'some_command %s ' "${Args[@]}" ; else printf 'some_command %s '
"$@"; fi ; }
printf '%s\n' a b c | f
f a b c
So you could define f as: f(){ [[ ! -t 0 ]] && mapfile -t -d '' Args ;
if [[ -n "${Args[@]}" ]]; then ssh <remote-system> guix system build -e
"${Args[@]//$'\n'/}" ; else ssh <remote-system> guix system build -e
"$@"; fi ; }
and then I think you should be able to cat config.scm | f
Notice -d '' above which means use null as delimiter which will most
often put everything in index 0 of the list. Also notice the parameter
expansion which removes all newlines from the content.
I do agree though that it would be nicer to just have '-' as a guix
input arg causing any guix command to read from stdin.
I hope it helps!
Best regards,
David
next prev parent reply other threads:[~2021-03-20 19:16 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-20 12:13 Make guix commands pipeable pkill9
2021-03-20 19:15 ` david larsson [this message]
2021-03-21 22:15 ` Léo Le Bouter
2021-03-24 0:01 ` pkill9
2021-03-24 0:03 ` pkill9
2021-03-21 10:21 ` zimoun
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
List information: https://guix.gnu.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=c6364b207e504c2fd60b89c0aee3b23d@selfhosted.xyz \
--to=david.larsson@selfhosted.xyz \
--cc=guix-devel-bounces+david.larsson=selfhosted.xyz@gnu.org \
--cc=guix-devel@gnu.org \
--cc=pkill9@runbox.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 public inbox
https://git.savannah.gnu.org/cgit/guix.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).