Commit 084df7a4 authored by Ross Smyth's avatar Ross Smyth
Browse files

television: Refactor, add wrapper helper

parent 3d356d30
Loading
Loading
Loading
Loading
+91 −52
Original line number Diff line number Diff line
{
  lib,
  stdenv,
  rustPlatform,
  fetchFromGitHub,
  makeWrapper,
  testers,
  television,
  callPackage,
  installShellFiles,
  nix-update-script,
  extraPackages ? [ ],
  testers,
  targetPackages,
  extraPackages ? null,
}:
rustPlatform.buildRustPackage (finalAttrs: {

assert
  (extraPackages == null)
  || lib.warn "Overriding television with the 'extraPackages' attribute is deprecated. Please use `television.withPackages (p: [ p.fd ...])` instead.";

let
  television = rustPlatform.buildRustPackage (finalAttrs: {
    pname = "television";

    version = "0.13.5";

    src = fetchFromGitHub {
@@ -21,23 +30,49 @@ rustPlatform.buildRustPackage (finalAttrs: {

    cargoHash = "sha256-QKUspbC1bmSeZP0n/O5roEqQkrja+fVKLhAvgzqNS9E=";

  nativeBuildInputs = [ makeWrapper ];

  postInstall = lib.optionalString (extraPackages != [ ]) ''
    wrapProgram $out/bin/tv \
      --prefix PATH : ${lib.makeBinPath extraPackages}
  '';
    strictDeps = true;
    nativeBuildInputs = [
      installShellFiles
    ];

    # TODO(@getchoo): Investigate selectively disabling some tests, or fixing them
    # https://github.com/NixOS/nixpkgs/pull/423662#issuecomment-3156362941
    doCheck = false;

    postInstall = ''
      installManPage target/${stdenv.hostPlatform.rust.cargoShortTarget}/assets/tv.1

      installShellCompletion --cmd tv \
        television/utils/shell/completion.bash \
        television/utils/shell/completion.fish \
        television/utils/shell/completion.nu \
        television/utils/shell/completion.zsh
    '';

    passthru = {
    tests.version = testers.testVersion {
      package = television;
      updateScript = nix-update-script { };

      withPackages =
        f:
        callPackage ./wrapper.nix {
          television = finalAttrs.finalPackage;
          extraPackages = f targetPackages;
        };

      tests = {
        version = testers.testVersion {
          package = finalAttrs.finalPackage;
          command = "XDG_DATA_HOME=$TMPDIR tv --version";
        };
        wrapper = testers.testVersion {
          package = finalAttrs.finalPackage.withPackages (pkgs: [
            pkgs.fd
            pkgs.git
          ]);

          command = "XDG_DATA_HOME=$TMPDIR tv --version";
        };
    updateScript = nix-update-script { };
      };
    };

    meta = {
@@ -55,6 +90,10 @@ rustPlatform.buildRustPackage (finalAttrs: {
      maintainers = with lib.maintainers; [
        louis-thevenet
        getchoo
        RossSmyth
      ];
    };
})
  });
in

if extraPackages == null then television else television.withPackages (lib.const extraPackages)
+33 −0
Original line number Diff line number Diff line
{
  lib,
  symlinkJoin,
  television,
  makeBinaryWrapper,
  extraPackages,
}:

symlinkJoin {
  inherit (television) version;
  pname = "${television.pname}-with-pkgs";

  paths = [ television ];

  nativeBuildInputs = [ makeBinaryWrapper ];

  postBuild = ''
    wrapProgram $out/bin/tv \
      --prefix PATH : "${lib.makeBinPath extraPackages}"
  '';

  meta = {
    inherit (television.meta)
      description
      longDescription
      homepage
      changelog
      license
      mainProgram
      maintainers
      ;
  };
}