From ccfb602b885b3c752f81338dcabeae0e2eece464 Mon Sep 17 00:00:00 2001 From: Mathtician Date: Thu, 11 Jun 2026 00:30:46 -0500 Subject: [PATCH] discord: recreate module symlinks on every launch As of commit b49b623a ("discord: use distro layout for stable on Linux", PR #515876), Discord's launch script runs a `discord-stage-modules` script defined in `linux.nix`, which creates symlinks from `~/.config/discord//modules/` to the corresponding Nix store paths so Discord can find them. It checks whether this has already been done by looking for `installed.json` in the same dir, which it also creates, and skips link creation if so. However, since the dir is indexed by Discord version number, the links are not refreshed when opening a new build of Discord with the same version number as an older build. If the old build is then GC'd, the links break and Discord fails to start with an error such as `Cannot find module 'discord_desktop_core'`. Deleting the module folder entirely allows for it to be recreated and for Discord to start without issue. This problem and solution are attested on the wiki, albeit with less explanation: https://wiki.nixos.org/wiki/Discord#Crash_on_start-up. The package fix is to delete and recreate the `modules` folder on each launch, as it is small and does not contain any data meant to persist between launches: it has only the module links, `installed.json`, and a `pending/` download directory recreated by Discord's updater on startup. The fix ensures that the links always point to the Nix store of the build of Discord being run, so they will not be broken by GC. Assisted-by: Claude Fable 5 in Claude Code (cherry picked from commit 8f5437cf20d11ed4da6d78e140c4ef303eadcc7e) --- .../instant-messengers/discord/linux.nix | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/pkgs/applications/networking/instant-messengers/discord/linux.nix b/pkgs/applications/networking/instant-messengers/discord/linux.nix index 51bdeadd412e..e6f62c4c729f 100644 --- a/pkgs/applications/networking/instant-messengers/discord/linux.nix +++ b/pkgs/applications/networking/instant-messengers/discord/linux.nix @@ -152,14 +152,13 @@ let stageModules = writeShellScript "discord-stage-modules" '' store_modules="$1" modules_dir="''${XDG_CONFIG_HOME:-$HOME/.config}/${lib.toLower binaryName}/${version}/modules" - if [ ! -f "$modules_dir/installed.json" ]; then - mkdir -p "$modules_dir" - for m in ${lib.concatStringsSep " " (lib.attrNames moduleSrcs)}; do - ln -sfn "$store_modules/$m" "$modules_dir/$m" - done - echo '${builtins.toJSON (lib.mapAttrs (_: mod: { installedVersion = mod; }) moduleVersions)}' \ - > "$modules_dir/installed.json" - fi + rm -rf "$modules_dir" + mkdir -p "$modules_dir" + for m in ${lib.concatStringsSep " " (lib.attrNames moduleSrcs)}; do + ln -sn "$store_modules/$m" "$modules_dir/$m" + done + echo '${builtins.toJSON (lib.mapAttrs (_: mod: { installedVersion = mod; }) moduleVersions)}' \ + > "$modules_dir/installed.json" ''; disableBreakingUpdates =