{ lib, scrubDerivation }:

let
  # List of packages that need to be scrubbed on Darwin
  # Packages are scrubbed on Linux and expected in test output
  packagesToScrub = [
    # keep-sorted start case=no numeric=yes
    "abook"
    "aerc"
    "aerospace"
    "aichat"
    "aider-chat"
    "alacritty"
    "alot"
    "antidote"
    "anvil-editor"
    "aria2"
    "atuin"
    "autojump"
    "autorandr"
    "awscli2"
    "bacon"
    "bash"
    "bash-completion"
    "bash-preexec"
    "bashInteractive"
    "bat"
    "beets"
    "borgmatic"
    "bottom"
    "broot"
    "browserpass"
    "btop"
    "calibre"
    "carapace"
    "cava"
    "chromium"
    "claude-code"
    "clock-rs"
    "cmus"
    "codex"
    "comodoro"
    "cudatext"
    "darcs"
    "delta"
    "devenv"
    "difftastic"
    "dircolors"
    "direnv"
    "discord"
    "discoss"
    "earthly"
    "ec"
    "element-desktop"
    "emacs"
    "espanso"
    "eza"
    "fastfetch"
    "feh"
    "flameshot"
    "freetube"
    "fzf"
    "gallery-dl"
    "getconf"
    "gh"
    "gh-dash"
    "ghostty"
    "git"
    "git-cliff"
    "git-credential-oauth"
    "git-lfs"
    "git-worktree-switcher"
    "github-copilot-cli"
    "gitMinimal"
    "gnupg"
    "go"
    "google-chrome"
    "google-chrome-beta"
    "google-chrome-dev"
    "gradle"
    "granted"
    "halloy"
    "helix"
    "hello"
    "himalaya"
    "hjson-go"
    "htop"
    "hyfetch"
    "i3status"
    "inori"
    "intelli-shell"
    "irssi"
    "isync"
    "jankyborders"
    "joplin-desktop"
    "jqp"
    "jujutsu"
    "k9s"
    "kakoune"
    "keepassxc"
    "khal"
    "khard"
    "kitty"
    "kubecolor"
    "kubeswitch"
    "lapce"
    "lazydocker"
    "lazygit"
    "lazysql"
    "ledger"
    "less"
    "lesspipe"
    "lf"
    "librewolf"
    "librewolf-unwrapped"
    "lieer"
    "lsd"
    "ludusavi"
    "mbsync"
    "meli"
    "mergiraf"
    "micro"
    "mise"
    "mistral-vibe"
    "mpv"
    "msmtp"
    "mu"
    "mujmap"
    "mullvad-vpn"
    "ncmpcpp"
    "ne"
    "neomutt"
    "neovide"
    "neovim"
    "newsboat"
    "nh"
    "nheko"
    "nix"
    "nix-direnv"
    "nix-index"
    "nix-init"
    "nix-your-shell"
    "notmuch"
    "npth"
    "nushell"
    "nyxt"
    "oh-my-posh"
    "ollama"
    "onlyoffice-desktopeditors"
    "opencode"
    "openssh"
    "openstackclient"
    "papis"
    "parallel-full"
    "patdiff"
    "pay-respects"
    "pet"
    "pgcli"
    "pi-coding-agent"
    "pimsync"
    "pistol"
    "pls"
    "poetry"
    "powerline-go"
    "proton-pass-cli"
    "pubs"
    "pyenv"
    "qcal"
    "qutebrowser"
    "radio-cli"
    "ranger"
    "retext"
    "retroarch-bare"
    "rio"
    "ripgrep"
    "ruff"
    "sage"
    "sapling"
    "sbt"
    "scmpuff"
    "senpai"
    "sftpman"
    "sioyek"
    "skhd"
    "sm64ex"
    "smug"
    "spotify-player"
    "starship"
    "superfile"
    "sway-easyfocus"
    "taskwarrior2"
    "tealdeer"
    "texlive"
    "thefuck"
    "thunderbird"
    "tmate"
    "tmux"
    "topgrade"
    "translate-shell"
    "tray-tui"
    "usage"
    "vesktop"
    "vifm"
    "vim-vint"
    "vimPlugins"
    "visidata"
    "vscode"
    "wallust"
    "watson"
    "wezterm"
    "yazi"
    "yq-go"
    "yt-dlp"
    "yubikey-agent"
    "zed-editor"
    "zellij"
    "zk"
    "zoxide"
    "zplug"
    "zsh"
    "zsh-fast-syntax-highlighting"
    "zsh-history-substring-search"
    # keep-sorted end
  ];

  # Create an overlay that scrubs packages in the scrublist
  packageScrubOverlay =
    _self: super:
    lib.mapAttrs (
      name: value:
      if lib.elem name packagesToScrub then
        # Apply scrubbing to this specific package
        scrubDerivation name value
      else
        value
    ) super;

in
self: super:
packageScrubOverlay self super
// {
  buildPackages = super.buildPackages.extend packageScrubOverlay;
}
