diff options
author | Gregor Kleen <gkleen@yggdrasil.li> | 2017-09-03 22:03:35 +0200 |
---|---|---|
committer | Gregor Kleen <gkleen@yggdrasil.li> | 2017-09-03 22:03:35 +0200 |
commit | 076a87e9784635b679ab337b74ebc617c4e2dd3d (patch) | |
tree | bc4d2eeb2267931bc3bd32efb26fdab1f81e5571 | |
parent | 739fbfc609b74754186ef29bf041e792f1c72148 (diff) | |
download | nixos-076a87e9784635b679ab337b74ebc617c4e2dd3d.tar nixos-076a87e9784635b679ab337b74ebc617c4e2dd3d.tar.gz nixos-076a87e9784635b679ab337b74ebc617c4e2dd3d.tar.bz2 nixos-076a87e9784635b679ab337b74ebc617c4e2dd3d.tar.xz nixos-076a87e9784635b679ab337b74ebc617c4e2dd3d.zip |
Much fancier trivmix-service
-rw-r--r-- | bragi.nix | 33 | ||||
-rw-r--r-- | custom/trivmix-service.nix | 94 |
2 files changed, 82 insertions, 45 deletions
@@ -1,8 +1,6 @@ | |||
1 | { config, pkgs, ... }: | 1 | { config, pkgs, ... }: |
2 | 2 | ||
3 | let | 3 | let |
4 | trivmixService = opts: (pkgs.callPackage ./custom/trivmix-service.nix opts).out; | ||
5 | thermoprint-servant = (pkgs.callPackage ./custom/thermoprint {}).thermoprint-servant; | ||
6 | inherit (pkgs) lib; | 4 | inherit (pkgs) lib; |
7 | in rec { | 5 | in rec { |
8 | imports = | 6 | imports = |
@@ -11,6 +9,7 @@ in rec { | |||
11 | ./custom/zsh.nix | 9 | ./custom/zsh.nix |
12 | ./users.nix | 10 | ./users.nix |
13 | ./custom/unit-status-mail.nix | 11 | ./custom/unit-status-mail.nix |
12 | ./custom/trivmix-service.nix | ||
14 | ]; | 13 | ]; |
15 | 14 | ||
16 | boot.loader.grub.enable = true; | 15 | boot.loader.grub.enable = true; |
@@ -145,26 +144,28 @@ in rec { | |||
145 | }; | 144 | }; |
146 | }; | 145 | }; |
147 | 146 | ||
148 | systemd.services."mpdmix0" = trivmixService { name = "mpdmix0"; connectOut = "outnode0:in"; group = "mpd"; initial = "-35dB"; }; | 147 | services.trivmix = { |
149 | systemd.services."mpdmix1" = trivmixService { name = "mpdmix1"; connectOut = "outnode1:in"; group = "mpd"; initial = "-35dB"; }; | 148 | mpdmix0 = { connectOut = "outnode0:in"; group = "mpd"; initial = "-35dB"; }; |
149 | mpdmix1 = { connectOut = "outnode1:in"; group = "mpd"; initial = "-35dB"; }; | ||
150 | 150 | ||
151 | systemd.services."passmix0" = trivmixService { name = "passmix0"; connectOut = "outnode0:in"; connectIn = "system:capture_5"; group = "vali_out"; initial = "-5dB"; }; | 151 | passmix0 = { connectOut = "outnode0:in"; connectIn = "system:capture_5"; group = "vali_out"; initial = "-5dB"; }; |
152 | systemd.services."passmix1" = trivmixService { name = "passmix1"; connectOut = "outnode1:in"; connectIn = "system:capture_6"; group = "vali_out"; initial = "-5dB"; }; | 152 | passmix1 = { connectOut = "outnode1:in"; connectIn = "system:capture_6"; group = "vali_out"; initial = "-5dB"; }; |
153 | 153 | ||
154 | systemd.services."passmix2" = trivmixService { name = "passmix2"; connectOut = "system:playback_5"; connectIn = "system:capture_1"; group = "mic_out"; initial = "1"; }; | 154 | passmix2 = { connectOut = "system:playback_5"; connectIn = "system:capture_1"; group = "mic_out"; initial = "1"; }; |
155 | systemd.services."passmix3" = trivmixService { name = "passmix3"; connectOut = "system:playback_6"; connectIn = "system:capture_1"; group = "mic_out"; initial = "1"; }; | 155 | passmix3 = { connectOut = "system:playback_6"; connectIn = "system:capture_1"; group = "mic_out"; initial = "1"; }; |
156 | 156 | ||
157 | systemd.services."passmix4" = trivmixService { name = "passmix4"; connectOut = "outnode0:in"; connectIn = "system:capture_7"; group = "hel_out"; initial = "-5dB"; }; | 157 | passmix4 = { connectOut = "outnode0:in"; connectIn = "system:capture_7"; group = "hel_out"; initial = "-5dB"; }; |
158 | systemd.services."passmix5" = trivmixService { name = "passmix5"; connectOut = "outnode1:in"; connectIn = "system:capture_8"; group = "hel_out"; initial = "-5dB"; }; | 158 | passmix5 = { connectOut = "outnode1:in"; connectIn = "system:capture_8"; group = "hel_out"; initial = "-5dB"; }; |
159 | 159 | ||
160 | systemd.services."outnode0" = trivmixService { name = "outnode0"; initial = "1"; }; | 160 | outnode0 = { initial = "1"; }; |
161 | systemd.services."outnode1" = trivmixService { name = "outnode1"; initial = "1"; }; | 161 | outnode1 = { initial = "1"; }; |
162 | 162 | ||
163 | systemd.services."headphones0" = trivmixService { name = "heaphones0"; connectOut = "system:playback_3"; connectIn = "outnode0:out"; group = "headphones"; initial = "1"; }; | 163 | headphones0 = { connectOut = "system:playback_3"; connectIn = "outnode0:out"; group = "headphones"; initial = "1"; }; |
164 | systemd.services."headphones1" = trivmixService { name = "heaphones1"; connectOut = "system:playback_4"; connectIn = "outnode1:out"; group = "headphones"; initial = "1"; }; | 164 | headphones1 = { connectOut = "system:playback_4"; connectIn = "outnode1:out"; group = "headphones"; initial = "1"; }; |
165 | 165 | ||
166 | systemd.services."speakers0" = trivmixService { name = "speakers0"; connectOut = "system:playback_7"; connectIn = "outnode0:out"; group = "speakers"; initial = "0"; }; | 166 | speakers0 = { connectOut = "system:playback_7"; connectIn = "outnode0:out"; group = "speakers"; initial = "0"; }; |
167 | systemd.services."speakers1" = trivmixService { name = "speakers1"; connectOut = "system:playback_8"; connectIn = "outnode1:out"; group = "speakers"; initial = "0"; }; | 167 | speakers1 = { connectOut = "system:playback_8"; connectIn = "outnode1:out"; group = "speakers"; initial = "0"; }; |
168 | }; | ||
168 | 169 | ||
169 | services.mpd = { | 170 | services.mpd = { |
170 | enable = true; | 171 | enable = true; |
diff --git a/custom/trivmix-service.nix b/custom/trivmix-service.nix index 44044504..e8cb5072 100644 --- a/custom/trivmix-service.nix +++ b/custom/trivmix-service.nix | |||
@@ -1,40 +1,69 @@ | |||
1 | { name | 1 | { config, lib, pkgs, ... }: |
2 | , run ? null | 2 | |
3 | , connectOut ? null | 3 | with lib; |
4 | , connectIn ? null | ||
5 | , group ? null | ||
6 | , initial ? null | ||
7 | , adjustable ? true | ||
8 | , trivmix | ||
9 | , stdenv | ||
10 | , makeWrapper | ||
11 | , jack2Full | ||
12 | , coreutils | ||
13 | , writeScript | ||
14 | }: | ||
15 | 4 | ||
16 | let | 5 | let |
17 | connect = (! isNull connectOut) || (! isNull connectIn); | 6 | cfg = config.services.trivmix; |
18 | connectScript = writeScript "connect" '' | ||
19 | #!${stdenv.shell} | ||
20 | 7 | ||
21 | PATH=${jack2Full}/bin:$PATH | 8 | mixerModule = { |
9 | connectIn = mkOption { | ||
10 | type = with types; either str (listOf str); | ||
11 | default = []; | ||
12 | description = "Ports to connect mixer input to"; | ||
13 | }; | ||
22 | 14 | ||
23 | ${optionalString (! isNull connectIn) "jack_connect ${connectIn} $1"} | 15 | connectOut = mkOption { |
24 | ${optionalString (! isNull connectOut) "jack_connect $2 ${connectOut}"} | 16 | type = with types; either str (listOf str); |
25 | ''; | 17 | default = []; |
26 | inherit (stdenv.lib) optionalString; | 18 | description = "Ports to connect mixer output to"; |
27 | in { | 19 | }; |
28 | out = { | 20 | |
21 | onConnect = mkOption { | ||
22 | type = types.lines; | ||
23 | default = ""; | ||
24 | description = "Additional shell commands to run after connections are set up"; | ||
25 | }; | ||
26 | |||
27 | adjustable = mkOption { | ||
28 | type = types.bool; | ||
29 | default = true; | ||
30 | description = "Should the volume on this mixer be adjustable?"; | ||
31 | }; | ||
32 | |||
33 | group = mkOption { | ||
34 | type = types.nullOr types.str; | ||
35 | default = null; | ||
36 | description = "Volumes of mixers that share a group name are synchronised"; | ||
37 | }; | ||
38 | |||
39 | initial = mkOption { | ||
40 | type = types.str; | ||
41 | default = "1"; | ||
42 | description = "Initial volume"; | ||
43 | }; | ||
44 | }; | ||
45 | |||
46 | service = name: mixerCfg: with mixerCfg; let | ||
47 | connectIn = if isList mixerCfg.connectIn then mixerCfg.connectIn else singleton mixerCfg.connectIn; | ||
48 | connectOut = if isList mixerCfg.connectOut then mixerCfg.connectOut else singleton mixerCfg.connectOut; | ||
49 | |||
50 | connectScript = '' | ||
51 | #!${pkgs.stdenv.shell} | ||
52 | |||
53 | ${concatMapStringsSep "\n" (port: "jack_connect ${port} $1") connectIn} | ||
54 | ${concatMapStringsSep "\n" (port: "jack_connect $2 ${port}") connectOut} | ||
55 | ${onConnect} | ||
56 | ''; | ||
57 | |||
58 | connect = (connectOut != []) || (connectIn != []) || (onConnect != []); | ||
59 | in { | ||
29 | wantedBy = [ "sound.target" ]; | 60 | wantedBy = [ "sound.target" ]; |
30 | requires = [ "jack.service" ]; | 61 | requires = [ "jack.service" ]; |
31 | before = [ "mpd.service" ]; | ||
32 | serviceConfig = { | 62 | serviceConfig = { |
33 | Type = "simple"; | 63 | Type = "simple"; |
34 | ExecStart = ''${trivmix}/bin/trivmix --client ${name} \ | 64 | ExecStart = ''${pkgs.trivmix}/bin/trivmix --client ${name} \ |
35 | ${optionalString connect "--run ${connectScript}"} \ | 65 | ${optionalString connect "--run ${connectScript}"} \ |
36 | ${optionalString (! isNull run) "--run ${run}"} \ | 66 | "--level ${initial}" \ |
37 | ${optionalString (! isNull initial) "--level ${initial}"} \ | ||
38 | ${optionalString (adjustable && isNull group) "/dev/shm/mix/${name}/level"} \ | 67 | ${optionalString (adjustable && isNull group) "/dev/shm/mix/${name}/level"} \ |
39 | ${optionalString (! isNull group) "/dev/shm/mix/${group}/level"} | 68 | ${optionalString (! isNull group) "/dev/shm/mix/${group}/level"} |
40 | ''; | 69 | ''; |
@@ -43,6 +72,13 @@ in { | |||
43 | Nice = "-10"; | 72 | Nice = "-10"; |
44 | LimitRTPRIO = "95:95"; | 73 | LimitRTPRIO = "95:95"; |
45 | LimitMEMLOCK = "infinity"; | 74 | LimitMEMLOCK = "infinity"; |
46 | }; | ||
47 | }; | 75 | }; |
76 | in { | ||
77 | options.services.trivmix = mkOption { | ||
78 | type = types.attrsOf (types.submodule mixerModule); | ||
79 | default = []; | ||
80 | description = "Definition of mixers"; | ||
81 | }; | ||
82 | |||
83 | config.systemd.services = mapAttrs service cfg; | ||
48 | } | 84 | } |