[Top][All Lists]

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

Re: Make guix commands pipeable

From: david larsson
Subject: Re: Make guix commands pipeable
Date: Sat, 20 Mar 2021 20:15:19 +0100

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,

reply via email to

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