How to enable ALSA device/monitor at boot if not connected?

Hi!

I have a media PC in my living room which sometimes is just for music with an S/PDIF (toslink) cable and sometimes for watching stuff on a projector.

I’m just having problems with both outputs:

  • The sound only works on toslink if an audio jack is inserted (then the toslink mirrors the audio output). It also works if I execute amixer -c 0 set Master on
  • If I turn on the PC before I turn on the projector, the video output is deactivated. So the projector needs to be turned on before the PC, which is inconvenient for letting it run for music only.

I couldn’t find any settings to activate ALSA devices and couldn’t figure out how to config the stuff with wireplumber (the files in ~/.local/state/wireplumber/ stay the same after turning the device on/off with amixer).

And is there an option to turn on the display? Or is it due to my choice of Display manager? (Openbox on X11 with kodi fullscreen in Autostart)

Here’s my audio config:

  services.pipewire = {
    enable = true;
    audio.enable = true;
    pulse.enable = true;
    alsa.enable = true;
    alsa.support32Bit = true;
    wireplumber.enable = true;
    jack.enable = true;
  };

Thanks in advance! :slight_smile:

I managed to find it out on my own. For ALSA, I created a systemd service:

ystemd.user.services.activate-sound = {
    enable = true;
    after = [ "sound.target" ];
    wantedBy = [ "default.target" ];
    description = "Activate the soundcard, no matter if there's an audio jack plugged in";
    serviceConfig = {
      Type = "oneshot";
      ExecStart = ''${pkgs.alsa-utils}/bin/amixer -c 0 set Master on'';
    };
  };

And for the projector, I stole the systemd-service from the service.autorandr option:

systemd.user.services.autorandr-common = {
  wantedBy = [ "sleep.target" ];
  description = "Autorandr execution hook";
  after = [ "sleep.target" ];

  startLimitIntervalSec = 5;
  startLimitBurst = 1;
  serviceConfig = {
    ExecStart = ''
        ${pkgs.autorandr}/bin/autorandr common
      '';
      Type = "oneshot";
      RemainAfterExit = false;
      KillMode = "process";
      environment.DISPLAY = ":0";
  };
};

Still not sure if there is still a prepared option, but this works, too. Maybe the autorandr --common stuff could be put into nixpkgs, though.