Skip to content

feat(nix): add flake with package, overlay and devShells - #104

Open
WangYiBen0 wants to merge 1 commit into
std-microblock:masterfrom
WangYiBen0:nix-flake
Open

WangYiBen0 wants to merge 1 commit into
std-microblock:masterfrom
WangYiBen0:nix-flake

Conversation

@WangYiBen0

Copy link
Copy Markdown

Summary

Adds a Nix flake: packages.celemod, packages.celemod-ui, overlays.default
and devShells.{default,ci} for x86_64-linux and aarch64-linux.

nix build .#celemod
nix run   .#celemod
nix develop
nix flake check

Verified

check result
nix eval .#packages.x86_64-linux.celemod.version 1.2.2, read from version.txt
nix build .#packages.x86_64-linux.celemod exit 0
$out/bin/ cele-mod (GTK wrapper) + .cele-mod-wrapped
nix flake check --all-systems --no-build exit 0

Implementation notes

Constraints of this nixpkgs or this repository, not preferences. Each is
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)], so a stable rustc fails with E0554. rustPlatform comes from rust-overlay's rust-bin.nightly.latest.default; the component .rustc ships no std sysroot (E0463).
  • cargo-tauri.hook drives the build. It runs tauri-build with the custom-protocol feature, so the frontend is embedded instead of loaded from build.devUrl at runtime. Building without it produces a binary that opens a window and shows nothing.
  • wrapGAppsHook4 supplies the GTK runtime environment (XDG_DATA_DIRS, GDK_PIXBUF_MODULE_PATH, GIO modules) and installs the desktop entry and icons.
  • cargoHash is top-level and cargoLock absent. buildRustPackage prefers cargoLock whenever it is set and silently ignores a top-level cargoHash, then fails with No 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 for Cargo.lock outside the workspace root; buildAndTestSubdir selects src-tauri.
  • CMAKE_POLICY_VERSION_MINIMUM = 3.5. prost-build 0.10.4 vendors protobuf and runs CMake on a pre-3.5 CMakeLists.txt.
  • rust-overlay is pinned by rev, not HEAD. A floating ref makes every evaluation call the GitHub API, which rate-limits.
  • nix/ must stay tracked. A git-repo flake cannot see untracked files.

Hashes

All three hashes in nix/versions.nix came from real fetch failures, never
guesses. scripts/update-nix-hashes.sh recomputes them, validates every
digest, asserts the written value matches the one just measured, and is
byte-identical on a second run.

Guard

checks.<system>.celemod-is-real fails the build if either package stops being
a real derivation, because nix flake check --no-build cannot tell a real
derivation from an empty runCommand stub. It asserts on nativeBuildInputs
rather than passthru.placeholder, which a plain runCommand never sets.

Scope

Desktop builds only. Android, AppImage/deb bundling and tauri build output
artifacts are untouched.


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.
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.

1 participant