Unverified Commit 06f9bc9a authored by Kevin Cox's avatar Kevin Cox Committed by GitHub
Browse files

sonarr: upgrade to dotnet 8 and 4.0.11.2680 -> 4.0.12.2823 (#380045)

parents f25f31e3 e16a609f
Loading
Loading
Loading
Loading
+176 −251

File changed.

Preview size limit exceeded, changes collapsed.

+120 −77
Original line number Diff line number Diff line
{ lib
, stdenvNoCC
, fetchFromGitHub
, buildDotnetModule
, dotnetCorePackages
, sqlite
, withFFmpeg ? true # replace bundled ffprobe binary with symlink to ffmpeg package.
, ffmpeg
, fetchYarnDeps
, yarn
, fixup-yarn-lock
, nodejs
, nixosTests
{
  lib,
  stdenvNoCC,
  fetchFromGitHub,
  buildDotnetModule,
  dotnetCorePackages,
  sqlite,
  withFFmpeg ? true, # replace bundled ffprobe binary with symlink to ffmpeg package.
  ffmpeg,
  fetchYarnDeps,
  yarn,
  fixup-yarn-lock,
  nodejs,
  nixosTests,
  # update script
, writers
, python3Packages
, nix
, prefetch-yarn-deps
  writers,
  python3Packages,
  nix,
  prefetch-yarn-deps,
  fetchpatch,
  applyPatches,
}:
let
  version = "4.0.11.2680";
  version = "4.0.12.2823";
  # 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-+Ezr+O5BeOAf21l1TjHSQ7OoHPuQ9HXVvmuQvo8V9ss=";
      hash = "sha256-gAvbA3Idx73QEDthLwrM8Jbt6YhXxK8LzEJI6eF2k20=";
    };
    patches =
      [
        ./nuget-config.patch
      ]
      ++ 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
@@ -31,16 +59,17 @@ buildDotnetModule {
  pname = "sonarr";
  inherit version src;

  patches = [
    ./nuget-config.patch
  ];

  strictDeps = true;
  nativeBuildInputs = [ nodejs yarn prefetch-yarn-deps fixup-yarn-lock ];
  nativeBuildInputs = [
    nodejs
    yarn
    prefetch-yarn-deps
    fixup-yarn-lock
  ];

  yarnOfflineCache = fetchYarnDeps {
    yarnLock = "${src}/yarn.lock";
    hash = "sha256-S1USzvQ/BcIr+od+gQd+uWxaEz5/qtyOkuIIVK5b7lg=";
    hash = "sha256-YkBFvv+g4p22HdM/GQAHVGGW1yLYGWpNtRq7+QJiLIw=";
  };

  ffprobe = lib.optionalDrvAttr withFFmpeg (lib.getExe' ffmpeg "ffprobe");
@@ -54,10 +83,12 @@ buildDotnetModule {
  postBuild = ''
    yarn --offline run build --env production
  '';
  postInstall = lib.optionalString withFFmpeg ''
  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.
@@ -69,8 +100,8 @@ buildDotnetModule {

  runtimeDeps = [ sqlite ];

  dotnet-sdk = dotnetCorePackages.sdk_6_0-bin;
  dotnet-runtime = dotnetCorePackages.aspnetcore_6_0-bin;
  dotnet-sdk = dotnetCorePackages.sdk_8_0;
  dotnet-runtime = dotnetCorePackages.aspnetcore_8_0;

  doCheck = true;

@@ -96,10 +127,10 @@ buildDotnetModule {
  ];

  dotnetFlags = [
    "--property:TargetFramework=net6.0"
    "--property:TargetFramework=net8.0"
    "--property:EnableAnalyzers=false"
    # Override defaults in src/Directory.Build.props that use current time.
    "--property:Copyright=Copyright 2014-2024 sonarr.tv (GNU General Public v3)"
    "--property:Copyright=Copyright 2014-2025 sonarr.tv (GNU General Public v3)"
    "--property:AssemblyVersion=${version}"
    "--property:AssemblyConfiguration=main"
    "--property:RuntimeIdentifier=${rid}"
@@ -107,7 +138,9 @@ buildDotnetModule {

  # Skip manual, integration, automation and platform-dependent tests.
  dotnetTestFlags = [
    "--filter:${lib.concatStringsSep "&" [
    "--filter:${
      lib.concatStringsSep "&" (
        [
          "TestCategory!=ManualTest"
          "TestCategory!=IntegrationTest"
          "TestCategory!=AutomationTest"
@@ -129,10 +162,14 @@ buildDotnetModule {
          # 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 = {
@@ -140,24 +177,30 @@ buildDotnetModule {
      inherit (nixosTests) sonarr;
    };

    updateScript = writers.writePython3 "sonarr-updater"
      {
    updateScript = writers.writePython3 "sonarr-updater" {
      libraries = with python3Packages; [ requests ];
      makeWrapperArgs = [
        "--prefix"
        "PATH"
        ":"
          (lib.makeBinPath [ nix prefetch-yarn-deps ])
        (lib.makeBinPath [
          nix
          prefetch-yarn-deps
        ])
      ];
      }
      ./update.py;
    } ./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 ];
    maintainers = with lib.maintainers; [
      fadenb
      purcell
      tie
      niklaskorz
    ];
    mainProgram = "Sonarr";
    # platforms inherited from dotnet-sdk.
  };
+35 −15
Original line number Diff line number Diff line
@@ -55,7 +55,7 @@ package_attrs = json.loads(subprocess.run(
        "--apply", """p: {
          dir = builtins.dirOf p.meta.position;
          version = p.version;
          sourceHash = p.src.outputHash;
          sourceHash = p.src.src.outputHash;
          yarnHash = p.yarnOfflineCache.outputHash;
        }""",
        "--",
@@ -97,22 +97,9 @@ source_nix_hash, source_store_path = subprocess.run(
old_source_hash = package_attrs["sourceHash"]
new_source_hash = nix_hash_to_sri(source_nix_hash)

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(source_store_path, "yarn.lock"),
    ],
    stdout=subprocess.PIPE,
    text=True,
    check=True,
).stdout.rstrip())

package_dir = package_attrs["dir"]
package_file_name = "package.nix"
deps_file_name = "deps.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.
@@ -127,6 +114,39 @@ with tempfile.TemporaryDirectory() as work_dir:
        # 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,
    })