lidarr: build from source (#492299)

This commit is contained in:
Jo
2026-02-25 18:24:56 +00:00
committed by GitHub
7 changed files with 1692 additions and 129 deletions
+6
View File
@@ -13586,6 +13586,12 @@
github = "karantan";
githubId = 7062631;
};
karaolidis = {
name = "Nikolaos Karaolidis";
email = "nick@karaolidis.com";
github = "karaolidis";
githubId = 46189100;
};
KarlJoad = {
email = "karl@hallsby.com";
github = "KarlJoad";
+1324
View File
File diff suppressed because it is too large Load Diff
+155 -66
View File
@@ -1,86 +1,175 @@
{
lib,
stdenv,
fetchurl,
libmediainfo,
stdenvNoCC,
fetchFromGitHub,
buildDotnetModule,
dotnetCorePackages,
sqlite,
curl,
makeWrapper,
icu,
dotnet-runtime,
openssl,
fetchYarnDeps,
yarn,
fixup-yarn-lock,
nodejs,
nixosTests,
zlib,
# update script
writers,
python3Packages,
nix,
prefetch-yarn-deps,
applyPatches,
}:
let
os = if stdenv.hostPlatform.isDarwin then "osx" else "linux";
arch =
{
x86_64-linux = "x64";
aarch64-linux = "arm64";
x86_64-darwin = "x64";
aarch64-darwin = "arm64";
}
."${stdenv.hostPlatform.system}" or (throw "Unsupported system: ${stdenv.hostPlatform.system}");
hash =
{
x64-linux_hash = "sha256-IPF1rsK5CN4q4GtyVE2uUE79212yqX6k42hm3lO8L6U=";
arm64-linux_hash = "sha256-/1gCHUt3sDEMkEE6vU8wNs/VAxL+exkunWiNSC5MvzY=";
x64-osx_hash = "sha256-e+AiZoLRNv2TFTTtrhQkVr5yL5e9EQJj7nAHhLgJurI=";
arm64-osx_hash = "sha256-724Y8IBvpAeIB07HtqSkXiyQua1jHO0jD3vjWw0kZpc=";
}
."${arch}-${os}_hash";
in
stdenv.mkDerivation (finalAttrs: {
pname = "lidarr";
version = "3.1.0.4875";
# The dotnet8 compatibility patches also change `yarn.lock`, so we must pass
# the already patched lockfile to `fetchYarnDeps`.
src = applyPatches {
src = fetchFromGitHub {
owner = "Lidarr";
repo = "Lidarr";
tag = "v${version}";
hash = "sha256-RCJlToQw96U8seZaD/QCPL1Pn42yw5iXFWGJCHSHwQw=";
};
postPatch = ''
mv src/NuGet.config NuGet.Config
'';
};
rid = dotnetCorePackages.systemToDotnetRid stdenvNoCC.hostPlatform.system;
in
buildDotnetModule {
pname = "lidarr";
inherit version src;
src = fetchurl {
inherit hash;
strictDeps = true;
nativeBuildInputs = [
nodejs
yarn
prefetch-yarn-deps
fixup-yarn-lock
];
url = "https://github.com/lidarr/Lidarr/releases/download/v${finalAttrs.version}/Lidarr.master.${finalAttrs.version}.${os}-core-${arch}.tar.gz";
yarnOfflineCache = fetchYarnDeps {
yarnLock = "${src}/yarn.lock";
hash = "sha256-Jq2O7gvB+PKcz6uDBMg7ox6/Bu+pikXH6JGuLfKG5fI=";
};
nativeBuildInputs = [ makeWrapper ];
installPhase = ''
runHook preInstall
mkdir -p $out/{bin,share/${finalAttrs.pname}-${finalAttrs.version}}
cp -r * $out/share/${finalAttrs.pname}-${finalAttrs.version}/.
makeWrapper "${dotnet-runtime}/bin/dotnet" $out/bin/Lidarr \
--add-flags "$out/share/${finalAttrs.pname}-${finalAttrs.version}/Lidarr.dll" \
--prefix LD_LIBRARY_PATH : ${
lib.makeLibraryPath [
curl
sqlite
libmediainfo
icu
openssl
zlib
]
}
runHook postInstall
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 = ''
cp -a -- _output/UI "$out/lib/lidarr/UI"
'';
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 = [ "Lidarr" ];
projectFile = [
"src/NzbDrone.Console/Lidarr.Console.csproj"
"src/NzbDrone.Mono/Lidarr.Mono.csproj"
];
testProjectFile = [
"src/NzbDrone.Api.Test/Lidarr.Api.Test.csproj"
"src/NzbDrone.Common.Test/Lidarr.Common.Test.csproj"
"src/NzbDrone.Core.Test/Lidarr.Core.Test.csproj"
"src/NzbDrone.Host.Test/Lidarr.Host.Test.csproj"
"src/NzbDrone.Libraries.Test/Lidarr.Libraries.Test.csproj"
"src/NzbDrone.Mono.Test/Lidarr.Mono.Test.csproj"
"src/NzbDrone.Test.Common/Lidarr.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 lidarr.audio (GNU General Public v3)"
"--property:AssemblyVersion=${version}"
"--property:AssemblyConfiguration=master"
"--property:RuntimeIdentifier=${rid}"
];
# Skip manual, integration, automation and platform-dependent tests.
testFilters = [
"TestCategory!=ManualTest"
"TestCategory!=IntegrationTest"
"TestCategory!=AutomationTest"
# makes real HTTP requests
"FullyQualifiedName!~NzbDrone.Core.Test.UpdateTests.UpdatePackageProviderFixture"
"FullyQualifiedName!~NzbDrone.Core.Test.ImportListTests.SpotifyMappingFixture"
"FullyQualifiedName!~NzbDrone.Core.Test.MetadataSource.SkyHook.SkyHookProxyFixture"
"FullyQualifiedName!~NzbDrone.Core.Test.MetadataSource.SkyHook.SkyHookProxySearchFixture"
]
++ lib.optionals stdenvNoCC.buildPlatform.isDarwin [
# fails on macOS
"FullyQualifiedName!~NzbDrone.Core.Test.Http.HttpProxySettingsProviderFixture"
];
disabledTests = [
# setgid tests
"NzbDrone.Mono.Test.DiskProviderTests.DiskProviderFixture.should_preserve_setgid_on_set_folder_permissions"
"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)
"NzbDrone.Mono.Test.DiskProviderTests.FreeSpaceFixture.should_return_free_disk_space"
"NzbDrone.Common.Test.ServiceFactoryFixture.event_handlers_should_be_unique"
# attempts to read /etc/*release and fails since it does not exist
"NzbDrone.Mono.Test.EnvironmentInfo.ReleaseFileVersionAdapterFixture.should_get_version_info"
# fails to start test dummy because it cannot locate .NET runtime for some reason
"NzbDrone.Common.Test.ProcessProviderFixture.should_be_able_to_start_process"
"NzbDrone.Common.Test.ProcessProviderFixture.exists_should_find_running_process"
"NzbDrone.Common.Test.ProcessProviderFixture.kill_all_should_kill_all_process_with_name"
];
passthru = {
updateScript = ./update.sh;
tests.smoke-test = nixosTests.lidarr;
tests = {
inherit (nixosTests) lidarr;
};
updateScript = writers.writePython3 "lidarr-updater" {
libraries = with python3Packages; [ requests ];
flakeIgnore = [ "E501" ];
makeWrapperArgs = [
"--prefix"
"PATH"
":"
(lib.makeBinPath [
nix
prefetch-yarn-deps
])
];
} ./update.py;
};
meta = {
description = "Usenet/BitTorrent music downloader";
homepage = "https://lidarr.audio/";
license = lib.licenses.gpl3;
maintainers = with lib.maintainers; [ ramonacat ];
mainProgram = "Lidarr";
platforms = [
"x86_64-linux"
"aarch64-linux"
"x86_64-darwin"
"aarch64-darwin"
homepage = "https://lidarr.audio";
changelog = "https://github.com/Lidarr/Lidarr/releases/tag/v${version}";
license = lib.licenses.gpl3Only;
maintainers = with lib.maintainers; [
ramonacat
karaolidis
];
mainProgram = "Lidarr";
# platforms inherited from dotnet-sdk.
};
})
}
+181
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", "lidarr")
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 Lidarr API instead of GitHub to fetch latest stable release.
# This corresponds to the Updates tab in the web UI. See also
# https://github.com/Lidarr/Lidarr/blob/350860e524029b7fb4165ed14fbcabb11217ada2/src/NzbDrone.Core/Update/UpdatePackageProvider.cs
version_update = requests.get(
f"https://lidarr.servarr.com/v1/update/master?version={old_version}&includeMajorVersion=true",
).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/Lidarr/Lidarr/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))
-35
View File
@@ -1,35 +0,0 @@
#!/usr/bin/env nix-shell
#!nix-shell -i bash -p curl gnused nix-prefetch jq
set -euo pipefail
dirname="$(dirname "$(readlink -f "$0")")"
updateHash() {
local version arch os
version="$1"
arch="$2"
os="$3"
local url hash sriHash
url="https://github.com/Lidarr/Lidarr/releases/download/v$version/Lidarr.master.$version.$os-core-$arch.tar.gz"
hash="$(nix-prefetch-url --type sha256 "$url")"
sriHash="$(nix --extra-experimental-features nix-command hash convert --to sri --hash-algo sha256 "$hash")"
local hashKey="${arch}-${os}_hash"
sed -i "s|$hashKey = \"[a-zA-Z0-9\/+-=]*\";|$hashKey = \"$sriHash\";|g" "$dirname/package.nix"
}
updateVersion() {
sed -i "s/version = \"[0-9.]*\";/version = \"$1\";/g" "$dirname/package.nix"
}
latestTag=$(curl https://api.github.com/repos/Lidarr/Lidarr/releases/latest | jq -r ".tag_name")
latestVersion="$(expr "$latestTag" : 'v\(.*\)')"
updateVersion "$latestVersion"
updateHash "$latestVersion" x64 linux
updateHash "$latestVersion" arm64 linux
updateHash "$latestVersion" x64 osx
updateHash "$latestVersion" arm64 osx
+1
View File
@@ -196,6 +196,7 @@ buildDotnetModule {
maintainers = with lib.maintainers; [
purcell
nyanloutre
karaolidis
];
mainProgram = "Radarr";
# platforms inherited from dotnet-sdk.
+25 -28
View File
@@ -141,39 +141,35 @@ buildDotnetModule {
];
# Skip manual, integration, automation and platform-dependent tests.
dotnetTestFlags = [
"--filter:${
lib.concatStringsSep "&" (
[
"TestCategory!=ManualTest"
"TestCategory!=IntegrationTest"
"TestCategory!=AutomationTest"
testFilters = [
"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"
# makes real HTTP requests
"FullyQualifiedName!~NzbDrone.Core.Test.UpdateTests.UpdatePackageProviderFixture"
"FullyQualifiedName!~NzbDrone.Core.Test.TvTests.RefreshEpisodeServiceFixture"
]
++ lib.optionals stdenvNoCC.buildPlatform.isDarwin [
# fails on macOS
"FullyQualifiedName!~NzbDrone.Core.Test.Http.HttpProxySettingsProviderFixture"
];
# 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"
disabledTests = [
# setgid tests
"NzbDrone.Mono.Test.DiskProviderTests.DiskProviderFixture.should_preserve_setgid_on_set_folder_permissions"
"NzbDrone.Mono.Test.DiskProviderTests.DiskProviderFixture.should_clear_setgid_on_set_folder_permissions"
# attempts to read /etc/*release and fails since it does not exist
"FullyQualifiedName!=NzbDrone.Mono.Test.EnvironmentInfo.ReleaseFileVersionAdapterFixture.should_get_version_info"
# we do not set application data directory during tests (i.e. XDG data directory)
"NzbDrone.Mono.Test.DiskProviderTests.FreeSpaceFixture.should_return_free_disk_space"
"NzbDrone.Common.Test.ServiceFactoryFixture.event_handlers_should_be_unique"
# 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"
# attempts to read /etc/*release and fails since it does not exist
"NzbDrone.Mono.Test.EnvironmentInfo.ReleaseFileVersionAdapterFixture.should_get_version_info"
# 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"
]
)
}"
# fails to start test dummy because it cannot locate .NET runtime for some reason
"NzbDrone.Common.Test.ProcessProviderFixture.Should_be_able_to_start_process"
"NzbDrone.Common.Test.ProcessProviderFixture.kill_all_should_kill_all_process_with_name"
];
passthru = {
@@ -203,6 +199,7 @@ buildDotnetModule {
purcell
tie
niklaskorz
karaolidis
];
mainProgram = "Sonarr";
# platforms inherited from dotnet-sdk.