unofficial mirror of help-guix@gnu.org 
 help / color / mirror / Atom feed
* Run a system command in home configuration file
@ 2022-02-25 10:08 Reza Housseini
  2022-03-08 10:33 ` Ludovic Courtès
  0 siblings, 1 reply; 4+ messages in thread
From: Reza Housseini @ 2022-02-25 10:08 UTC (permalink / raw)
  To: help-guix

Hello guix

I want to run a system command and use the output inside my ssh config
file. Below is the service configuration I'm talking about and my current
implementation which does not work, probably because the command is run
from the daemon, but I need it to run from the current user. Has anyone an
idea how to achieve this?

(simple-service 'ssh-config
 home-files-service-type
 (list `("ssh/config"
 ,(mixed-text-file "config" "
Host *
  IdentityAgent " #~(system* #$(file-append gnupg "/bin/gpgconf")
"--list-dirs" "agent-ssh-socket") "
"))))

Thanks and cheers,
Reza

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

* Re: Run a system command in home configuration file
  2022-02-25 10:08 Run a system command in home configuration file Reza Housseini
@ 2022-03-08 10:33 ` Ludovic Courtès
  2022-03-08 14:38   ` Reza Housseini
  0 siblings, 1 reply; 4+ messages in thread
From: Ludovic Courtès @ 2022-03-08 10:33 UTC (permalink / raw)
  To: Reza Housseini; +Cc: help-guix

Hi,

Reza Housseini <reza.housseini@gmail.com> skribis:

> I want to run a system command and use the output inside my ssh config
> file. Below is the service configuration I'm talking about and my current
> implementation which does not work, probably because the command is run
> from the daemon, but I need it to run from the current user. Has anyone an
> idea how to achieve this?
>
> (simple-service 'ssh-config
>  home-files-service-type
>  (list `("ssh/config"
>  ,(mixed-text-file "config" "
> Host *
>   IdentityAgent " #~(system* #$(file-append gnupg "/bin/gpgconf")
> "--list-dirs" "agent-ssh-socket") "
> "))))

Instead of #~(system* …) above, you could do something like:

  (let* ((pipe (open-input-pipe "gpgconf" …))
         (data (get-string-all pipe)))
    (close-pipe pipe)
    data)

The effect will be that ‘gpgconf’ will run when you invoke ‘guix system
reconfigure’, as the user who invokes it.  (You need the (ice-9 popen)
and (rnrs io bytevectors) modules.)

I can’t necessarily recommend it because it’s kinda wild, but it should
do the trick.

HTH,
Ludo’.


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

* Re: Run a system command in home configuration file
  2022-03-08 10:33 ` Ludovic Courtès
@ 2022-03-08 14:38   ` Reza Housseini
  2022-03-09  7:37     ` Efraim Flashner
  0 siblings, 1 reply; 4+ messages in thread
From: Reza Housseini @ 2022-03-08 14:38 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: help-guix


On 3/8/22 11:33, Ludovic Courtès wrote:
> Hi,
>
> Reza Housseini <reza.housseini@gmail.com> skribis:
>
>> I want to run a system command and use the output inside my ssh config
>> file. Below is the service configuration I'm talking about and my current
>> implementation which does not work, probably because the command is run
>> from the daemon, but I need it to run from the current user. Has anyone an
>> idea how to achieve this?
>>
>> (simple-service 'ssh-config
>>   home-files-service-type
>>   (list `("ssh/config"
>>   ,(mixed-text-file "config" "
>> Host *
>>    IdentityAgent " #~(system* #$(file-append gnupg "/bin/gpgconf")
>> "--list-dirs" "agent-ssh-socket")"
>> "))))
> Instead of #~(system* …) above, you could do something like:
>
>    (let* ((pipe (open-input-pipe "gpgconf" …))
>           (data (get-string-all pipe)))
>      (close-pipe pipe)
>      data)
>
> The effect will be that ‘gpgconf’ will run when you invoke ‘guix system
> reconfigure’, as the user who invokes it.  (You need the (ice-9 popen)
> and (rnrs io bytevectors) modules.)
>
> I can’t necessarily recommend it because it’s kinda wild, but it should
> do the trick.
>
> HTH,
> Ludo’.


Hi Ludo

Thanks for the reply, it really looks kinda wild :)

Isn't there a general need to run certain commands for  specific user 
especially in the context of guix home?

Cheers,

Reza



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

* Re: Run a system command in home configuration file
  2022-03-08 14:38   ` Reza Housseini
@ 2022-03-09  7:37     ` Efraim Flashner
  0 siblings, 0 replies; 4+ messages in thread
From: Efraim Flashner @ 2022-03-09  7:37 UTC (permalink / raw)
  To: Reza Housseini; +Cc: help-guix

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

On Tue, Mar 08, 2022 at 03:38:19PM +0100, Reza Housseini wrote:
> 
> On 3/8/22 11:33, Ludovic Courtès wrote:
> > Hi,
> > 
> > Reza Housseini <reza.housseini@gmail.com> skribis:
> > 
> > > I want to run a system command and use the output inside my ssh config
> > > file. Below is the service configuration I'm talking about and my current
> > > implementation which does not work, probably because the command is run
> > > from the daemon, but I need it to run from the current user. Has anyone an
> > > idea how to achieve this?
> > > 
> > > (simple-service 'ssh-config
> > >   home-files-service-type
> > >   (list `("ssh/config"
> > >   ,(mixed-text-file "config" "
> > > Host *
> > >    IdentityAgent " #~(system* #$(file-append gnupg "/bin/gpgconf")
> > > "--list-dirs" "agent-ssh-socket")"
> > > "))))
> > Instead of #~(system* …) above, you could do something like:
> > 
> >    (let* ((pipe (open-input-pipe "gpgconf" …))
> >           (data (get-string-all pipe)))
> >      (close-pipe pipe)
> >      data)
> > 
> > The effect will be that ‘gpgconf’ will run when you invoke ‘guix system
> > reconfigure’, as the user who invokes it.  (You need the (ice-9 popen)
> > and (rnrs io bytevectors) modules.)
> > 
> > I can’t necessarily recommend it because it’s kinda wild, but it should
> > do the trick.
> > 
> 
> Thanks for the reply, it really looks kinda wild :)
> 
> Isn't there a general need to run certain commands for  specific user
> especially in the context of guix home?
> 

One option is a one-off shepherd service. For finding the
SSH_AUTH_SOCKET using gpgconf I stuck with the tried and true method of
setting it in .bash_profile¹.

¹ https://git.sr.ht/~efraim/guix-config/tree/master/item/efraim-home.scm#L694

-- 
Efraim Flashner   <efraim@flashner.co.il>   אפרים פלשנר
GPG key = A28B F40C 3E55 1372 662D  14F7 41AA E7DC CA3D 8351
Confidentiality cannot be guaranteed on emails sent or received unencrypted

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

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

end of thread, other threads:[~2022-03-09  7:41 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-02-25 10:08 Run a system command in home configuration file Reza Housseini
2022-03-08 10:33 ` Ludovic Courtès
2022-03-08 14:38   ` Reza Housseini
2022-03-09  7:37     ` Efraim Flashner

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