nixos-config/nixos/modules/system/audio.nix

161 lines
4.3 KiB
Nix
Raw Normal View History

2019-10-24 02:20:38 +02:00
{ config, lib, pkgs, ... }:
with lib;
let
ladspaPath = "${pkgs.ladspaPlugins}/lib/ladspa";
2019-12-20 05:54:26 +01:00
jackScript =
pkgs.writeShellScriptBin "jack" (lib.fileContents ../../assets/jack.sh);
2019-10-24 02:20:38 +02:00
queueElement = {
options = {
plugin = mkOption {
2019-12-20 05:54:26 +01:00
type = with types; str;
2019-10-24 02:20:38 +02:00
description = "file name without suffix of the plugin";
};
label = mkOption {
2019-12-20 05:54:26 +01:00
type = with types; str;
2019-10-24 02:20:38 +02:00
description = "label of the queue element (needs to be correct)";
};
control = mkOption {
2019-12-20 05:54:26 +01:00
type = with types; listOf str;
2019-10-24 02:20:38 +02:00
description = "parameter of plugin";
};
};
};
sinkElement = {
options = {
name = mkOption {
2019-12-20 05:54:26 +01:00
type = with types; str;
2019-10-24 02:20:38 +02:00
description = "name of the sink";
};
queue = mkOption {
2019-12-20 05:54:26 +01:00
type = with types; listOf (submodule queueElement);
2019-10-24 02:20:38 +02:00
description = "queues";
};
};
};
cfg = config.system.custom.audio;
2021-11-01 09:20:42 +01:00
in
{
2019-10-24 02:20:38 +02:00
options.system.custom.audio = {
enable = mkEnableOption "use PluseAudio";
2019-12-20 05:54:26 +01:00
sinks = mkOption {
type = with types; listOf (submodule sinkElement);
2019-10-24 02:20:38 +02:00
description = "list of sinks";
};
};
config = mkIf cfg.enable {
# add virtual midi module
# -----------------------
2020-02-18 23:28:39 +01:00
#boot = {
# # to route midi signals
# # between bitwig and vcvrack
# kernelModules = [ "snd_virmidi" ];
# # index=-2 prevents from beeing recognised as the default
# # audio device
# # midi_devs limit the number of midi devices.
# extraModprobeConfig = "options snd-virmidi index=-2 midi_devs=1";
#};
2019-10-24 02:20:38 +02:00
# LADSPA
# ------
2019-12-20 05:54:26 +01:00
programs.bash.interactiveShellInit = # sh
''
# set ladspa library path
# about testing the plugins check analyseplugin command
export LADSPA_PATH=${ladspaPath}
'';
programs.zsh.interactiveShellInit = # sh
''
# set ladspa library path
# about testing the plugins check analyseplugin command
export LADSPA_PATH=${ladspaPath}
'';
2019-10-24 02:20:38 +02:00
# PulseAudio
# ----------
# because of systemWide ensure main user is in audio group
2022-04-17 20:16:40 +02:00
system.custom.mainUser.extraGroups = [ "audio" "pipewire" ];
2019-10-24 02:20:38 +02:00
2022-04-17 20:16:40 +02:00
# todo use pipewire for this
2019-10-24 02:20:38 +02:00
hardware.pulseaudio = {
2023-05-29 20:27:56 +02:00
enable = false;
2020-02-18 23:28:39 +01:00
package = pkgs.pulseaudioFull;
2019-10-24 02:20:38 +02:00
# all in audio group can do audio
2022-09-23 20:29:18 +02:00
systemWide = false;
2019-10-24 02:20:38 +02:00
extraConfig = ''
2019-12-20 05:54:26 +01:00
# automatically switch to newly-connected devices
load-module module-switch-on-connect
# http://plugin.org.uk/ladspa-swh/docs/ladspa-swh.html
# https://gavv.github.io/articles/pulseaudio-under-the-hood/#ladspa-plugin-sink
${builtins.toString (flip map cfg.sinks (sink: ''
# ladspa sink : ${sink.name}
# -------------
${builtins.toString (flip imap0 (reverseList sink.queue)
(index: queua:
let
sinkName = suffix: "${sink.name}${builtins.toString suffix}";
sinkValue = "sink_name=${sinkName index}";
sinkDescription = "sink_properties=device.description=${
sinkName index
}-${queua.label}";
2020-02-18 23:28:39 +01:00
masterValue = if (index == 0) then
""
else
"sink_master=${sinkName (index - 1)}";
2019-12-20 05:54:26 +01:00
pluginValue = "plugin=${ladspaPath}/${queua.plugin}";
labelValue = "label=${queua.label}";
controlValue = "control=${
builtins.toString
(foldl (a: b: "${a},${b}") (head queua.control)
(tail queua.control))
}";
in ''
# ${sinkName index} : ${queua.label}
load-module module-ladspa-sink ${sinkValue} ${sinkDescription} ${masterValue} ${pluginValue} ${labelValue} ${controlValue}
''))}
2019-10-24 02:20:38 +02:00
''))}
2019-12-20 05:54:26 +01:00
'';
2019-10-24 02:20:38 +02:00
};
# Packages needed
# ---------------
2019-12-20 05:54:26 +01:00
environment.systemPackages = with pkgs; [
2019-10-24 02:20:38 +02:00
# Music making
2020-02-18 23:28:39 +01:00
# ------------
#jackScript
#jack2Full
#patchage
#zynaddsubfx
#qjackctl
2019-10-24 02:20:38 +02:00
2020-02-18 23:28:39 +01:00
alsaUtils
2019-10-24 02:20:38 +02:00
# LADSPA
# ------
ladspaPlugins
ladspa-sdk
# PulseAudio control
# ------------------
pavucontrol
lxqt.pavucontrol-qt
];
};
}