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