Skip to content

discord: add Krisp patcher#506089

Open
FlameFlag wants to merge 1 commit intoNixOS:masterfrom
FlameFlag:flameflag/push-vmswpuqmvzpt
Open

discord: add Krisp patcher#506089
FlameFlag wants to merge 1 commit intoNixOS:masterfrom
FlameFlag:flameflag/push-vmswpuqmvzpt

Conversation

@FlameFlag
Copy link
Copy Markdown
Member

Krisp is Discord's proprietary noise cancellation feature. On nixpkgs it fails to load because patchelf/code signing changes cause the module's built-in signature verification to fail (see #195512)

This PR binary-patches discord_krisp.node to bypass the signature check, deploys the patched module to the user's Discord config dir at runtime, and handles macOS ad-hoc re-signing

There was a prior attempt (and this was inspired by it):

  • discord: fix krisp module #290077 Binary-patched Krisp using hardcoded mangled C++ symbol names looked up via objdump. This approach technically works. Locating IsSignedByDiscord by its mangled symbol and patching it is functionally equivalent to what we do here.

The problem is maintenance: If the symbol gets stripped/renamed entirely (which Discord could do at any time), the approach breaks with no fallback. Also see #290077 (review)

Here is how my patch works (conceptually):

On ELF, the patcher finds a unique byte pattern in .text that corresponds to the MD5 comparison in the signature check (pmovmskb + cmp $0xffff), walks back to the function start, and overwrites it with mov eax, 1; ret

On Mach-O (macOS), it starts from the _SecStaticCodeCreateWithPath import stub and walks callers upward, each hop is the single unique caller of the previous target. When the chain fans out (multiple callers), we've found IsSignedByDiscord() and patch it to return true. Then re-sign with darwin.signingUtils

At runtime, deploy-krisp.py copies the patched module into the user's config dir before Discord starts. It uses a SHA-256 marker to skip redeployment on subsequent launches and to catch cases where vanilla Discord overwrites our files (macOS APFS case-insensitivity). On fresh installs it waits for Discord to bootstrap its core modules before writing to installed.json

I'm keeping it off by default tho, using Krisp with a modified Discord client probably violates Discord's ToS. But, using Vencord/Equicord/Moonlight already violates those same terms, so enabling Krisp alongside them doesn't introduce any new ToS risk

Closes #195512

Tested on NixOS and Nix-Darwin

Things done

  • Built on platform:
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • Tested, as applicable:
  • Ran nixpkgs-review on this PR. See nixpkgs-review usage.
  • Tested basic functionality of all binary files, usually in ./result/bin/.
  • Nixpkgs Release Notes
    • Package update: when the change is major or breaking.
  • NixOS Release Notes
    • Module addition: when adding a new NixOS module.
    • Module update: when the change is significant.
  • Fits CONTRIBUTING.md, pkgs/README.md, maintainers/README.md and other READMEs.

@nixpkgs-ci nixpkgs-ci Bot added 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 11.by: package-maintainer This PR was created by a maintainer of all the package it changes. labels Apr 2, 2026
@FlameFlag

This comment has been minimized.

@DaniHRE

This comment has been minimized.

@DaniHRE

This comment has been minimized.

@FlameFlag FlameFlag force-pushed the flameflag/push-vmswpuqmvzpt branch from 34cbd38 to 53d44f0 Compare April 5, 2026 06:38
@FlameFlag

This comment has been minimized.

@vladdeSV
Copy link
Copy Markdown

vladdeSV commented Apr 5, 2026

does this go against Discord's TOS?

from the wiki regarding patching the binary:

Warning: The usage of such modifications goes against Discord's Terms of Service and Krisp's Terms of Use and can result in your Discord account being terminated and/or being banned from using Krisp's services!

if so, should this be in the official NixOS packages?

EDIT: totally missed it's off by default, my bad

@FlameFlag
Copy link
Copy Markdown
Member Author

FlameFlag commented Apr 5, 2026

does this go against Discord's TOS?

if so, should this be in the official NixOS packages?

By this logic that would mean we would have to drop Vencord and Equicord and all other 3rd party Discord clients, as Discord doesn't allow any 3rd party clients or modifications

Practically nobody has ever been banned for using 3rd party clients or modifications (when used in "good faith"), Discord seemingly only cares that you don't hammer their API (which obv none of these stuff do)

EDIT: I re-read it again and as well I saw your edit, seems like we misunderstood each other, to clarify it's disabled by default ofc, and I said in PR itself, it's enabled implicitly by using 3rd party modification like Vencord or Equicord as you're knowingly breaking ToS anyways

@FlameFlag

This comment has been minimized.

@FlameFlag FlameFlag requested a review from ashuramaruzxc April 11, 2026 09:30
Comment thread pkgs/applications/networking/instant-messengers/discord/deploy-krisp.py Outdated
Comment thread pkgs/applications/networking/instant-messengers/discord/deploy-krisp.py Outdated
Comment thread pkgs/applications/networking/instant-messengers/discord/patch-krisp.py Outdated
Comment thread pkgs/applications/networking/instant-messengers/discord/patch-krisp.py Outdated
Comment thread pkgs/applications/networking/instant-messengers/discord/patch-krisp.py Outdated
Comment thread pkgs/applications/networking/instant-messengers/discord/patch-krisp.py Outdated
@FlameFlag FlameFlag force-pushed the flameflag/push-vmswpuqmvzpt branch from 53d44f0 to d87fa33 Compare April 11, 2026 15:35
@FlameFlag
Copy link
Copy Markdown
Member Author

@ashuramaruzxc Thanks a lot for the review!

Copy link
Copy Markdown
Member

@ashuramaruzxc ashuramaruzxc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some parts of the code regarding reading files and bytes could be improved but overall lgtm

@nixpkgs-ci nixpkgs-ci Bot added the 12.approvals: 1 This PR was reviewed and approved by one person. label Apr 11, 2026
@FlameFlag

This comment has been minimized.

@nixpkgs-ci nixpkgs-ci Bot added 12.approvals: 2 This PR was reviewed and approved by two persons. and removed 12.approvals: 1 This PR was reviewed and approved by one person. labels Apr 12, 2026
@FlameFlag FlameFlag force-pushed the flameflag/push-vmswpuqmvzpt branch 2 times, most recently from 1c52ef9 to 661d16d Compare April 24, 2026 17:41
@FlameFlag
Copy link
Copy Markdown
Member Author

FlameFlag commented Apr 24, 2026

Now that #507728 is merged, this PR needed more than just conflict resolution

That PR changed how the non-stable Linux Discord packages are fetched/staged: PTB/Canary/Development now use Discord's distro/module packaging, and discord_krisp may come from source.modules.discord_krisp instead of a separate *-krisp entry in sources.json.

I updated this PR to support both worlds: legacy Krisp zips and distro module Krisp sources. For distro modules, Krisp can be a brotli-compressed tar module, so the patching path handles that too. When withKrisp is enabled we stage the other distro modules normally, but leave discord_krisp to the runtime deploy helper so the patched module is the one Discord sees

For the relevant changes please look at: 1c52ef9 (I squashed it out because I wanted it to purely serves as a clean diff)

@FlameFlag FlameFlag force-pushed the flameflag/push-vmswpuqmvzpt branch from 661d16d to 3fd9c5c Compare April 24, 2026 17:52
@FlameFlag

This comment has been minimized.

@typedrat
Copy link
Copy Markdown
Contributor

typedrat commented May 6, 2026

This heavily leaks memory on my system. Just leaving Discord open for a couple of hours with this enabled, the Python script ends up consuming around ~40 GB of RAM.

@alper-han
Copy link
Copy Markdown
Contributor

This heavily leaks memory on my system. Just leaving Discord open for a couple of hours with this enabled, the Python script ends up consuming around ~40 GB of RAM.

This might not be related to this.

I’m experiencing a similar issue when screen sharing is active while using Vesktop. I don’t think this is related to this PR.

@typedrat
Copy link
Copy Markdown
Contributor

typedrat commented May 7, 2026

This heavily leaks memory on my system. Just leaving Discord open for a couple of hours with this enabled, the Python script ends up consuming around ~40 GB of RAM.

This might not be related to this.

I’m experiencing a similar issue when screen sharing is active while using Vesktop. I don’t think this is related to this PR.

No, it's specifically the Python script added in this PR, which I've pulled in as a patch against my nixpkgs.

@ashuramaruzxc
Copy link
Copy Markdown
Member

ashuramaruzxc commented May 7, 2026

No, it's specifically the Python script added in this PR, which I've pulled in as a patch against my nixpkgs.

Please provide your system information,
kernel version,
discord version, etc
and steps to reproduce

I've tried keeping discord open with this patch already over 30 hours and it doesn't seem to leak memory with this patch on both x86_64-linux and aarch64-darwin

@FlameFlag FlameFlag force-pushed the flameflag/push-vmswpuqmvzpt branch from 3fd9c5c to 5784401 Compare May 7, 2026 13:22
@FlameFlag
Copy link
Copy Markdown
Member Author

This heavily leaks memory on my system. Just leaving Discord open for a couple of hours with this enabled, the Python script ends up consuming around ~40 GB of RAM.

I couldn't really replicate this on my side, but I added a fix for what looks like the likely cause. Even aside from the memory issue, this should be the more correct watcher behavior

@koffydrop
Copy link
Copy Markdown
Member

It seems to be fixed on my end

Comment thread pkgs/applications/networking/instant-messengers/discord/darwin.nix Outdated
@FlameFlag FlameFlag force-pushed the flameflag/push-vmswpuqmvzpt branch from 5784401 to 3327261 Compare May 9, 2026 01:19
@typedrat
Copy link
Copy Markdown
Contributor

typedrat commented May 9, 2026

Can confirm this fixed my issues.

@koffydrop
Copy link
Copy Markdown
Member

nixpkgs-review result

Generated using nixpkgs-review.

Command: nixpkgs-review pr 506089
Commit: 3327261e53f551e4b4393ef3d6ac660976c19a1d


x86_64-linux

✅ 4 packages built:
  • discord
  • discord-canary
  • discord-development
  • discord-ptb

Copy link
Copy Markdown
Member

@koffydrop koffydrop left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved automatically following the successful run of nixpkgs-review.

@nixpkgs-ci nixpkgs-ci Bot added 12.approvals: 3+ This PR was reviewed and approved by three or more persons. and removed 12.approvals: 2 This PR was reviewed and approved by two persons. labels May 9, 2026
@FlameFlag
Copy link
Copy Markdown
Member Author

nixpkgs-review result

Generated using nixpkgs-review-gha

Command: nixpkgs-review pr 506089
Commit: 3327261e53f551e4b4393ef3d6ac660976c19a1d (subsequent changes)
Merge: 8999d9638e92c733682680a177732c5d85c53333

Logs: https://github.com/FlameFlag/nixpkgs-review-gha/actions/runs/25623268452


x86_64-linux

✅ 4 packages built:
  • discord
  • discord-canary
  • discord-development
  • discord-ptb

aarch64-linux

No rebuilds


x86_64-darwin (sandbox = relaxed)

✅ 4 packages built:
  • discord
  • discord-canary
  • discord-development
  • discord-ptb

aarch64-darwin (sandbox = relaxed)

✅ 4 packages built:
  • discord
  • discord-canary
  • discord-development
  • discord-ptb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. 11.by: package-maintainer This PR was created by a maintainer of all the package it changes. 12.approvals: 3+ This PR was reviewed and approved by three or more persons.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

discord: krisp module doesn't load

9 participants