diff --git a/cli/build.rs b/cli/build.rs index ec5119d762..942c616981 100644 --- a/cli/build.rs +++ b/cli/build.rs @@ -69,13 +69,20 @@ fn timestamp_to_date(ts_str: &str) -> Option> { .and_then(|ts| DateTime::::from_timestamp(ts, 0)) } -/// Return the git hash and the committer timestamp +/// Return the UTC committer date (maybe) and the git hash fn get_git_timestamp_and_hash() -> Option<(String, Option>)> { - if let Some(nix_hash) = std::env::var("NIX_JJ_GIT_HASH") - .ok() - .filter(|s| !s.is_empty()) - { - return Some((nix_hash, None)); + if let (Ok(nix_hash), maybe_nix_timestamp) = ( + std::env::var("NIX_JJ_GIT_HASH"), + std::env::var("NIX_JJ_GIT_TIMESTAMP"), + ) { + if !nix_hash.is_empty() { + return Some(( + nix_hash, + maybe_nix_timestamp + .ok() + .and_then(|ts_str| timestamp_to_date(&ts_str)), + )); + } } fn parse_timestamp_vbar_hash(bytes: &[u8]) -> (String, Option>) { diff --git a/flake.nix b/flake.nix index 53260e4e9c..3bffe98b61 100644 --- a/flake.nix +++ b/flake.nix @@ -18,6 +18,11 @@ } // (flake-utils.lib.eachDefaultSystem (system: let + # TODO(aseipp): Use dirtyRev and dirtyShortRev to record dirty checkout + # when we update `build.rs` to understand dirty checkouts. + gitRev = self.rev or ""; + gitTimestamp = toString self.lastModified; + pkgs = import nixpkgs { inherit system; overlays = [ @@ -76,7 +81,8 @@ ZSTD_SYS_USE_PKG_CONFIG = "1"; LIBSSH2_SYS_USE_PKG_CONFIG = "1"; - NIX_JJ_GIT_HASH = self.rev or ""; + NIX_JJ_GIT_HASH = gitRev; + NIX_JJ_GIT_TIMESTAMP = gitTimestamp; CARGO_INCREMENTAL = "0"; preCheck = "export RUST_BACKTRACE=1"; @@ -132,6 +138,8 @@ export RUST_BACKTRACE=1 export ZSTD_SYS_USE_PKG_CONFIG=1 export LIBSSH2_SYS_USE_PKG_CONFIG=1 + export NIX_JJ_GIT_HASH="${gitRev}" + export NIX_JJ_GIT_TIMESTAMP="${gitTimestamp}"; ''; }; }));