nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 lib,
3 stdenvNoCC,
4 fetchFromGitHub,
5 buildDotnetModule,
6 dotnetCorePackages,
7 sqlite,
8 withFFmpeg ? true, # replace bundled ffprobe binary with symlink to ffmpeg package.
9 servarr-ffmpeg,
10 fetchYarnDeps,
11 yarn,
12 fixup-yarn-lock,
13 nodejs,
14 nixosTests,
15 # update script
16 writers,
17 python3Packages,
18 nix,
19 prefetch-yarn-deps,
20 fetchpatch,
21 applyPatches,
22}:
23let
24 version = "4.0.16.2944";
25 # The dotnet8 compatibility patches also change `yarn.lock`, so we must pass
26 # the already patched lockfile to `fetchYarnDeps`.
27 src = applyPatches {
28 src = fetchFromGitHub {
29 owner = "Sonarr";
30 repo = "Sonarr";
31 tag = "v${version}";
32 hash = "sha256-ec/fxCUvKd6/+zrWLccnOsCwnZucZkEeCz9VpzdtjTg=";
33 };
34 postPatch = ''
35 mv src/NuGet.Config NuGet.Config
36
37 # error CS0104: 'IPNetwork' is an ambiguous reference between 'Microsoft.AspNetCore.HttpOverrides.IPNetwork' and 'System.Net.IPNetwork'
38 substituteInPlace src/NzbDrone.Host/Startup.cs \
39 --replace-fail 'IPNetwork' 'Microsoft.AspNetCore.HttpOverrides.IPNetwork'
40 '';
41 patches = lib.optionals (lib.versionOlder version "5.0") [
42 # See https://github.com/Sonarr/Sonarr/issues/7442 and
43 # https://github.com/Sonarr/Sonarr/pull/7443.
44 # Unfortunately, the .NET 8 upgrade was only merged into the v5 branch,
45 # and it may take some time for that to become stable.
46 # However, the patches cleanly apply to v4 as well.
47 (fetchpatch {
48 name = "dotnet8-compatibility";
49 url = "https://github.com/Sonarr/Sonarr/commit/518f1799dca96a7481004ceefe39be465de3d72d.patch";
50 hash = "sha256-e+/rKZrTf6lWq9bmCAwnZrbEPRkqVmI7qNavpLjfpUE=";
51 })
52 (fetchpatch {
53 name = "dotnet8-darwin-compatibility";
54 url = "https://github.com/Sonarr/Sonarr/commit/1a5fa185d11d2548f45fefb8a0facd3731a946d0.patch";
55 hash = "sha256-6Lzo4ph1StA05+B1xYhWH+BBegLd6DxHiEiaRxGXn7k=";
56 })
57 ];
58 };
59 rid = dotnetCorePackages.systemToDotnetRid stdenvNoCC.hostPlatform.system;
60in
61buildDotnetModule {
62 pname = "sonarr";
63 inherit version src;
64
65 strictDeps = true;
66 nativeBuildInputs = [
67 nodejs
68 yarn
69 prefetch-yarn-deps
70 fixup-yarn-lock
71 ];
72
73 yarnOfflineCache = fetchYarnDeps {
74 yarnLock = "${src}/yarn.lock";
75 hash = "sha256-YkBFvv+g4p22HdM/GQAHVGGW1yLYGWpNtRq7+QJiLIw=";
76 };
77
78 ffprobe = lib.optionalDrvAttr withFFmpeg (lib.getExe' servarr-ffmpeg "ffprobe");
79
80 postConfigure = ''
81 yarn config --offline set yarn-offline-mirror "$yarnOfflineCache"
82 fixup-yarn-lock yarn.lock
83 yarn install --offline --frozen-lockfile --ignore-platform --ignore-scripts --no-progress --non-interactive
84 patchShebangs --build node_modules
85 '';
86 postBuild = ''
87 yarn --offline run build --env production
88 '';
89 postInstall =
90 lib.optionalString withFFmpeg ''
91 rm -- "$out/lib/sonarr/ffprobe"
92 ln -s -- "$ffprobe" "$out/lib/sonarr/ffprobe"
93 ''
94 + ''
95 cp -a -- _output/UI "$out/lib/sonarr/UI"
96 '';
97 # Add an alias for compatibility with Sonarr v3 package.
98 postFixup = ''
99 ln -s -- Sonarr "$out/bin/NzbDrone"
100 '';
101
102 nugetDeps = ./deps.json;
103
104 runtimeDeps = [ sqlite ];
105
106 dotnet-sdk = dotnetCorePackages.sdk_8_0;
107 dotnet-runtime = dotnetCorePackages.aspnetcore_8_0;
108
109 doCheck = true;
110
111 __darwinAllowLocalNetworking = true; # for tests
112
113 __structuredAttrs = true; # for Copyright property that contains spaces
114
115 executables = [ "Sonarr" ];
116
117 projectFile = [
118 "src/NzbDrone.Console/Sonarr.Console.csproj"
119 "src/NzbDrone.Mono/Sonarr.Mono.csproj"
120 ];
121
122 testProjectFile = [
123 "src/NzbDrone.Api.Test/Sonarr.Api.Test.csproj"
124 "src/NzbDrone.Common.Test/Sonarr.Common.Test.csproj"
125 "src/NzbDrone.Core.Test/Sonarr.Core.Test.csproj"
126 "src/NzbDrone.Host.Test/Sonarr.Host.Test.csproj"
127 "src/NzbDrone.Libraries.Test/Sonarr.Libraries.Test.csproj"
128 "src/NzbDrone.Mono.Test/Sonarr.Mono.Test.csproj"
129 "src/NzbDrone.Test.Common/Sonarr.Test.Common.csproj"
130 ];
131
132 dotnetFlags = [
133 "--property:TargetFramework=net8.0"
134 "--property:EnableAnalyzers=false"
135 "--property:SentryUploadSymbols=false" # Fix Sentry upload failed warnings
136 # Override defaults in src/Directory.Build.props that use current time.
137 "--property:Copyright=Copyright 2014-2025 sonarr.tv (GNU General Public v3)"
138 "--property:AssemblyVersion=${version}"
139 "--property:AssemblyConfiguration=main"
140 "--property:RuntimeIdentifier=${rid}"
141 ];
142
143 # Skip manual, integration, automation and platform-dependent tests.
144 dotnetTestFlags = [
145 "--filter:${
146 lib.concatStringsSep "&" (
147 [
148 "TestCategory!=ManualTest"
149 "TestCategory!=IntegrationTest"
150 "TestCategory!=AutomationTest"
151
152 # setgid tests
153 "FullyQualifiedName!=NzbDrone.Mono.Test.DiskProviderTests.DiskProviderFixture.should_preserve_setgid_on_set_folder_permissions"
154 "FullyQualifiedName!=NzbDrone.Mono.Test.DiskProviderTests.DiskProviderFixture.should_clear_setgid_on_set_folder_permissions"
155
156 # we do not set application data directory during tests (i.e. XDG data directory)
157 "FullyQualifiedName!=NzbDrone.Mono.Test.DiskProviderTests.FreeSpaceFixture.should_return_free_disk_space"
158
159 # attempts to read /etc/*release and fails since it does not exist
160 "FullyQualifiedName!=NzbDrone.Mono.Test.EnvironmentInfo.ReleaseFileVersionAdapterFixture.should_get_version_info"
161
162 # fails to start test dummy because it cannot locate .NET runtime for some reason
163 "FullyQualifiedName!=NzbDrone.Common.Test.ProcessProviderFixture.Should_be_able_to_start_process"
164 "FullyQualifiedName!=NzbDrone.Common.Test.ProcessProviderFixture.kill_all_should_kill_all_process_with_name"
165
166 # makes real HTTP requests
167 "FullyQualifiedName!~NzbDrone.Core.Test.TvTests.RefreshEpisodeServiceFixture"
168 "FullyQualifiedName!~NzbDrone.Core.Test.UpdateTests.UpdatePackageProviderFixture"
169 ]
170 ++ lib.optionals stdenvNoCC.buildPlatform.isDarwin [
171 # fails on macOS
172 "FullyQualifiedName!~NzbDrone.Core.Test.Http.HttpProxySettingsProviderFixture"
173 "FullyQualifiedName!=NzbDrone.Common.Test.ServiceFactoryFixture.event_handlers_should_be_unique"
174 ]
175 )
176 }"
177 ];
178
179 passthru = {
180 tests = {
181 inherit (nixosTests) sonarr;
182 };
183
184 updateScript = writers.writePython3 "sonarr-updater" {
185 libraries = with python3Packages; [ requests ];
186 makeWrapperArgs = [
187 "--prefix"
188 "PATH"
189 ":"
190 (lib.makeBinPath [
191 nix
192 prefetch-yarn-deps
193 ])
194 ];
195 } ./update.py;
196 };
197
198 meta = {
199 description = "Smart PVR for newsgroup and bittorrent users";
200 homepage = "https://sonarr.tv";
201 license = lib.licenses.gpl3Only;
202 maintainers = with lib.maintainers; [
203 purcell
204 tie
205 niklaskorz
206 ];
207 mainProgram = "Sonarr";
208 # platforms inherited from dotnet-sdk.
209 };
210}