Repository navigation
feat(nix): add flake with package, overlay and devShells - #104
WangYiBen0 wants to merge 4 commits into
Conversation
std-microblock
left a comment
There was a problem hiding this comment.
Thanks, the write-up is good and the traps you documented are real. A few concrete problems before merge:
Blocking
nix/versions.nixsays it can be reduced to{ }and the flake still evaluates. It can't:nix/tools.nixunconditionally readsversions.versionandversions.pnpm.depsHash, andmkCelemod's defaultcargoHash ? versions.cargoHashis evaluated too. Fix the comment or the code, otherwise following that instruction breaks the flake.scripts/update-nix-hashes.sh:--repo-rootcan never be reached, because theflake.nixexistence check runs before the argument parsing. Move thewhile [ $# -gt 0 ]loop above it.nix/hooks/celemod.shandnix/hooks/ci.share never sourced by eithershellHook. Wire them in or drop them.- The
resultsymlink left bynix buildis not in.gitignore. Please add/result(and/result-*). - Nothing in CI runs the flake, while the three hashes have to be recomputed every time
Cargo.lockorsrc/celemod-ui/pnpm-lock.yamlchanges. Please add a check job (ubuntu-latest is enough), or say innix/README.mdthat this is best effort and who refreshes the hashes.
Nits
cargoRootis described three ways: the PR body says it is required,nix/README.mdhas a section titled "NocargoRoot", andnix/tools.nixdefaults to".". Please align.nix/versions.nixhardcodesversion = "1.2.2"whileversion.txtis the single source of truth. Drop it or explain why it is there.nix/README.mdsays the refresher writes a fake hash into the file first; it actually builds a throwaway expression withpkgs.lib.fakeHash. Worth rewording.nix/versions.nixhas no trailing newline.
One question: is a Nix package meant to be supported long term here, and who owns the hash refresh when the lockfiles move? That answer decides how much of the above is blocking.
你说得对,三处都确实无条件求值。改了代码也改了注释: repoVersion = lib.strings.trim (builtins.readFile ./../version.txt);
inherit (versions) cargoHash;
已调换,先解析后校验。
已接进 接的过程中发现另一个问题:
已加。
选了加 job,
统一成
删了。
已按实际做法重写。
已补。
我的意思是长期维护:lockfile 变动时由我刷哈希。脚本是自助式的,CI 也会在 另外把包名统一了:上游 改动在 |
Adds a flake exposing packages.celemod, packages.celemod-ui,
overlays.default and devShells.{default,ci} for x86_64-linux and
aarch64-linux.
The package builds and runs:
nix build .#celemod
nix run .#celemod
The Vite frontend is a separate derivation driven by fetchPnpmDeps. The Tauri
shell builds through cargo-tauri.hook, which runs tauri-build with the
custom-protocol feature so the finished dist/ is embedded; without it the
binary loads build.devUrl at runtime and shows an empty window.
wrapGAppsHook4 supplies the GTK runtime environment (XDG_DATA_DIRS,
GDK_PIXBUF_MODULE_PATH, GIO modules) and installs the desktop entry and icons.
Constraints worth knowing, each commented at the relevant line and written up
in nix/README.md:
* nightly Rust is required (src-tauri/src/lib.rs uses #![feature(try_blocks)]);
rustPlatform comes from rust-overlay's nightly .default toolchain
* cargoHash must be top-level and cargoLock absent; supplying both makes
buildRustPackage prefer importCargoLock, which then demands outputHashes
for the git dependency
* cargoRoot stays "." so fetchCargoVendor finds the workspace lockfile
* rust-overlay is pinned by rev, not HEAD, so evaluation never calls the
GitHub API
* nix/ must stay git-tracked: a git-repo flake cannot see untracked files
Every hash in nix/versions.nix came from a real fetch failure.
scripts/update-nix-hashes.sh refreshes them idempotently and asserts that what
it writes matches what it measured.
checks.<system>.celemod-is-real guards against the packages collapsing to
runCommand placeholders, which `nix flake check --no-build` cannot detect.
Blocking items:
* nix/versions.nix claimed it could be reduced to `{ }`. It cannot:
tools.nix reads cargoHash, pnpm.fetcherVersion and pnpm.depsHash
unconditionally. The comment now says so.
* Drop `version` from versions.nix entirely. It duplicated version.txt and
tools.nix now reads version.txt through builtins.readFile, so the file
holds hashes only.
* scripts/update-nix-hashes.sh parsed arguments after validating REPO_ROOT,
so --repo-root could never be reached. Parse first, then validate.
* Sourcing nix/hooks/{celemod,ci}.sh from the shellHook instead of shipping
them unused. ci.sh also drives colourless output, so CARGO_TERM_COLOR in
mkShell now depends on the mode.
* Ignore the /result symlinks nix build leaves behind.
* Add .github/workflows/Nix.yml: evaluates the flake on every relevant
change, builds the package, and fails when nix/versions.nix is stale
relative to either lockfile.
Nits:
* cargoRoot is documented as `cargoRoot = "."` everywhere; the README no
longer contradicts tools.nix.
* README describes the refresher accurately: it builds a throwaway
expression with pkgs.lib.fakeHash rather than writing a fake into the file.
* versions.nix ends with a newline.
Also renames the package attributes to match the upstream crate, whose
[package] and [[bin]] are both `cele-mod`.
406c930 to
1bfa798
Compare
v1.4.0 moved the frontend from src/celemod-ui/ to the repository root
(package.json, pnpm-lock.yaml and pnpm-workspace.yaml now sit next to
Cargo.toml). Follow that in the packaging:
* celemodUiDeps takes the root as src instead of src + "/src/celemod-ui"
* pnpmRoot is "." instead of "src/celemod-ui"
* the app's postPatch stages the built frontend into dist/ instead of
src/celemod-ui/dist/
* update-nix-hashes.sh points the pnpm fetcher at the root too
Taken upstream's .gitignore wholesale: it already contained every entry this
branch had added, plus the root-level /node_modules and /dist the new layout
needs.
Summary
Adds a Nix flake:
packages.celemod,packages.celemod-ui,overlays.defaultand
devShells.{default,ci}forx86_64-linuxandaarch64-linux.Verified
nix eval .#packages.x86_64-linux.celemod.version1.2.2, read fromversion.txtnix build .#packages.x86_64-linux.celemod$out/bin/cele-mod(GTK wrapper) +.cele-mod-wrappednix flake check --all-systems --no-buildImplementation notes
Constraints of this nixpkgs or this repository, not preferences. Each is
commented at the relevant line and written up in
nix/README.md.src-tauri/src/lib.rsuses#![feature(try_blocks)], so a stable rustc fails withE0554.rustPlatformcomes from rust-overlay'srust-bin.nightly.latest.default; the component.rustcships no std sysroot (E0463).cargo-tauri.hookdrives the build. It runstauri-buildwith thecustom-protocolfeature, so the frontend is embedded instead of loaded frombuild.devUrlat runtime. Building without it produces a binary that opens a window and shows nothing.wrapGAppsHook4supplies the GTK runtime environment (XDG_DATA_DIRS,GDK_PIXBUF_MODULE_PATH, GIO modules) and installs the desktop entry and icons.cargoHashis top-level andcargoLockabsent.buildRustPackagepreferscargoLockwhenever it is set and silently ignores a top-levelcargoHash, then fails withNo hash was found while vendoring the git dependency game-scanner-1.2.0.cargoRoot = ".". It also drives vendor staging, so any other value makes it look forCargo.lockoutside the workspace root;buildAndTestSubdirselectssrc-tauri.CMAKE_POLICY_VERSION_MINIMUM = 3.5.prost-build 0.10.4vendors protobuf and runs CMake on a pre-3.5CMakeLists.txt.nix/must stay tracked. A git-repo flake cannot see untracked files.Hashes
All three hashes in
nix/versions.nixcame from real fetch failures, neverguesses.
scripts/update-nix-hashes.shrecomputes them, validates everydigest, asserts the written value matches the one just measured, and is
byte-identical on a second run.
Guard
checks.<system>.celemod-is-realfails the build if either package stops beinga real derivation, because
nix flake check --no-buildcannot tell a realderivation from an empty
runCommandstub. It asserts onnativeBuildInputsrather than
passthru.placeholder, which a plainrunCommandnever sets.Scope
Desktop builds only. Android, AppImage/deb bundling and
tauri buildoutputartifacts are untouched.