This repository has no description
3.1 kB
106 lines
1{ self, pkgs, ... }:
2{
3 imports = [
4 ./mpv.nix
5 ];
6 users.users.media = {
7 isNormalUser = true;
8 uid = self.inputs.stockholm.lib.genid_uint31 "media";
9 extraGroups = [
10 "video"
11 "audio"
12 "pipewire"
13 ];
14 packages = [
15 (pkgs.writers.writeDashBin "mpv" ''
16 if test -e "$1"; then
17 mpv-ipc-cli loadfile "$(realpath "$1")"
18 else
19 mpv-ipc-cli loadfile "$1"
20 fi
21 '')
22 ];
23 };
24
25 users.users.mainUser.packages = [
26 (pkgs.writers.writeDashBin "mpv" ''
27 if test -e "$1"; then
28 mpv-ipc-cli loadfile "$(realpath "$1")"
29 else
30 mpv-ipc-cli loadfile "$1"
31 fi
32 '')
33 ];
34
35 services.xserver.displayManager.autoLogin = {
36 enable = true;
37 user = "media";
38 };
39
40 hardware.pulseaudio.configFile = pkgs.writeText "pulse.pa" ''
41 .include ${pkgs.pulseaudioFull}/etc/pulse/default.pa
42 load-module module-native-protocol-tcp auth-ip-acl=127.0.0.1;10.42.0.0/24 auth-anonymous=1
43 '';
44
45 environment.systemPackages = [
46 (pkgs.writers.writeDashBin "mpv-ipc-cli" ''
47 set -efux
48 ${pkgs.jq}/bin/jq -nc '{ "command": $ARGS.positional }' --args "$@" | ${pkgs.socat}/bin/socat - /tmp/mpv.ipc
49 '')
50 (pkgs.writers.writeDashBin "ipc-mpv" ''
51 /run/current-system/sw/bin/mpv \
52 --audio-display=no --audio-channels=stereo \
53 --audio-samplerate=48000 --audio-format=s16 \
54 --ao-pcm-file=/run/snapserver/snapfifo --ao=pcm \
55 --audio-delay=-1 \
56 "$@"
57 '')
58 pkgs.mpvc
59 (pkgs.writers.writeDashBin "iptv" ''
60 curl -Ssf 'https://iptv-org.github.io/iptv/index.nsfw.m3u' |
61 sed 's/.*,//' |
62 sed -z 's/\nhttp/,http/g' |
63 fzf --bind='enter:execute(echo {} | cut -d ',' -f 2 | xargs -0 mpv-ipc-cli loadfile)'
64 '')
65 ];
66
67 environment.variables.SOCKET = "/tmp/mpv.ipc";
68 systemd.services.mpvd = {
69 wantedBy = [ "multi-user.target" ];
70 environment.DISPLAY = ":0";
71 serviceConfig = {
72 User = "media";
73 RemainAfterExit = true;
74 Nice = "-10";
75 ExecStart = ''
76 ${pkgs.tmux}/bin/tmux -2 new-session -d -s mpvd -- /run/current-system/sw/bin/ipc-mpv \
77 --audio-display=no --audio-channels=stereo \
78 --audio-samplerate=48000 --audio-format=s16 \
79 --ao-pcm-file=/run/snapserver/snapfifo --ao=pcm \
80 --audio-delay=-1 \
81 --network-timeout=3 \
82 --untimed --cache-pause=no \
83 --idle=yes --force-window=yes \
84 --loop-playlist=inf \
85 --input-ipc-server=/tmp/mpv.ipc
86 '';
87 ExecStop = "${pkgs.tmux}/bin/tmux kill-session -t mpvd";
88 ExecStartPre = [
89 "+${pkgs.writers.writeDash "remove_socket" ''
90 set -efux
91 rm -f /tmp/mpv.ipc
92 ''}"
93 ];
94 ExecStartPost = [
95 "+${pkgs.writers.writeDash "fix_permissions" ''
96 set -efux
97 until test -e /tmp/mpv.ipc; do
98 sleep 1
99 done
100 # sleep 2
101 chmod 666 /tmp/mpv.ipc || :
102 ''}"
103 ];
104 };
105 };
106}