Personal-use NixOS configuration
1# based on https://github.com/tofu-salad/emby-server-flake/tree/a8c30e4160ee9c06ff1e875cd08dfd952868a5fb
2
3{
4 pkgs,
5 lib,
6 fetchurl,
7 ...
8}:
9
10pkgs.stdenv.mkDerivation rec {
11 pname = "emby-server";
12 version = "4.10.0.4";
13
14 src = fetchurl {
15 url = "https://github.com/MediaBrowser/Emby.Releases/releases/download/${version}/${pname}-deb_${version}_amd64.deb";
16 sha256 = "sha256-NXsUInwhnxz7xLtB8W30LOl3LwG4NQkKkNLyHjgCzB0=";
17 };
18
19 buildInputs = with pkgs; [
20 dpkg
21 expat
22 glibc
23 lttng-ust_2_12
24 zlib
25 ];
26
27 nativeBuildInputs = with pkgs; [
28 autoPatchelfHook
29 makeWrapper
30 ];
31
32 # Tell autoPatchelfHook where to find the bundled libraries
33 autoPatchelfIgnoreMissingDeps = [
34 "libavdevice.so.59"
35 "libavfilter.so.8"
36 "libavformat.so.59"
37 "libavcodec.so.59"
38 "libpostproc.so.56"
39 "libswresample.so.4"
40 "libswscale.so.6"
41 "libavutil.so.57"
42 ];
43
44 unpackPhase = ''
45 dpkg-deb -x $src unpacked
46 cd unpacked
47 '';
48
49 installPhase = ''
50 # Copy everything to the output
51 cp -r opt/emby-server $out/
52
53 # Remove systemd files and licenses we don't need
54 rm -rf $out/lib/systemd
55 rm -rf $out/licenses
56
57 # Fix paths in scripts
58 find $out/bin -type f -exec sed -i "s|/opt/emby-server|$out|g" {} \;
59
60 # Create bin directory for wrappers
61 mkdir -p $out/bin
62
63 # Create wrapper for main emby server (disable auto-updates with empty updatepackage)
64 makeWrapper "$out/bin/emby-server" $out/bin/emby \
65 --prefix LD_LIBRARY_PATH : "$out/lib:$out/lib/x86_64-linux-gnu" \
66 --add-flags "$out/EmbyServer.dll -ffmpeg $out/bin/emby-ffmpeg -ffprobe $out/bin/emby-ffprobe -updatepackage \"\""
67
68 # Create wrapper for emby-ffmpeg that sets up library path
69 mv $out/bin/emby-ffmpeg $out/bin/.emby-ffmpeg-unwrapped
70 makeWrapper "$out/bin/.emby-ffmpeg-unwrapped" $out/bin/emby-ffmpeg \
71 --prefix LD_LIBRARY_PATH : "$out/lib:$out/lib/x86_64-linux-gnu"
72
73 # Create wrapper for emby-ffdetect
74 mv $out/bin/emby-ffdetect $out/bin/.emby-ffdetect-unwrapped
75 makeWrapper "$out/bin/.emby-ffdetect-unwrapped" $out/bin/emby-ffdetect \
76 --prefix LD_LIBRARY_PATH : "$out/lib:$out/lib/x86_64-linux-gnu"
77
78 # Also wrap the direct ffmpeg/ffprobe binaries
79 mv $out/bin/ffmpeg $out/bin/.ffmpeg-unwrapped
80 makeWrapper "$out/bin/.ffmpeg-unwrapped" $out/bin/ffmpeg \
81 --prefix LD_LIBRARY_PATH : "$out/lib:$out/lib/x86_64-linux-gnu"
82
83 mv $out/bin/ffprobe $out/bin/.ffprobe-unwrapped
84 makeWrapper "$out/bin/.ffprobe-unwrapped" $out/bin/ffprobe \
85 --prefix LD_LIBRARY_PATH : "$out/lib:$out/lib/x86_64-linux-gnu"
86
87 rm -f $out/lib/libc.so.6
88 '';
89
90 # Run autoPatchelfHook manually after installPhase
91 postFixup = ''
92 # Patch all binaries to use system libraries where possible
93 # The FFmpeg libraries from the deb will be found via LD_LIBRARY_PATH
94 autoPatchelf $out/bin/.emby-ffmpeg-unwrapped || true
95 autoPatchelf $out/bin/.emby-ffdetect-unwrapped || true
96 autoPatchelf $out/bin/.ffmpeg-unwrapped || true
97 autoPatchelf $out/bin/.ffprobe-unwrapped || true
98
99 # Also patch other binaries
100 find $out/bin -name "*.so" -exec autoPatchelf {} \; || true
101 '';
102
103 meta = {
104 description = "Emby Media Server";
105 homepage = "https://emby.media/";
106 license = lib.licenses.unfree;
107 maintainers = with lib.maintainers; [ encode42 ];
108 platforms = [ "x86_64-linux" ];
109 mainProgram = "emby";
110 };
111}