nixpkgs icon indicating copy to clipboard operation
nixpkgs copied to clipboard

Sunshine module does not autostart

Open Redhawk18 opened this issue 1 year ago • 15 comments

Describe the bug

sunshine service does not start once enabled

Steps To Reproduce

Steps to reproduce the behavior:

{
  services.sunshine = {
    enable = true;
    openFirewall = true;
    #    capSysAdmin = true;
  };
}

Expected behavior

for the service to autostart, I saw the autostart option but I believe thats set to true by default.

Screenshots

nixos-config on  main [!?] 
❯ systemctl --user status sunshine
○ sunshine.service - Self-hosted game stream host for Moonlight
     Loaded: loaded (/etc/systemd/user/sunshine.service; enabled; preset: enabled)
     Active: inactive (dead)

nixos-config on  main [!?] 
❯ journalctl --user -u sunshine
-- No entries --

Notify maintainers

@tarantoj @Scrumplex

Metadata

Please run nix-shell -p nix-info --run "nix-info -m" and paste the result.

nixos-config on  main [!?] 
❯ nix-shell -p nix-info --run "nix-info -m"
 - system: `"x86_64-linux"`
 - host os: `Linux 6.6.48, NixOS, 24.05 (Uakari), 24.05.4469.6e99f2a27d60`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.18.5`
 - channels(root): `"home-manager-24.05.tar.gz, nixos-24.05"`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixos`


Add a :+1: reaction to issues you find important.

Redhawk18 avatar Sep 05 '24 18:09 Redhawk18

Also does enabling services.sunshine.capSysAdmin mean that the service runs as root? or just has some root perms?

Redhawk18 avatar Sep 05 '24 18:09 Redhawk18

Do you have the autoStart option set to true? Looks like that will make it start once you start up your graphical session.

svrana avatar Sep 05 '24 18:09 svrana

Do you have the autoStart option set to true? Looks like that will make it start once you start up your graphical session.

No because I saw its enabled by default

Redhawk18 avatar Sep 05 '24 18:09 Redhawk18

After restarting the warning I got about not having access to capsysadmin also disappeared. So what happened was

  1. I added sunshine like the bug report above
  2. I accessed the webui, and saw the warnings about capsysadmin
  3. enabled capsysadmin and rebuilt, I noticed that the service did not automatically restart
  4. I manually restarted the service and the warning seemed to have gone away.

I'm not sure if this is intended but it's weird

Redhawk18 avatar Sep 05 '24 18:09 Redhawk18

Yeah, can confirm the service does not automatically start after enabling.

These rules must need some work, but I'll have to read more or just start playing with it.

      wantedBy = mkIf cfg.autoStart [ "graphical-session.target" ];
      partOf = [ "graphical-session.target" ];
      wants = [ "graphical-session.target" ];
      after = [ "graphical-session.target" ];

svrana avatar Sep 05 '24 18:09 svrana

Yeah, can confirm the service does not automatically start after enabling.

These rules must need some work, but I'll have to read more or just start playing with it.

      wantedBy = mkIf cfg.autoStart [ "graphical-session.target" ];
      partOf = [ "graphical-session.target" ];
      wants = [ "graphical-session.target" ];
      after = [ "graphical-session.target" ];

Thanks I thought I was going crazy lol

Redhawk18 avatar Sep 05 '24 19:09 Redhawk18

Does your graphical-session.target get started? If you are not using a traditional DE, you might need to use a wrapper to start the target for you

Scrumplex avatar Sep 05 '24 19:09 Scrumplex

Does your graphical-session.target get started? If you are not using a traditional WM, you might need to use a wrapper to start the target for you

It should have been, I use kde.

Redhawk18 avatar Sep 05 '24 19:09 Redhawk18

Does it start after a reboot? I use this module with Plasma, and it autostarts on boot/login for me normally.

devusb avatar Sep 05 '24 19:09 devusb

Does it start after a reboot? I use this module with Plasma, and it autostarts on boot/login for me normally.

I haven't tested this but all I needed to do was a service restart so I assume yes.

Redhawk18 avatar Sep 05 '24 20:09 Redhawk18

I think this is expected behavior -- pretty the unit will not start if it's just enabled after the target is reached -- it will either need to be started manually, or the system (or DE) will need to be restarted to re-trigger everything needed for the target. @Scrumplex thoughts on if this seems reasonable?

devusb avatar Sep 05 '24 20:09 devusb

Can confirm it does start automatically after I restart my DM. Is this default NixOS behavior? not to start a service or at least warn that it may need to be started automatically? (I believe HM adds some warnings when units need to be started which is nice.)

svrana avatar Sep 05 '24 20:09 svrana

Can confirm it does start automatically after I restart my DM. Is this default NixOS behavior? not to start a service or at least warn that it may need to be started automatically? (I believe HM adds some warnings when units need to be started which is nice.)

It should automatically restart if a config option change requires a restart. Because if you don't you end of up "ghost" like settings that aren't in your config

Redhawk18 avatar Sep 05 '24 21:09 Redhawk18

IMO it would be a valid assumption to start the unit if it wasn't running yet, but this is a long standing issue with user units and NixOS. I can't find the issue that's tracking this right now

Scrumplex avatar Sep 05 '24 21:09 Scrumplex

this is a long standing issue with user units and NixOS. I can't find the issue that's tracking this right now

@Scrumplex , was this it or was it somewhere else?

  • https://github.com/NixOS/nixpkgs/issues/21460

ruffsl avatar Jun 22 '25 23:06 ruffsl

this is a long standing issue with user units and NixOS. I can't find the issue that's tracking this right now

@Scrumplex , was this it or was it somewhere else?

* [systemd user-units can't be easily enabled/disabled per user #21460](https://github.com/NixOS/nixpkgs/issues/21460)

Not quite. I meant that changes to user units don't cause restarts to user services unless Home Manager (or a similar tool) is used.

Scrumplex avatar Jun 23 '25 09:06 Scrumplex