Skip to content

build: 添加 Nix flake 支持 - #151

Draft
SegmentationViolator wants to merge 2 commits into
SPlayer-Dev:devfrom
SegmentationViolator:feat/flake
Draft

build: 添加 Nix flake 支持#151
SegmentationViolator wants to merge 2 commits 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里也有一个维护包定义来着

refactor: 从 package.json 获取 flake 的包版本
@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
exec = "splayer-next %U";
terminal = false;
type = "Application";
icon = "SPlayer-Next";

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.

上面把图标安装到了$out/share/icons/hicolor/$_icons/apps/splayer-next.png,是全小写的splayer-next,但是此处图标写成了SPlayer-Next,大小写不匹配会导致找不到正确图标

@SegmentationViolator
SegmentationViolator marked this pull request as draft August 12, 2026 14:11
Comment thread flake.nix
pkgs.python3
pkgs.makeWrapper
pkgs.copyDesktopItems
pkgs.pkg-config

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.

现在的问题是在项目根目录直接执行nix build ".#splayer-next"或者nix run ".#splayer-next"都是可以正常运行的,但是如果把该flake引入系统配置再进行nixos-rebuild那么在wayland环境中splayer-next会找不到libstdc++.so.6进而无法正常显示窗口。在这里加入pkgs.autoPatchelfHook可以解决这个问题,即使是在系统配置中引入也可以正常启动运行。

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.

我希望这个可以解决 @MasterZack69 的问题

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I hope this can be resolved. @MasterZack69The problem

我可以确认添加 pkgs.autoPatchelfHook 后,应用能够正常构建并启动。

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

现在的问题是在项目根目录直接执行nix build ".#splayer-next"或者nix run ".#splayer-next"都是可以正常运行的,但是如果把该flake引入系统配置再进行nixos-rebuild那么在wayland环境中splayer-next会找不到libstdc++.so.6进而无法正常显示窗口。在这里加入pkgs.autoPatchelfHook可以解决这个问题,即使是在系统配置中引入也可以正常启动运行。

我曾短暂地将 pkgs.autoPatchelfHook 添加到 buildInputs 中,这解决了 MasterZack69 遇到的问题。不过,在发现 ccince113424 的 package.nix 中并没有它之后,我又把它移除了。

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.

我的LLM智能体告诉我nixpkgs版的111行rm -rf prebuilds很重要,因为better-sqlite3自带了预编译二进制,但这些预编译二进制不携带RUNPATH所以在NixOS的非标准路径中找不到libstdc++.so.6

patchelf会注入RUNPATH从而防止报错因此加入pkgs.autoPatchelfHook可以解决问题;
直接删除预编译二进制会强制使用新编译的原生模块而不是预编译的二进制,因此携带了正确的RUNPATH而不会报错,因此rm -rf prebuilds也可以解决问题。

很抱歉在这里复读LLM内容,我只是觉得这些内容能帮上忙。

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.

5 participants