[Nix-dev] [PATCH] pulseaudio: Add support for package configuration files.

Luca Bruno lethalman88 at gmail.com
Wed Nov 18 10:02:33 CET 2015


On 17/11/2015 21:39, Jookia wrote:
> In a fashion like udev's support, this patch allows configurations from packages
> to be merged in to directories for PulseAudio to read from. Currently supported
> directories are the alsa-mixer mdoule's profile-sets and paths.
>
> This is accomplished by patching PulseAudio to read directories from environment
> variables globally defined by NixOS rather from the data path in the Nix store.
> Modules that support it (such as the alsa module) can still be configured at
> runtime to use specific paths, this just changes the default paths.
>
> The environment variables are only used if they're defined, as such the previous
> behaviour can be reverted to if the variables are unset or NixOS isn't running.
> ---
>  nixos/modules/config/pulseaudio.nix       | 43 +++++++++++++++++++++++++
>  pkgs/servers/pulseaudio/custom-dirs.patch | 52 +++++++++++++++++++++++++++++++
>  pkgs/servers/pulseaudio/default.nix       |  2 +-
>  3 files changed, 96 insertions(+), 1 deletion(-)
>  create mode 100644 pkgs/servers/pulseaudio/custom-dirs.patch
>
> diff --git a/nixos/modules/config/pulseaudio.nix b/nixos/modules/config/pulseaudio.nix
> index 2ebc612..bad4bf3 100644
> --- a/nixos/modules/config/pulseaudio.nix
> +++ b/nixos/modules/config/pulseaudio.nix
> @@ -52,6 +52,37 @@ let
>      }
>    '');
>  
> +  # Create a directory full of configuration files for PulseAudio to use for
> +  # various modules. Packages are scanned similiar how udev does it.
> +  moduleEnvVars = {
> +    PA_ALSA_PATHS_DIR = "${moduleConf}/alsa-paths";
> +    PA_ALSA_PROFILE_SETS_DIR = "${moduleConf}/alsa-profiles";
> +  };
> +  moduleConf = stdenv.mkDerivation {
> +    name = "pulseaudio-moduleconf";
> +
> +    preferLocalBuild = true;
> +    allowSubstitutes = false;
> +
> +    buildCommand = ''
> +      mkdir -p $out/{alsa-profiles,alsa-paths}
> +      shopt -s nullglob
> +      set +o pipefail
> +
> +      function copy_dir() {
> +        for j in $1/$2/*; do
> +          echo "Copying $i to $out/$3/$(basename $j)"
> +          cat $j > $out/$3/$(basename $j)
> +        done
> +      }
> +
> +      for i in ${toString cfg.packages}; do
> +        echo "Adding configuration for package $i"
> +        copy_dir $i/usr/share/pulseaudio/alsa-mixer profile-sets alsa-profiles
> +        copy_dir $i/usr/share/pulseaudio/alsa-mixer paths alsa-paths
> +      done
> +    '';
> +  };
>  in {
>  
>    options = {
> @@ -96,6 +127,17 @@ in {
>          '';
>        };
>  
> +      packages = mkOption {
> +        type = types.listOf types.path;
> +        description = ''
> +          List of packages containing additional PulseAudio configuration.
> +          All files found in the following directories:
> +          <filename><replaceable>pkg</replaceable>/usr/share/lib/pulseaudio/alsa-mixer/profile-sets</filename>
> +          <filename><replaceable>pkg</replaceable>/usr/share/lib/pulseaudio/alsa-mixer/paths</filename>
> +          will be included.
> +        '';
> +      };
> +
>        package = mkOption {
>          type = types.package;
>          default = pulseaudioLight;
> @@ -130,6 +172,7 @@ in {
>        };
>  
>        hardware.pulseaudio.configFile = mkDefault "${cfg.package}/etc/pulse/default.pa";
> +      environment.sessionVariables = moduleEnvVars;
>      }
>  
>      (mkIf cfg.enable {
> diff --git a/pkgs/servers/pulseaudio/custom-dirs.patch b/pkgs/servers/pulseaudio/custom-dirs.patch
> new file mode 100644
> index 0000000..00e2ee7
> --- /dev/null
> +++ b/pkgs/servers/pulseaudio/custom-dirs.patch
> @@ -0,0 +1,52 @@
> +diff -Naur pulseaudio-7.0/src/modules/alsa/alsa-mixer.c pulseaudio-7.0.new/src/modules/alsa/alsa-mixer.c
> +--- pulseaudio-7.0/src/modules/alsa/alsa-mixer.c	2015-09-15 14:46:06.000000000 +1000
> ++++ pulseaudio-7.0.new/src/modules/alsa/alsa-mixer.c	2015-11-18 12:58:33.490001078 +1100
> +@@ -2521,10 +2521,11 @@
> + }
> + 
> + static const char *get_default_paths_dir(void) {
> ++    char *env = getenv("PA_ALSA_PATHS_DIR");
> +     if (pa_run_from_build_tree())
> +         return PA_SRCDIR "/modules/alsa/mixer/paths/";
> +     else
> +-        return PA_ALSA_PATHS_DIR;
> ++        return (env ? env : PA_ALSA_PATHS_DIR);
> + }
> + 
> + pa_alsa_path* pa_alsa_path_new(const char *paths_dir, const char *fname, pa_alsa_direction_t direction) {
> +@@ -4347,6 +4348,7 @@
> +     pa_alsa_profile *p;
> +     pa_alsa_mapping *m;
> +     pa_alsa_decibel_fix *db_fix;
> ++    char *env;
> +     char *fn;
> +     int r;
> +     void *state;
> +@@ -4392,9 +4394,10 @@
> +     if (!fname)
> +         fname = "default.conf";
> + 
> ++    env = getenv("PA_ALSA_PROFILE_SETS_DIR");
> +     fn = pa_maybe_prefix_path(fname,
> +                               pa_run_from_build_tree() ? PA_SRCDIR "/modules/alsa/mixer/profile-sets/" :
> +-                              PA_ALSA_PROFILE_SETS_DIR);
> ++                              (env ? env : PA_ALSA_PROFILE_SETS_DIR));
> + 
> +     r = pa_config_parse(fn, NULL, items, NULL, ps);
> +     pa_xfree(fn);
> +diff -Naur pulseaudio-7.0/src/tests/alsa-mixer-path-test.c pulseaudio-7.0.new/src/tests/alsa-mixer-path-test.c
> +--- pulseaudio-7.0/src/tests/alsa-mixer-path-test.c	2014-02-15 03:06:12.000000000 +1100
> ++++ pulseaudio-7.0.new/src/tests/alsa-mixer-path-test.c	2015-11-18 12:57:40.750001071 +1100
> +@@ -15,10 +15,11 @@
> + 
> + /* This function was copied from alsa-mixer.c */
> + static const char *get_default_paths_dir(void) {
> ++    char *env = getenv("PA_ALSA_PATHS_DIR");
> +     if (pa_run_from_build_tree())
> +         return PA_SRCDIR "/modules/alsa/mixer/paths/";
> +     else
> +-        return PA_ALSA_PATHS_DIR;
> ++        return (env ? env : PA_ALSA_PATHS_DIR);
> + }
> + 
> + static pa_strlist *load_makefile() {
> diff --git a/pkgs/servers/pulseaudio/default.nix b/pkgs/servers/pulseaudio/default.nix
> index d1888e1..fcef7cf 100644
> --- a/pkgs/servers/pulseaudio/default.nix
> +++ b/pkgs/servers/pulseaudio/default.nix
> @@ -41,7 +41,7 @@ stdenv.mkDerivation rec {
>      sha256 = "1yp8x8z4wigrzik131kjdyhn7hznazvbkbp2zz1vy9l9gqvy26na";
>    };
>  
> -  patches = [ ./caps-fix.patch ];
> +  patches = [ ./caps-fix.patch ./custom-dirs.patch ];
>  
>    nativeBuildInputs = [ pkgconfig intltool autoreconfHook ];
>  
I hope somehow will review this. Personally I'd prefer if you made a
pull request on github.


More information about the nix-dev mailing list