Isn't this a nix antipattern?

We have a simple package for intercepting proxy Caido:

All it does is just grabs a binary release and repackage it. But the way everything is defined inside let (...) in prohibits from using overrideAttrs to manually bump the version ourselves:

{ pkgs, ... }:
{
  environment.systemPackages = with pkgs; [
    (caido.overrideAttrs {
      version = "0.55.3";
    })
  ];
}

Is there a clean way to override just this version attribute without full package redefinition via overlay? Shouldn’t the maintainer put version inside inputs to make this easier? There are dozens of packages like this, that are bumped every now and then, but never when one need the latest version :stuck_out_tongue:

Yes. I consider this an antipattern, at least. IMO this kind of construct should be made via the mkDerivation fixed-point, or handled with some passthru shenanigans, precisely for this reason (though in either case you’d have to override the src as well).

There’s no good way besides overriding the attributes you have access to. That said, the good news is that you can submit a PR to improve things.

4 Likes

You are correct that this prevents overrideAttrs from working correctly. Unfortunately it seems like that derivation is written in a rather complex way, and refactoring it to avoid the usage of let … in would be really difficult. It’s probably doable but you’d have to raise that issue directly on GitHub and ping the maintainer.

1 Like

Thanks, I’ll try to fix it then :slight_smile:

2 Likes

So I’m just toying with ideas now. Would moving this into inputs be considered a better practice? Like this:

{
  lib,
  stdenv,
  fetchurl,
  appimageTools,
  makeWrapper,
  autoPatchelfHook,
  _7zz,
  unzip,
  libgcc,
  appVariants ? [ ],
  version ? "0.55.1",
  cliSources ? {
    x86_64-linux = {
      url = "https://caido.download/releases/v${version}/caido-cli-v${version}-linux-x86_64.tar.gz";
      hash = "sha256-4xRkEN/ZA+JUFMB2qoEZT0Bzv2Qc7Y9kcj251MCAhKE=";
    };
    aarch64-linux = {
      url = "https://caido.download/releases/v${version}/caido-cli-v${version}-linux-aarch64.tar.gz";
      hash = "sha256-gMQkF0+mq2nRBy0oBenFvp69byWCkqmt8E4ZpKuNxKw=";
    };
    x86_64-darwin = {
      url = "https://caido.download/releases/v${version}/caido-cli-v${version}-mac-x86_64.zip";
      hash = "sha256-C+EfmSBJMyxYXLfzxCrY7ZVtg8nwtie8w0Lj1Dy7o/k=";
    };
    aarch64-darwin = {
      url = "https://caido.download/releases/v${version}/caido-cli-v${version}-mac-aarch64.zip";
      hash = "sha256-b0cBS3RwsiLgJNqHWxi672MVZNfTYNOEJ2k0h2qNnP0=";
    };
  },
  desktopSources ? {
    x86_64-linux = {
      url = "https://caido.download/releases/v${version}/caido-desktop-v${version}-linux-x86_64.AppImage";
      hash = "sha256-zfts2h8QWTxe/dISwgKRQiSx2nD6vtE1atPfREyGX/U=";
    };
    aarch64-linux = {
      url = "https://caido.download/releases/v${version}/caido-desktop-v${version}-linux-aarch64.AppImage";
      hash = "sha256-fYqzukRptCB466LIPbVre2EwBFt4Bsq9amQ4kjQuV2Q=";
    };
    x86_64-darwin = {
      url = "https://caido.download/releases/v${version}/caido-desktop-v${version}-mac-x86_64.dmg";
      hash = "sha256-UsGT5n0MGVwWCXACo74Harb4J/qt/3TyD0+EFYNmPxw=";
    };
    aarch64-darwin = {
      url = "https://caido.download/releases/v${version}/caido-desktop-v${version}-mac-aarch64.dmg";
      hash = "sha256-iZHZayj2VYjMY9+p+xrlX+vP/DcbCRPQizQEqtF39EU=";
    };
  },
  meta ? {
    description = "Lightweight web security auditing toolkit";
    homepage = "https://caido.io/";
    changelog = "https://github.com/caido/caido/releases/tag/v${version}";
    license = lib.licenses.unfree;
    maintainers = with lib.maintainers; [
      octodi
      blackzeshi
    ];
    platforms = [
      "x86_64-linux"
      "aarch64-linux"
      "x86_64-darwin"
      "aarch64-darwin"
    ];
  },
}:
let
(....)