feat(build-time-versioning): nix packages compute build time at build phase

First attempt used builtins.currentTime at flake-evaluation time -- this
broke the plain, documented `nix build .#xcecore_debug` command entirely
(pure-eval strips builtins.currentTime, requiring --impure) and produced
a raw epoch-seconds string instead of UTC ISO-8601. Caught by task-local
review (REJECTED, round 1) before merge.

Fixed by moving the computation into each derivation's own build phase:
a preConfigure hook in xce.nix/xcecli.nix runs `date -u` (stdenv's
bundled coreutils, unaffected by pure-eval) and appends -Dbuild_time= to
mesonFlagsArray, with a fail-loud guard against empty output. commit_id's
existing self.shortRev/self.dirtyShortRev eval-time mechanism is
untouched. Verified via nix eval (no --impure) and nix build reaching
configure with real values on both xcecore_debug and xcecli (round 2,
APPROVED).

Task 2.2/13 of build-time-versioning. Also corrects design.md/research.md,
which described the now-superseded builtins.currentTime approach.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Rongsong Shen 2026-08-20 09:32:34 +00:00
parent dc574abf54
commit d08fda76a5
No known key found for this signature in database
GPG key ID: 5BCDAAE0123E9FE2
7 changed files with 64 additions and 9 deletions

View file

@ -16,6 +16,19 @@
if builtins.hasAttr "shortRev" self
then self.shortRev
else self.dirtyShortRev;
# NOTE (build-time-versioning task 2.2, remediation round): unlike
# myCommitId (a genuinely flake-level, eval-time concept sourced from
# self.shortRev/self.dirtyShortRev), the build timestamp is NOT
# computed here. An earlier attempt used `builtins.toString
# builtins.currentTime` at this exact spot -- but builtins.currentTime
# is stripped entirely under a flake's default pure evaluation
# ("error: attribute 'currentTime' missing"), so `nix build
# .#xcecore_debug` (no --impure, the documented canonical command)
# failed at evaluation. Fixed by moving the build-time computation
# into each derivation's own build phase instead (xce.nix/xcecli.nix
# `preConfigure`, via stdenv's bundled `date -u`) -- see those files.
# Nothing build-time-related needs to be threaded through the flake
# or nixSupport/default.nix any more; only myCommitId still does.
in
flake-utils.lib.eachSystem supportedSystems (
system: let