-
Notifications
You must be signed in to change notification settings - Fork 0
/
module.nix
51 lines (48 loc) · 1.49 KB
/
module.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.BlackHole;
drivers = map (n: pkgs.callPackage ./BlackHole.nix { }) cfg.channels;
in
{
options = {
BlackHole = {
enable = mkEnableOption "BlackHole";
# TODO: currently not supported
channels = mkOption {
default = [ 2 ];
type = types.uniq (types.listOf types.int);
description = ''
num of channels
'';
};
stateFileName = mkOption {
type = types.str;
default = "nix-BlackHole";
description = "state file to manage Audio Plug-Ins. use carefully";
};
};
};
config = mkIf cfg.enable {
system.activationScripts.extraActivation.text = ''
mkdir -p /Library/Audio/Plug-Ins/HAL
# cleanup phase
find -L /Library/Audio/Plug-Ins/HAL -type d -name "*.driver" -print0 | while IFS= read -rd "" driver; do
stateFile="$driver/Contents/Resources/${cfg.stateFileName}"
if [ -r "$state" ]; then
# if driver manged by this module
drv="$(cat "$state")"
if [ ${concatStringsSep " && " (map (driver: '' "$drv" != "${driver}"'') drivers) } ];then
rm -rf "$driver"
fi
fi
done
${concatStringsSep "\n" (map (driver: ''
cp -r ${driver}/Library/Audio/Plug-Ins/HAL/*.driver /Library/Audio/Plug-Ins/HAL/
'') drivers)}
'';
system.activationScripts.postActivation.text = ''
launchctl kickstart -kp system/com.apple.audio.coreaudiod
'';
};
}