all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Creating a service that runs a user-installed package as root
@ 2023-08-16  0:16 heat from fire via
  2023-08-29 13:19 ` wolf
  0 siblings, 1 reply; 2+ messages in thread
From: heat from fire via @ 2023-08-16  0:16 UTC (permalink / raw)
  To: help-guix@gnu.org

Hi all,
 
First time posting on this forum.
 
I am trying to set up a service that runs "sudo mullvad-daemon" upon user login. The mullvad package is installed through Nix on a user profile.
 
I've tried creating a user service using Shepherd in a config file at "~/.config/shepherd/init.scm", but it doesn't seem possible to run the command as root.
Here's a snippet from the file:
 
(define mullvad
  (service '(mullvad)
    #:respawn? #t
    #:start (make-forkexec-constructor '("mullvad-daemon" "-v"))
    #:stop (make-kill-destructor)))
 
I read through here in hopes to find a solution, but to no avail:
https://www.gnu.org/software/shepherd/manual/shepherd.html#Services
Perhaps there is a service constructor with an option to run the command as root?
 
I know that I can define a Shepherd service in my system config file, which runs the command in it as root, but given that it depends on a user-installed Nix package, I'm not sure how I'll have to accommodate for that. The command is located at /home/user/.nix-profile/bin/mullvad-daemon.
I also tried creating a regular system service using service-type, but couldn't get it to work.
 
My only other alternative is to run sudo mullvad-daemon in ~/.profile and make an exception in the sudoers file to not require a password. This solution is messy so I wanna try to avoid it. I could also put the command in the Guix equivalent of "/etc/rc.local", but I don't think there is one in Guix.
 
Any ideas on how I can create a service that runs a command installed in a user profile as root? Or alternatively, a better way to run a command as root without password on user login, after sourcing ~/.profile?
 
Thanks!

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

* Re: Creating a service that runs a user-installed package as root
  2023-08-16  0:16 Creating a service that runs a user-installed package as root heat from fire via
@ 2023-08-29 13:19 ` wolf
  0 siblings, 0 replies; 2+ messages in thread
From: wolf @ 2023-08-29 13:19 UTC (permalink / raw)
  To: heat from fire; +Cc: help-guix@gnu.org

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

On 2023-08-15 19:16:11 -0500, heat from fire via wrote:
> Hi all,
>  
> First time posting on this forum.
>  
> I am trying to set up a service that runs "sudo mullvad-daemon" upon user login. The mullvad package is installed through Nix on a user profile.
>  
> I've tried creating a user service using Shepherd in a config file at "~/.config/shepherd/init.scm", but it doesn't seem possible to run the command as root.
> Here's a snippet from the file:
>  
> (define mullvad
>   (service '(mullvad)
>     #:respawn? #t
>     #:start (make-forkexec-constructor '("mullvad-daemon" "-v"))
>     #:stop (make-kill-destructor)))
>  
> I read through here in hopes to find a solution, but to no avail:
> https://www.gnu.org/software/shepherd/manual/shepherd.html#Services
> Perhaps there is a service constructor with an option to run the command as root?

I also do not see such option, and since the user shepherd runs under the user,
I do not think it is possible without modifications to the sudoers file.

>  
> I know that I can define a Shepherd service in my system config file, which runs the command in it as root, but given that it depends on a user-installed Nix package, I'm not sure how I'll have to accommodate for that. The command is located at /home/user/.nix-profile/bin/mullvad-daemon.
> I also tried creating a regular system service using service-type, but couldn't get it to work.
>  
> My only other alternative is to run sudo mullvad-daemon in ~/.profile and make an exception in the sudoers file to not require a password. This solution is messy so I wanna try to avoid it. I could also put the command in the Guix equivalent of "/etc/rc.local", but I don't think there is one in Guix.
>  
> Any ideas on how I can create a service that runs a command installed in a user profile as root? Or alternatively, a better way to run a command as root without password on user login, after sourcing ~/.profile?

I do not have much experience with shepherd (yet!), but cannot you just use
'("sudo" "mullvad-daemon" "-v")?  While still requiring an entry in sudoers
file, I would say it is cleaner than sudo ... in the ~/.profile, and it you
could still start/stop it via the herd command.

>  
> Thanks!

-- 
There are only two hard things in Computer Science:
cache invalidation, naming things and off-by-one errors.

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

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

end of thread, other threads:[~2023-08-29 13:42 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-16  0:16 Creating a service that runs a user-installed package as root heat from fire via
2023-08-29 13:19 ` wolf

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.