Repository navigation
discord: use distro layout for stable and Darwin - #515876
Conversation
This comment has been minimized.
This comment has been minimized.
dbfa93c to
50e92b6
Compare
This comment has been minimized.
This comment has been minimized.
50e92b6 to
b49b623
Compare
|
Repurposing this PR a bit: while working through the macOS distro layout change, I found that Linux stable finally got the distro layout too, so let's deal with that while we're here |
| fixDistroSymlinks = writeScript "discord-fix-distro-symlinks.py" '' | ||
| #!${python3.interpreter} | ||
| import pathlib | ||
| import sys | ||
| import tarfile | ||
|
|
||
| with tarfile.open(sys.argv[1]) as tar: | ||
| for member in tar: | ||
| if not member.issym(): | ||
| continue | ||
| parts = pathlib.PurePosixPath(member.name).parts[1:] | ||
| if not parts: | ||
| continue | ||
| path = pathlib.Path(sys.argv[2], *parts) | ||
| path.unlink(missing_ok=True) | ||
| path.symlink_to(member.linkname) | ||
| ''; |
There was a problem hiding this comment.
Discord's macOS distro tarballs store framework symlinks with mode 000, recreate them so the app bundle has readable symlinks
| stageModules = writeShellScript "discord-stage-modules" '' | ||
| store_modules="$1" | ||
| modules_dir="$HOME/Library/Application Support/${configDirName}/${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 | ||
| ''; |
There was a problem hiding this comment.
Darwin still defaults to the legacy module updater path, which only adds the per-user <version>/modules directory to Node's module search path
The distro modules are stored in the Nix store, so this stages symlinks plus installed.json there to make Discord load the pinned modules instead of bootstrapping them at runtime
|
|
Thanks for putting all this research into how the new discord update process work ^^ |
|
Backport failed for Please cherry-pick the changes locally and resolve any conflicts. git fetch origin release-25.11
git worktree add -d .worktree/backport-515876-to-release-25.11 origin/release-25.11
cd .worktree/backport-515876-to-release-25.11
git switch --create backport-515876-to-release-25.11
git cherry-pick -x f069e07d2bff540335b01f31920c54c6877f5e97 b45dc30858ce125bb5ba6d117a2072df10783909 a7c378c095f4f13bd1be524c4f668dd95e60259b 48dd7b3c34fff167391ced88bc97a1b66e7cd353 0f6c97b536c10d40518fb2dbc28e5b747f137374 fda82730c08c4dc68f53917f8530a635aae60279 19aa7391cae79ed6b97917f5f331ddee0fc476cb b851333c77487f0e6a680bc0305d4b321b4ca0df b7c15d7f2e30e0db5549f1deb97eb2519fde1233 2a82a95464b9aae569a39e9018cf12e25b3d9fc3 b49b623ae22c544c250e891d3fdbec82ed5f3393 |
As of commit b49b623 ("discord: use distro layout for stable on Linux", PR NixOS#515876), Discord's launch script runs a `discord-stage-modules` script defined in `linux.nix`, which creates symlinks from `~/.config/discord/<version>/modules/<module_name>` 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
As of commit b49b623 ("discord: use distro layout for stable on Linux", PR NixOS#515876), Discord's launch script runs a `discord-stage-modules` script defined in `linux.nix`, which creates symlinks from `~/.config/discord/<version>/modules/<module_name>` 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 8f5437c)
Things done
passthru.tests.nixpkgs-reviewon this PR. See nixpkgs-review usage../result/bin/.