@ -4,6 +4,7 @@
with lib ;
let
json = pkgs . formats . json { } ;
cfg = config . services . pipewire . media-session ;
enable32BitAlsaPlugins = cfg . alsa . support32Bit
&& pkgs . stdenv . isx86_64
@ -17,24 +18,13 @@ let
media-session = ( builtins . fromJSON ( builtins . readFile ./media-session.conf.json ) ) ;
v4l2-monitor = ( builtins . fromJSON ( builtins . readFile ./v4l2-monitor.conf.json ) ) ;
} ;
# Helpers for generating the pipewire JSON config file
mkSPAValueString = v :
if builtins . isList v then " [ ${ lib . concatMapStringsSep " " mkSPAValueString v } ] "
else if lib . types . attrs . check v then
" { ${ lib . concatStringsSep " " ( mkSPAKeyValue v ) } } "
else if builtins . isString v then " \" ${ lib . generators . mkValueStringDefault { } v } \" "
else lib . generators . mkValueStringDefault { } v ;
mkSPAKeyValue = attrs : map ( def : def . content ) (
lib . sortProperties
(
lib . mapAttrsToList
( k : v : lib . mkOrder ( v . _priority or 1000 ) " ${ lib . escape [ " = " " : " ] k } = ${ mkSPAValueString ( v . _content or v ) } " )
attrs
)
) ;
toSPAJSON = attrs : lib . concatStringsSep " \n " ( mkSPAKeyValue attrs ) ;
configs = {
alsa-monitor = recursiveUpdate defaults . alsa-monitor cfg . config . alsa-monitor ;
bluez-monitor = recursiveUpdate defaults . bluez-monitor cfg . config . bluez-monitor ;
media-session = recursiveUpdate defaults . media-session cfg . config . media-session ;
v4l2-monitor = recursiveUpdate defaults . v4l2-monitor cfg . config . v4l2-monitor ;
} ;
in {
meta = {
@ -62,7 +52,7 @@ in {
config = {
media-session = mkOption {
type = types . attrs ;
type = json . type ;
description = ''
Configuration for the media session core . For details see
https://gitlab.freedesktop.org/pipewire/pipewire/-/blob/$ { cfg . package . version } /src/daemon/media-session.d/media-session.conf
@ -71,7 +61,7 @@ in {
} ;
alsa-monitor = mkOption {
type = types . attrs ;
type = json . type ;
description = ''
Configuration for the alsa monitor . For details see
https://gitlab.freedesktop.org/pipewire/pipewire/-/blob/$ { cfg . package . version } /src/daemon/media-session.d/alsa-monitor.conf
@ -80,7 +70,7 @@ in {
} ;
bluez-monitor = mkOption {
type = types . attrs ;
type = json . type ;
description = ''
Configuration for the bluez5 monitor . For details see
https://gitlab.freedesktop.org/pipewire/pipewire/-/blob/$ { cfg . package . version } /src/daemon/media-session.d/bluez-monitor.conf
@ -89,7 +79,7 @@ in {
} ;
v4l2-monitor = mkOption {
type = types . attrs ;
type = json . type ;
description = ''
Configuration for the V4L2 monitor . For details see
https://gitlab.freedesktop.org/pipewire/pipewire/-/blob/$ { cfg . package . version } /src/daemon/media-session.d/v4l2-monitor.conf
@ -106,15 +96,34 @@ in {
systemd . packages = [ cfg . package ] ;
systemd . user . services . pipewire-media-session . wantedBy = [ " p i p e w i r e . s e r v i c e " ] ;
environment . etc . " p i p e w i r e / m e d i a - s e s s i o n . d / m e d i a - s e s s i o n . c o n f " = { text = toSPAJSON ( recursiveUpdate defaults . media-session cfg . config . media-session ) ; } ;
environment . etc . " p i p e w i r e / m e d i a - s e s s i o n . d / v 4 l 2 - m o n i t o r . c o n f " = { text = toSPAJSON ( recursiveUpdate defaults . v4l2-monitor cfg . config . v4l2-monitor ) ; } ;
environment . etc . " p i p e w i r e / m e d i a - s e s s i o n . d / m e d i a - s e s s i o n . c o n f " = {
source = json . generate " m e d i a - s e s s i o n . c o n f " configs . media-session ;
} ;
environment . etc . " p i p e w i r e / m e d i a - s e s s i o n . d / v 4 l 2 - m o n i t o r . c o n f " = {
source = json . generate " v 4 l 2 - m o n i t o r . c o n f " configs . v4l2-monitor ;
} ;
environment . etc . " p i p e w i r e / m e d i a - s e s s i o n . d / w i t h - a l s a " = mkIf config . services . pipewire . alsa . enable { text = " " ; } ;
environment . etc . " p i p e w i r e / m e d i a - s e s s i o n . d / a l s a - m o n i t o r . c o n f " = mkIf config . services . pipewire . alsa . enable { text = toSPAJSON ( recursiveUpdate defaults . alsa-monitor cfg . config . alsa-monitor ) ; } ;
environment . etc . " p i p e w i r e / m e d i a - s e s s i o n . d / w i t h - a l s a " =
mkIf config . services . pipewire . alsa . enable {
text = " " ;
} ;
environment . etc . " p i p e w i r e / m e d i a - s e s s i o n . d / a l s a - m o n i t o r . c o n f " =
mkIf config . services . pipewire . alsa . enable {
source = json . generate " a l s a - m o n i t o r . c o n f " configs . alsa-monitor ;
} ;
environment . etc . " p i p e w i r e / m e d i a - s e s s i o n . d / w i t h - p u l s e a u d i o " = mkIf config . services . pipewire . pulse . enable { text = " " ; } ;
environment . etc . " p i p e w i r e / m e d i a - s e s s i o n . d / b l u e z - m o n i t o r . c o n f " = mkIf config . services . pipewire . pulse . enable { text = toSPAJSON ( recursiveUpdate defaults . bluez-monitor cfg . config . bluez-monitor ) ; } ;
environment . etc . " p i p e w i r e / m e d i a - s e s s i o n . d / w i t h - p u l s e a u d i o " =
mkIf config . services . pipewire . pulse . enable {
text = " " ;
} ;
environment . etc . " p i p e w i r e / m e d i a - s e s s i o n . d / b l u e z - m o n i t o r . c o n f " =
mkIf config . services . pipewire . pulse . enable {
source = json . generate " b l u e z - m o n i t o r . c o n f " configs . bluez-monitor ;
} ;
environment . etc . " p i p e w i r e / m e d i a - s e s s i o n . d / w i t h - j a c k " = mkIf config . services . pipewire . jack . enable { text = " " ; } ;
environment . etc . " p i p e w i r e / m e d i a - s e s s i o n . d / w i t h - j a c k " =
mkIf config . services . pipewire . jack . enable {
text = " " ;
} ;
} ;
}