summaryrefslogtreecommitdiff
path: root/custom/trivmix-service.nix
diff options
context:
space:
mode:
authorGregor Kleen <gkleen@yggdrasil.li>2017-09-03 22:03:35 +0200
committerGregor Kleen <gkleen@yggdrasil.li>2017-09-03 22:03:35 +0200
commit076a87e9784635b679ab337b74ebc617c4e2dd3d (patch)
treebc4d2eeb2267931bc3bd32efb26fdab1f81e5571 /custom/trivmix-service.nix
parent739fbfc609b74754186ef29bf041e792f1c72148 (diff)
downloadnixos-076a87e9784635b679ab337b74ebc617c4e2dd3d.tar
nixos-076a87e9784635b679ab337b74ebc617c4e2dd3d.tar.gz
nixos-076a87e9784635b679ab337b74ebc617c4e2dd3d.tar.bz2
nixos-076a87e9784635b679ab337b74ebc617c4e2dd3d.tar.xz
nixos-076a87e9784635b679ab337b74ebc617c4e2dd3d.zip
Much fancier trivmix-service
Diffstat (limited to 'custom/trivmix-service.nix')
-rw-r--r--custom/trivmix-service.nix94
1 files changed, 65 insertions, 29 deletions
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 3with 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
16let 5let
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";
27in { 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 };
76in {
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}