push sheeet
Some checks failed
Periodic Merges (6h) / master → staging-nixos (push) Failing after 12m50s
Periodic Merges (6h) / master → staging-next (push) Failing after 12m54s
Periodic Merges (24h) / merge-base(master,staging) → haskell-updates (push) Failing after 11m54s
Periodic Merges (6h) / staging-next → staging (push) Failing after 12m13s
Periodic Merges (24h) / staging-next-25.05 → staging-25.05 (push) Failing after 13m24s
Periodic Merges (24h) / release-25.05 → staging-next-25.05 (push) Failing after 14m28s

This commit is contained in:
Dark Steveneq
2025-10-09 14:15:47 +02:00
commit 646b892680
49168 changed files with 5897842 additions and 0 deletions

1692
pkgs/by-name/so/sonarr/deps.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,207 @@
{
lib,
stdenvNoCC,
fetchFromGitHub,
buildDotnetModule,
dotnetCorePackages,
sqlite,
withFFmpeg ? true, # replace bundled ffprobe binary with symlink to ffmpeg package.
servarr-ffmpeg,
fetchYarnDeps,
yarn,
fixup-yarn-lock,
nodejs,
nixosTests,
# update script
writers,
python3Packages,
nix,
prefetch-yarn-deps,
fetchpatch,
applyPatches,
}:
let
version = "4.0.15.2941";
# The dotnet8 compatibility patches also change `yarn.lock`, so we must pass
# the already patched lockfile to `fetchYarnDeps`.
src = applyPatches {
src = fetchFromGitHub {
owner = "Sonarr";
repo = "Sonarr";
tag = "v${version}";
hash = "sha256-1lBUkodBDFpJD7pyHAFb8HRLrbK8wyAboX0A2oBQnTM=";
};
postPatch = ''
mv src/NuGet.Config NuGet.Config
'';
patches = lib.optionals (lib.versionOlder version "5.0") [
# See https://github.com/Sonarr/Sonarr/issues/7442 and
# https://github.com/Sonarr/Sonarr/pull/7443.
# Unfortunately, the .NET 8 upgrade was only merged into the v5 branch,
# and it may take some time for that to become stable.
# However, the patches cleanly apply to v4 as well.
(fetchpatch {
name = "dotnet8-compatibility";
url = "https://github.com/Sonarr/Sonarr/commit/518f1799dca96a7481004ceefe39be465de3d72d.patch";
hash = "sha256-e+/rKZrTf6lWq9bmCAwnZrbEPRkqVmI7qNavpLjfpUE=";
})
(fetchpatch {
name = "dotnet8-darwin-compatibility";
url = "https://github.com/Sonarr/Sonarr/commit/1a5fa185d11d2548f45fefb8a0facd3731a946d0.patch";
hash = "sha256-6Lzo4ph1StA05+B1xYhWH+BBegLd6DxHiEiaRxGXn7k=";
})
];
};
rid = dotnetCorePackages.systemToDotnetRid stdenvNoCC.hostPlatform.system;
in
buildDotnetModule {
pname = "sonarr";
inherit version src;
strictDeps = true;
nativeBuildInputs = [
nodejs
yarn
prefetch-yarn-deps
fixup-yarn-lock
];
yarnOfflineCache = fetchYarnDeps {
yarnLock = "${src}/yarn.lock";
hash = "sha256-YkBFvv+g4p22HdM/GQAHVGGW1yLYGWpNtRq7+QJiLIw=";
};
ffprobe = lib.optionalDrvAttr withFFmpeg (lib.getExe' servarr-ffmpeg "ffprobe");
postConfigure = ''
yarn config --offline set yarn-offline-mirror "$yarnOfflineCache"
fixup-yarn-lock yarn.lock
yarn install --offline --frozen-lockfile --ignore-platform --ignore-scripts --no-progress --non-interactive
patchShebangs --build node_modules
'';
postBuild = ''
yarn --offline run build --env production
'';
postInstall =
lib.optionalString withFFmpeg ''
rm -- "$out/lib/sonarr/ffprobe"
ln -s -- "$ffprobe" "$out/lib/sonarr/ffprobe"
''
+ ''
cp -a -- _output/UI "$out/lib/sonarr/UI"
'';
# Add an alias for compatibility with Sonarr v3 package.
postFixup = ''
ln -s -- Sonarr "$out/bin/NzbDrone"
'';
nugetDeps = ./deps.json;
runtimeDeps = [ sqlite ];
dotnet-sdk = dotnetCorePackages.sdk_8_0;
dotnet-runtime = dotnetCorePackages.aspnetcore_8_0;
doCheck = true;
__darwinAllowLocalNetworking = true; # for tests
__structuredAttrs = true; # for Copyright property that contains spaces
executables = [ "Sonarr" ];
projectFile = [
"src/NzbDrone.Console/Sonarr.Console.csproj"
"src/NzbDrone.Mono/Sonarr.Mono.csproj"
];
testProjectFile = [
"src/NzbDrone.Api.Test/Sonarr.Api.Test.csproj"
"src/NzbDrone.Common.Test/Sonarr.Common.Test.csproj"
"src/NzbDrone.Core.Test/Sonarr.Core.Test.csproj"
"src/NzbDrone.Host.Test/Sonarr.Host.Test.csproj"
"src/NzbDrone.Libraries.Test/Sonarr.Libraries.Test.csproj"
"src/NzbDrone.Mono.Test/Sonarr.Mono.Test.csproj"
"src/NzbDrone.Test.Common/Sonarr.Test.Common.csproj"
];
dotnetFlags = [
"--property:TargetFramework=net8.0"
"--property:EnableAnalyzers=false"
"--property:SentryUploadSymbols=false" # Fix Sentry upload failed warnings
# Override defaults in src/Directory.Build.props that use current time.
"--property:Copyright=Copyright 2014-2025 sonarr.tv (GNU General Public v3)"
"--property:AssemblyVersion=${version}"
"--property:AssemblyConfiguration=main"
"--property:RuntimeIdentifier=${rid}"
];
# Skip manual, integration, automation and platform-dependent tests.
dotnetTestFlags = [
"--filter:${
lib.concatStringsSep "&" (
[
"TestCategory!=ManualTest"
"TestCategory!=IntegrationTest"
"TestCategory!=AutomationTest"
# setgid tests
"FullyQualifiedName!=NzbDrone.Mono.Test.DiskProviderTests.DiskProviderFixture.should_preserve_setgid_on_set_folder_permissions"
"FullyQualifiedName!=NzbDrone.Mono.Test.DiskProviderTests.DiskProviderFixture.should_clear_setgid_on_set_folder_permissions"
# we do not set application data directory during tests (i.e. XDG data directory)
"FullyQualifiedName!=NzbDrone.Mono.Test.DiskProviderTests.FreeSpaceFixture.should_return_free_disk_space"
# attempts to read /etc/*release and fails since it does not exist
"FullyQualifiedName!=NzbDrone.Mono.Test.EnvironmentInfo.ReleaseFileVersionAdapterFixture.should_get_version_info"
# fails to start test dummy because it cannot locate .NET runtime for some reason
"FullyQualifiedName!=NzbDrone.Common.Test.ProcessProviderFixture.Should_be_able_to_start_process"
"FullyQualifiedName!=NzbDrone.Common.Test.ProcessProviderFixture.kill_all_should_kill_all_process_with_name"
# makes real HTTP requests
"FullyQualifiedName!~NzbDrone.Core.Test.TvTests.RefreshEpisodeServiceFixture"
"FullyQualifiedName!~NzbDrone.Core.Test.UpdateTests.UpdatePackageProviderFixture"
]
++ lib.optionals stdenvNoCC.buildPlatform.isDarwin [
# fails on macOS
"FullyQualifiedName!~NzbDrone.Core.Test.Http.HttpProxySettingsProviderFixture"
"FullyQualifiedName!=NzbDrone.Common.Test.ServiceFactoryFixture.event_handlers_should_be_unique"
]
)
}"
];
passthru = {
tests = {
inherit (nixosTests) sonarr;
};
updateScript = writers.writePython3 "sonarr-updater" {
libraries = with python3Packages; [ requests ];
makeWrapperArgs = [
"--prefix"
"PATH"
":"
(lib.makeBinPath [
nix
prefetch-yarn-deps
])
];
} ./update.py;
};
meta = {
description = "Smart PVR for newsgroup and bittorrent users";
homepage = "https://sonarr.tv";
license = lib.licenses.gpl3Only;
maintainers = with lib.maintainers; [
fadenb
purcell
tie
niklaskorz
];
mainProgram = "Sonarr";
# platforms inherited from dotnet-sdk.
};
}

View File

@@ -0,0 +1,181 @@
import json
import os
import pathlib
import requests
import shutil
import subprocess
import sys
import tempfile
def replace_in_file(file_path, replacements):
file_contents = pathlib.Path(file_path).read_text()
for old, new in replacements.items():
if old == new:
continue
updated_file_contents = file_contents.replace(old, new)
# A dumb way to check that weve actually replaced the string.
if file_contents == updated_file_contents:
print(f"no string to replace: {old}{new}", file=sys.stderr)
sys.exit(1)
file_contents = updated_file_contents
with tempfile.NamedTemporaryFile(mode="w") as t:
t.write(file_contents)
t.flush()
shutil.copyfile(t.name, file_path)
def nix_hash_to_sri(hash):
return subprocess.run(
[
"nix",
"--extra-experimental-features", "nix-command",
"hash",
"to-sri",
"--type", "sha256",
"--",
hash,
],
stdout=subprocess.PIPE,
text=True,
check=True,
).stdout.rstrip()
nixpkgs_path = "."
attr_path = os.getenv("UPDATE_NIX_ATTR_PATH", "sonarr")
package_attrs = json.loads(subprocess.run(
[
"nix",
"--extra-experimental-features", "nix-command",
"eval",
"--json",
"--file", nixpkgs_path,
"--apply", """p: {
dir = dirOf p.meta.position;
version = p.version;
sourceHash = p.src.src.outputHash;
yarnHash = p.yarnOfflineCache.outputHash;
}""",
"--",
attr_path,
],
stdout=subprocess.PIPE,
text=True,
check=True,
).stdout)
old_version = package_attrs["version"]
new_version = old_version
# Note that we use Sonarr API instead of GitHub to fetch latest stable release.
# This corresponds to the Updates tab in the web UI. See also
# https://github.com/Sonarr/Sonarr/blob/070919a7e6a96ca7e26524996417c6f8d1b5fcaa/src/NzbDrone.Core/Update/UpdatePackageProvider.cs
version_update = requests.get(
f"https://services.sonarr.tv/v1/update/main?version={old_version}",
).json()
if version_update["available"]:
new_version = version_update["updatePackage"]["version"]
if new_version == old_version:
sys.exit()
source_nix_hash, source_store_path = subprocess.run(
[
"nix-prefetch-url",
"--name", "source",
"--unpack",
"--print-path",
f"https://github.com/Sonarr/Sonarr/archive/v{new_version}.tar.gz",
],
stdout=subprocess.PIPE,
text=True,
check=True,
).stdout.rstrip().split("\n")
old_source_hash = package_attrs["sourceHash"]
new_source_hash = nix_hash_to_sri(source_nix_hash)
package_dir = package_attrs["dir"]
package_file_name = "package.nix"
deps_file_name = "deps.json"
# To update deps.nix, we copy the package to a temporary directory and run
# passthru.fetch-deps script there.
with tempfile.TemporaryDirectory() as work_dir:
package_file = os.path.join(work_dir, package_file_name)
deps_file = os.path.join(work_dir, deps_file_name)
shutil.copytree(package_dir, work_dir, dirs_exist_ok=True)
replace_in_file(package_file, {
# NB unlike hashes, versions are likely to be used in code or comments.
# Try to be more specific to avoid false positive matches.
f"version = \"{old_version}\"": f"version = \"{new_version}\"",
old_source_hash: new_source_hash,
})
# We need access to the patched and updated src to get the patched
# `yarn.lock`.
patched_src = os.path.join(work_dir, "patched-src")
subprocess.run(
[
"nix",
"--extra-experimental-features", "nix-command",
"build",
"--impure",
"--nix-path", "",
"--include", f"nixpkgs={nixpkgs_path}",
"--include", f"package={package_file}",
"--expr", "(import <nixpkgs> { }).callPackage <package> { }",
"--out-link", patched_src,
"src",
],
check=True,
)
old_yarn_hash = package_attrs["yarnHash"]
new_yarn_hash = nix_hash_to_sri(subprocess.run(
[
"prefetch-yarn-deps",
# does not support "--" separator :(
# Also --verbose writes to stdout, yikes.
os.path.join(patched_src, "yarn.lock"),
],
stdout=subprocess.PIPE,
text=True,
check=True,
).stdout.rstrip())
replace_in_file(package_file, {
old_yarn_hash: new_yarn_hash,
})
# Generate nuget-to-json dependency lock file.
fetch_deps = os.path.join(work_dir, "fetch-deps")
subprocess.run(
[
"nix",
"--extra-experimental-features", "nix-command",
"build",
"--impure",
"--nix-path", "",
"--include", f"nixpkgs={nixpkgs_path}",
"--include", f"package={package_file}",
"--expr", "(import <nixpkgs> { }).callPackage <package> { }",
"--out-link", fetch_deps,
"passthru.fetch-deps",
],
check=True,
)
subprocess.run(
[
fetch_deps,
deps_file,
],
stdout=subprocess.DEVNULL,
check=True,
)
shutil.copy(deps_file, os.path.join(package_dir, deps_file_name))
shutil.copy(package_file, os.path.join(package_dir, package_file_name))