Skip to content

build: 添加 Nix flake 支持 - #151

Open
SegmentationViolator wants to merge 1 commit into
SPlayer-Dev:devfrom
SegmentationViolator:feat/flake
Open

build: 添加 Nix flake 支持#151
SegmentationViolator wants to merge 1 commit into
SPlayer-Dev:devfrom
SegmentationViolator:feat/flake

Conversation

@SegmentationViolator

@SegmentationViolator SegmentationViolator commented Aug 11, 2026

Copy link
Copy Markdown

改动类型

  • 新功能(feat)
  • 缺陷修复(fix)
  • 重构 / 优化(不改变对外行为)
  • 文档(docs)
  • 其他(请在「改动说明」中注明)

是否包含破坏性变更

  • 是(请在「改动说明」中详细描述)

改动说明

这个 flake 基于 nixpkgs 中现有的 SPlayer 打包方案。

这个 PR 添加了一个用于打包该应用的 Nix flake,使 Nix 用户能够轻松地在自己的 flake 中引用并构建该应用。

此外,这个 PR 还更新了 pnpm-lock.yaml,因为 fetchPnpmDeps 要求使用最新的 lockfile,否则 flake 将无法构建。 这是我的误解,lockfile 已恢复到之前的版本。

fetchPnpmDeps 还要求提供依赖关系图的哈希值,这意味着每当依赖关系图发生变化时,都需要相应更新 flake。因此,我愿意在依赖关系发生变化导致 flake 失效时负责更新它。

测试情况

这个 flake 已在 NixOS 26.11.20260801.148bab9(Zokor)x86-64 Linux 上进行了测试。构建成功生成了应用程序,包括可执行文件、桌面文件、图标以及其他所需资源。生成的可执行文件能够正常启动 SPlayer-Next,在测试期间未遇到任何崩溃。

自查清单

  • 本 PR 只包含一个主要功能 / 修复,没有夹带无关改动
  • 已在本地完整测试通过;AI 生成的代码同样自行测试并审阅过,未做未经验证的提交
  • 已运行 pnpm format,并确认 pnpm typecheckpnpm lint 通过
  • 改动涉及原生模块时已 pnpm build:native 验证;未手写 native/*/index.d.ts
  • 已向 dev 分支提交

免责声明

我不懂中文,因此需要使用 LLM 帮助我翻译 PR 模板。我先用英文回答了模板中的问题,然后使用 LLM 将其翻译成中文。由于我无法核实翻译的准确性,因此我同时附上了英文原文和中文翻译,以便他人可以独立核实我所提供的信息。

Disclaimer

I do not understand Chinese, so I had to use an LLM to translate the PR template. I wrote my responses to the questions in English and then used an LLM to translate them into Chinese. Since I am unable to verify the accuracy of the translation, I am including the English text alongside the Chinese translation so that the information I provided can be independently verified.

Change Type

  • New feature (feat)
  • Bug fix (fix)
  • Refactor / optimization (no externally visible behavior changes)
  • Documentation (docs)
  • Other (please specify in "Description")

Does this include breaking changes?

  • Yes (describe in detail in "Description")
  • No

Description

This flake is based on the existing SPlayer packaging recipe in nixpkgs.

This PR adds a Nix flake that packages the application, allowing Nix users to easily include and build it in their own flakes.

This PR also updates pnpm-lock.yaml, as fetchPnpmDeps requires an up-to-date lockfile and the flake fails to build without it. This was a misconception on my part, lockfile was restored to its previous version.

fetchPnpmDeps also requires a hash of the dependency graph, meaning the flake will need to be updated whenever the dependency graph changes. Therefore, I volunteer to update the flake whenever this happens.

Testing

The flake was tested on NixOS 26.11.20260801.148bab9 (Zokor) on x86-64 Linux. It successfully builds the application, including the executable, desktop entry, icons, and other required resources. The resulting executable launches SPlayer-Next successfully, and I have not encountered any crashes during my testing.

Checklist

  • This PR contains only one main feature / fix and does not include unrelated changes
  • I have fully tested the changes locally; any AI-generated code has also been tested and reviewed by me and no unverified code has been submitted
  • I have run pnpm format and confirmed that pnpm typecheck and pnpm lint pass
  • If the changes involve native modules, I have verified them with pnpm build:native; I have not manually written native/*/index.d.ts
  • I have submitted this PR to the dev branch

Copilot AI balanced review requested due to automatic review settings August 11, 2026 22:51

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@SegmentationViolator
SegmentationViolator marked this pull request as draft August 12, 2026 08:05
@MasterZack69

Copy link
Copy Markdown

Hello i have failed to reproduce this on my system NIxOS 26.05 x86-linux

你好,我无法在我的 NixOS 26.05 x86-linux 系统上复现此构建。

splayer-next
13:28:14.347                 › Unhandled rejection Error: libstdc++.so.6: cannot open shared object file: No such file or directory
    at process.func [as dlopen] (node:electron/js2c/node_init:2:2625)
    at Object.<anonymous> (node:internal/modules/cjs/loader:2039:18)
    at Object.func [as .node] (node:electron/js2c/node_init:2:2852)
    at Module.load (node:internal/modules/cjs/loader:1601:32)
    at node:internal/modules/cjs/loader:1403:12
    at Module._load (node:electron/js2c/node_init:2:18095)
    at wrapModuleLoad (node:internal/modules/cjs/loader:262:19)
    at Module.require (node:internal/modules/cjs/loader:1624:12)
    at require (node:internal/modules/helpers:153:16)
    at getBinding (/nix/store/jiy6im8f3p4j1yrm16qia0a01qskzhrd-splayer-next-1.0.0/share/splayer-next/resources/app.asar/node_modules/better-sqlite3/lib/binding.js:30:26)
[3142:0812/132814.724896:ERROR:ui/ozone/platform/wayland/gpu/wayland_surface_factory.cc:249] '--ozone-platform=wayland' is not compatible with Vulkan. Consider switching to '--ozone-platform=x11' or disabling Vulkan

@ccicnce113424

Copy link
Copy Markdown

NixOS/nixpkgs#551762
供参考

@ccicnce113424

ccicnce113424 commented Aug 12, 2026

Copy link
Copy Markdown

NixOS用户如果想现在用的话可以尝试https://github.com/ccicnce113424/nix-packages ,可以作为flake,也可以从nur里面拉

@SegmentationViolator SegmentationViolator changed the title build: 添加 Nix flake 支持并更新 pnpm-lock.yaml build: 添加 Nix flake 支持 Aug 12, 2026
@kyv001

kyv001 commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

坏了,被抢先了()
我的NUR里也有一个维护包定义来着

@SegmentationViolator
SegmentationViolator force-pushed the feat/flake branch 2 times, most recently from 1aed849 to a11564a Compare August 12, 2026 11:26
@SegmentationViolator

Copy link
Copy Markdown
Author

这个 flake 已根据 @ccicnce113424 的工作进行了调整。即使他们在 nixpkgs 中的 PR 最终被合并,我仍希望保留这个 flake,作为一种为 Nix 打包项目最新 commit 的方式。

@MasterZack69 报告的问题应该也已经解决了,因为之前用于处理 bindgen 的临时 workaround 已经被正确的解决方案所替代。目前正在等待他确认问题是否已经修复。

The flake has been updated to build on the good work by @ccicnce113424. Even if their PR in nixpkgs gets merged, If possible, I’d still like to keep this flake as a way to package the latest commit of the project for Nix.

The issue reported by @MasterZack69 should also be resolved, as the previous hacky workaround for bindgen has been replaced with the proper solution. I’m waiting for him to confirm that the issue is fixed.

@SegmentationViolator
SegmentationViolator marked this pull request as ready for review August 12, 2026 11:34
Copilot AI review requested due to automatic review settings August 12, 2026 11:34

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@ccicnce113424

Copy link
Copy Markdown

除非能够自动从Cargo.lock和pnpm-lock.yaml中自动获得依赖,否则只要发生依赖变动,旧的FOD hash就会失效。如果不能实现这两点,只会增加麻烦。

@MasterZack69

Copy link
Copy Markdown

@MasterZack69 报告的问题应该也已经解决了,因为之前用于处理 bindgen 的临时 workaround 已经被正确的解决方案所替代。目前正在等待他确认问题是否已经修复。

我用新的 flake.nix 编译了,但问题依然存在,还是报一样的错。

Comment thread flake.nix Outdated
@SegmentationViolator
SegmentationViolator marked this pull request as draft August 12, 2026 14:11
Comment thread flake.nix
@SegmentationViolator

Copy link
Copy Markdown
Author

除非能够自动从Cargo.lock和pnpm-lock.yaml中自动获得依赖,否则只要发生依赖变动,旧的FOD hash就会失效。如果不能实现这两点,只会增加麻烦。

Cargo.lock 从来都不是问题,因为这里使用的是 rustPlatform.importCargoLock。至于 pnpm-lock.yaml,如果使用 dream2nix 来避免每次 lockfile 发生变化时都需要更新 FOD hash,这会不会有点过度设计?

@kyv001

kyv001 commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

使用FOD的情况下,如果每次更新依赖都需要更新者自行修改hash,对于本来不使用nix的用户来说是额外劳动;如果不要求更新者自行修改,那么即使有自动化修改,合并自动化产生的PR也是一种负担。

@MasterZack69

Copy link
Copy Markdown

看起来我这边无法正常播放封装在 m4a 容器里的 ALAC 文件(我手头没有原生 alac 容器的文件来测试,而且我也懒得手动去转封装了)。

在正式版本发布之前,我自己从源码编译 splayer-next 时这些文件是可以正常播放的。

我怀疑可能是 Flake 相关的问题,所以发在这里反馈一下(我还没试过官方正式发布的版本)。

english:
apparantly im not getting playback for alac files in m4a containers ( i dont have any alac in alac containers to check, yes im too lazy to change the containers manually)
they used to play fine when i had built splayer-next from source before the official release
i think maybe this is the flake issue that is why im posting it here (i have not checked the official release yet)

15:37:20.406 (player)        › FILE_DECODE_ERROR: Error: [DecodeFailed] decode failed: 打开本地音频失败: /home/zack/Music/SOLO - JENNIE.m4a: FFmpeg error -1128613112: Decoder not found
15:37:22.662 (player)        › FILE_DECODE_ERROR: Error: [DecodeFailed] decode failed: 打开本地音频失败: /home/zack/Music/28 Reasons - SEULGI.m4a: FFmpeg error -1128613112: Decoder not found
15:37:26.656 (player)        › FILE_DECODE_ERROR: Error: [DecodeFailed] decode failed: 打开本地音频失败: /home/zack/Music/BLING BLING - Ikkimel & nocashfromparents.m4a: FFmpeg error -1128613112: Decoder not found
15:37:27.697 (player)        › FILE_DECODE_ERROR: Error: [DecodeFailed] decode failed: 打开本地音频失败: /home/zack/Music/1. spiral.m4a: FFmpeg error -1128613112: Decoder not found
15:37:34.534 (player)        › FILE_DECODE_ERROR: Error: [DecodeFailed] decode failed: 打开本地音频失败: /home/zack/Music/1. spiral.m4a: FFmpeg error -1128613112: Decoder not found
15:37:42.500 (player)        › FILE_DECODE_ERROR: Error: [DecodeFailed] decode failed: 打开本地音频失败: /home/zack/Music/1. spiral.m4a: FFmpeg error -1128613112: Decoder not found
15:37:54.604 (player)        › FILE_DECODE_ERROR: Error: [DecodeFailed] decode failed: 打开本地音频失败: /home/zack/Music/1. spiral.m4a: FFmpeg error -1128613112: Decoder not found
15:37:55.655 (player)        › FILE_DECODE_ERROR: Error: [DecodeFailed] decode failed: 打开本地音频失败: /home/zack/Music/Night Crawling (feat. Billy Idol) - Miley Cyrus.m4a: FFmpeg error -1128613112: Decoder not found

@MasterZack69

Copy link
Copy Markdown

我已在 @ccicnce113424 提供的软件包中复现了相同的问题。

english: i have been able to reproduce the same decoding issue in @ccicnce113424's package

@MasterZack69

Copy link
Copy Markdown

I have tested the x86-64 Appimage from splayer-next's official github release and I can confirm that this issue is not there

我测试了 splayer-next 官方 GitHub Release 的 x86_64 AppImage,可以确认这里面没有这个问题。

@ccicnce113424 @SegmentationViolator

@ccicnce113424

Copy link
Copy Markdown

@MasterZack69 我仍然认为,在nixpkgs中,应该避免使用附带的ffmpeg。至于这个flake,我觉得无所谓。

@MasterZack69

Copy link
Copy Markdown

@MasterZack69 我仍然认为,在nixpkgs中,应该避免使用附带的ffmpeg。至于这个flake,我觉得无所谓。

备选方案则是发布一个损坏的包(package),这样它就无法与我的离线音乐库正常配合使用了。

@kyv001

kyv001 commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

疑似是FFMPEG_MODE=system配置下的ffmpeg给链接到chromium自带的那个版本里去了。我曾经有一个解决方案可能能解决这个问题。具体地说是那一堆LD_PRELOAD

Comment thread flake.nix
--add-flags $out/share/splayer-next/resources/app.asar \
--add-flags "\''${NIXOS_OZONE_WL:+\''${WAYLAND_DISPLAY:+--ozone-platform-hint=auto --enable-features=WaylandWindowDecorations --enable-wayland-ime=true --wayland-text-input-version=3}}" \
--set-default ELECTRON_FORCE_IS_PACKAGED 1 \
--set-default ELECTRON_IS_DEV 0 \

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

经测试,在此处加入

--prefix LD_PRELOAD : "${pkgs.ffmpeg-headless.lib}/lib/libavformat.so" \
--prefix LD_PRELOAD : "${pkgs.ffmpeg-headless.lib}/lib/libavcodec.so" \
--prefix LD_PRELOAD : "${pkgs.ffmpeg-headless.lib}/lib/libavutil.so" \
--prefix LD_PRELOAD : "${pkgs.ffmpeg-headless.lib}/lib/libswresample.so" \

可以解决问题。这可能不是最优雅的解决方案。
这样做的原因在于Electron自己也带着一个ffmpeg(阉割版的),如果只是设置FFMPEG_MODE=system那么编译出的原生模块会链接到Electron自带的那个,因此这里要手动加载nixpkgs版的ffmpeg才能得到完整功能

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nixpkgs 版我没有测试,估计是同理

@ccicnce113424 ccicnce113424 Aug 15, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

添加LD_LIBRARY_PATH可以解决这个问题吗?我现在不知道怎么用splayer打开外部的媒体文件。 不行

@SegmentationViolator
SegmentationViolator force-pushed the feat/flake branch 2 times, most recently from 9580e4d to 42ee1c5 Compare August 17, 2026 12:02
@kyv001

kyv001 commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

如果这个pr还在跟进的话,以下是一些可能需要的更新:

61d19d3 加入了libpulse.so依赖,可能需要pulseaudio作运行时依赖

deb8336 加入了一个对process.resourcePath的引用,需要在postPatch替换为"'$out/share/splayer-next/resources'"

              substituteInPlace electron/main/services/recognition/fingerprint.ts \
                --replace-fail 'process.resourcesPath' "'$out/share/splayer-next/resources'"

@SegmentationViolator
SegmentationViolator marked this pull request as ready for review August 17, 2026 13:34
refactor: 从 package.json 获取 flake 的包版本

fix: 在 flake 中修正 desktop 文件的 icon 属性。

fix: 删除 `prebuilds/` 目录以强制重新构建。

fix: 在包装器中设置 LD_PRELOAD 前缀,以加载正确的 FFmpeg 库

fix: 修补 fingerprinting.ts 中的资源路径并添加 PulseAudio 依赖
@MasterZack69

Copy link
Copy Markdown

在最新的提交之后,ALAC 解码问题已经解决了

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants