summary refs log tree commit diff
path: root/pkgs/servers/jellyfin/default.nix
blob: 636a1b6d02a0de0496ff8783c9f4fa522770899d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
{ lib
, fetchFromGitHub
, fetchurl
, linkFarmFromDrvs
, makeWrapper
, nixosTests
, stdenv
, dotnetCorePackages
, dotnetPackages
, ffmpeg
, fontconfig
, freetype
, jellyfin-web
, sqlite
}:

let
  runtimeDeps = [
    ffmpeg
    fontconfig
    freetype
  ];

  os = if stdenv.isDarwin then "osx" else "linux";
  arch =
    with stdenv.hostPlatform;
    if isx86_32 then "x86"
    else if isx86_64 then "x64"
    else if isAarch32 then "arm"
    else if isAarch64 then "arm64"
    else lib.warn "Unsupported architecture, some image processing features might be unavailable" "unknown";
  musl = lib.optionalString stdenv.hostPlatform.isMusl
    (lib.warnIf (arch != "x64") "Some image processing features might be unavailable for non x86-64 with Musl"
      "musl-");
  # https://docs.microsoft.com/en-us/dotnet/core/rid-catalog#using-rids
  runtimeId = "${os}-${musl}${arch}";

  dotnet-sdk = dotnetCorePackages.sdk_5_0;
  dotnet-net = dotnetCorePackages.net_5_0;
  dotnet-aspnetcore = dotnetCorePackages.aspnetcore_5_0;
in
stdenv.mkDerivation rec {
  pname = "jellyfin";
  version = "10.7.5"; # ensure that jellyfin-web has matching version

  src = fetchFromGitHub {
    owner = "jellyfin";
    repo = "jellyfin";
    rev = "v${version}";
    sha256 = "DlbNZpomNki9zrfG0C7He0Xrq79vx4Rn8ixpekvk34E=";
  };

  nativeBuildInputs = [
    dotnet-sdk
    dotnetPackages.Nuget
    makeWrapper
  ];

  propagatedBuildInputs = [
    dotnet-aspnetcore
    sqlite
  ];

  nugetDeps = linkFarmFromDrvs "${pname}-nuget-deps" (import ./nuget-deps.nix {
    fetchNuGet = { name, version, sha256 }: fetchurl {
      name = "nuget-${name}-${version}.nupkg";
      url = "https://www.nuget.org/api/v2/package/${name}/${version}";
      inherit sha256;
    };
  });

  configurePhase = ''
    runHook preConfigure

    export HOME=$(mktemp -d)

    export DOTNET_CLI_TELEMETRY_OPTOUT=1
    export DOTNET_NOLOGO=1

    nuget sources Add -Name nixos -Source "$PWD/nixos"
    nuget init "$nugetDeps" "$PWD/nixos"

    # FIXME: https://github.com/NuGet/Home/issues/4413
    mkdir -p $HOME/.nuget/NuGet
    cp $HOME/.config/NuGet/NuGet.Config $HOME/.nuget/NuGet

    runHook postConfigure
  '';

  buildPhase = ''
    runHook preBuild

    dotnet publish Jellyfin.Server \
      --configuration Release \
      --runtime ${runtimeId} \
      --no-self-contained \
      --output $out/opt/jellyfin

    runHook postBuild
  '';

  installPhase = ''
    runHook preInstall

    makeWrapper ${dotnet-aspnetcore}/bin/dotnet $out/bin/jellyfin \
      --suffix LD_LIBRARY_PATH : "${lib.makeLibraryPath runtimeDeps}" \
      --add-flags "$out/opt/jellyfin/jellyfin.dll" \
      --add-flags "--ffmpeg ${ffmpeg}/bin/ffmpeg" \
      --add-flags "--webdir ${jellyfin-web}/share/jellyfin-web"

    runHook postInstall
  '';

  passthru.tests = {
    smoke-test = nixosTests.jellyfin;
  };

  passthru.updateScript = ./update.sh;

  meta = with lib; {
    description = "The Free Software Media System";
    homepage = "https://jellyfin.org/";
    # https://github.com/jellyfin/jellyfin/issues/610#issuecomment-537625510
    license = licenses.gpl2Plus;
    maintainers = with maintainers; [ nyanloutre minijackson purcell jojosch ];
  };
}