diff options
Diffstat (limited to 'custom/uucp-mediaclient.nix')
-rw-r--r-- | custom/uucp-mediaclient.nix | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/custom/uucp-mediaclient.nix b/custom/uucp-mediaclient.nix new file mode 100644 index 00000000..07afeda4 --- /dev/null +++ b/custom/uucp-mediaclient.nix | |||
@@ -0,0 +1,89 @@ | |||
1 | { config, lib, pkgs, ... }: | ||
2 | |||
3 | with lib; | ||
4 | |||
5 | let | ||
6 | cfg = config.services.uucp.media-client; | ||
7 | |||
8 | recv-media = with pkgs; stdenv.mkDerivation rec { | ||
9 | name = "recv-media"; | ||
10 | src = ./recv-media.sh; | ||
11 | |||
12 | phases = [ "unpackPhase" "buildPhase" "installPhase" ]; | ||
13 | |||
14 | unpackPhase = '' | ||
15 | cp $src recv-media | ||
16 | ''; | ||
17 | |||
18 | inherit zsh coreutils; | ||
19 | inherit (config.security) wrapperDir; | ||
20 | inherit (cfg) mediaDir; | ||
21 | utillinux = util-linux; | ||
22 | doNotify = cfg.notify.users != []; | ||
23 | ffmpeg = if doNotify then ffmpeg-full else "/no-such-path"; | ||
24 | notify = writeScript "notify.sh" '' | ||
25 | #!${zsh}/bin/zsh | ||
26 | |||
27 | ${concatMapStringsSep "\n" ({ name, ... }: "${notify-user name}/bin/notify-${name} $@") notify.users} | ||
28 | ''; | ||
29 | |||
30 | buildPhase = '' | ||
31 | substituteAllInPlace recv-media | ||
32 | ''; | ||
33 | |||
34 | installPhase = '' | ||
35 | mkdir -p $out/bin | ||
36 | |||
37 | install -m 755 -t $out/bin \ | ||
38 | recv-media | ||
39 | ''; | ||
40 | }; | ||
41 | |||
42 | |||
43 | in { | ||
44 | options = { | ||
45 | services.uucp.media-client = { | ||
46 | remoteNodes = mkOption { | ||
47 | type = with types; listOf str; | ||
48 | default = []; | ||
49 | description = '' | ||
50 | Servers to receive media from | ||
51 | ''; | ||
52 | }; | ||
53 | |||
54 | notify = { | ||
55 | users = mkOption { | ||
56 | type = with types; listOf str; | ||
57 | default = []; | ||
58 | description = '' | ||
59 | Users to notify | ||
60 | ''; | ||
61 | }; | ||
62 | |||
63 | extractTitle = mkOption { | ||
64 | type = types.bool; | ||
65 | default = true; | ||
66 | description = '' | ||
67 | Use ffmpeg to include the media title in notifications | ||
68 | ''; | ||
69 | }; | ||
70 | }; | ||
71 | |||
72 | mediaDir = mkOption { | ||
73 | type = types.path; | ||
74 | default = "/var/media"; | ||
75 | description = "Media directory"; | ||
76 | }; | ||
77 | }; | ||
78 | }; | ||
79 | |||
80 | config = mkIf (cfg.remoteNodes != []) { | ||
81 | imports = [ ./custom/notify-users.nix ]; | ||
82 | |||
83 | services.uucp.commandPath = [ "${recv-media}/bin" ]; | ||
84 | services.uucp.remoteNodes = genAttrs cfg.remoteNodes (name: { commands = ["recv-media"]; } ); | ||
85 | |||
86 | services.notify-users = notify.users; | ||
87 | }; | ||
88 | } | ||
89 | |||