unofficial mirror of guix-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Make guix commands pipeable
@ 2021-03-20 12:13 pkill9
  2021-03-20 19:15 ` david larsson
  2021-03-21 10:21 ` zimoun
  0 siblings, 2 replies; 6+ messages in thread
From: pkill9 @ 2021-03-20 12:13 UTC (permalink / raw)
  To: guix-devel

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?


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Make guix commands pipeable
  2021-03-20 12:13 Make guix commands pipeable pkill9
@ 2021-03-20 19:15 ` david larsson
  2021-03-21 22:15   ` Léo Le Bouter
  2021-03-21 10:21 ` zimoun
  1 sibling, 1 reply; 6+ messages in thread
From: david larsson @ 2021-03-20 19:15 UTC (permalink / raw)
  To: pkill9; +Cc: guix-devel, Guix-devel

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


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Make guix commands pipeable
  2021-03-20 12:13 Make guix commands pipeable pkill9
  2021-03-20 19:15 ` david larsson
@ 2021-03-21 10:21 ` zimoun
  1 sibling, 0 replies; 6+ messages in thread
From: zimoun @ 2021-03-21 10:21 UTC (permalink / raw)
  To: pkill9, guix-devel

Hi,

On Sat, 20 Mar 2021 at 12:13, pkill9 <pkill9@runbox.com> wrote:
> I would like to be able to pipe files into guix commands.

Well, this work:

  guix search hello | recsel -C -P name | xargs guix build

> 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 -`.

Does “cat config.scm | ssh <remote> xargs -0 guix system -e” work?

Indeed, maybe some commands are expecting a real file and cannot read
from stdin.


Cheers,
simon


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Make guix commands pipeable
  2021-03-20 19:15 ` david larsson
@ 2021-03-21 22:15   ` Léo Le Bouter
  2021-03-24  0:01     ` pkill9
  2021-03-24  0:03     ` pkill9
  0 siblings, 2 replies; 6+ messages in thread
From: Léo Le Bouter @ 2021-03-21 22:15 UTC (permalink / raw)
  To: david larsson, pkill9; +Cc: guix-devel, Guix-devel

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

> 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.

Doesnt /dev/stdin work?

The only reason it could not is that somehow the file descriptor needs
to be seekable.

Léo

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Make guix commands pipeable
  2021-03-21 22:15   ` Léo Le Bouter
@ 2021-03-24  0:01     ` pkill9
  2021-03-24  0:03     ` pkill9
  1 sibling, 0 replies; 6+ messages in thread
From: pkill9 @ 2021-03-24  0:01 UTC (permalink / raw)
  To: Léo Le Bouter; +Cc: guix-devel, Guix-devel


> Doesnt /dev/stdin work?
> 
> The only reason it could not is that somehow the file descriptor needs
> to be seekable.
> 
> Léo

This doesn't work for me, with `cat <file> | guix build -f /dev/stdin`
i get "guix build: error: failed to load '/dev/stdin': No such file or
directory"


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Make guix commands pipeable
  2021-03-21 22:15   ` Léo Le Bouter
  2021-03-24  0:01     ` pkill9
@ 2021-03-24  0:03     ` pkill9
  1 sibling, 0 replies; 6+ messages in thread
From: pkill9 @ 2021-03-24  0:03 UTC (permalink / raw)
  To: Léo Le Bouter; +Cc: guix-devel, Guix-devel


> Doesnt /dev/stdin work?
> 
> The only reason it could not is that somehow the file descriptor needs
> to be seekable.
> 
> Léo

This doesn't work for me, with `cat <file> | guix build -f /dev/stdin`
i get "guix build: error: failed to load '/dev/stdin': No such file or
directory"


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-03-24  0:04 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-03-20 12:13 Make guix commands pipeable pkill9
2021-03-20 19:15 ` david larsson
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

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).