fix(build): pass git hash to Nix builds via env var

- build.rs checks GIT_HASH env var before shelling out to git
- flake.nix injects self.shortRev into the build environment
- Remove version number from footer, keep only commit hash
This commit is contained in:
Jon Seager 2026-02-07 11:17:03 +00:00
parent 9ceb1a2b69
commit ed0cb2fd39
No known key found for this signature in database
3 changed files with 11 additions and 9 deletions

View file

@ -7,14 +7,15 @@ fn main() {
} }
fn git_hash() { fn git_hash() {
let output = Command::new("git") let hash = std::env::var("GIT_HASH").ok().or_else(|| {
Command::new("git")
.args(["rev-parse", "--short", "HEAD"]) .args(["rev-parse", "--short", "HEAD"])
.output() .output()
.ok() .ok()
.filter(|o| o.status.success()) .filter(|o| o.status.success())
.and_then(|o| String::from_utf8(o.stdout).ok()) .and_then(|o| String::from_utf8(o.stdout).ok())
.unwrap_or_default(); });
let hash = output.trim(); let hash = hash.as_deref().map(str::trim).unwrap_or_default();
println!("cargo:rustc-env=GIT_HASH={hash}"); println!("cargo:rustc-env=GIT_HASH={hash}");
} }

View file

@ -63,6 +63,7 @@
stdenv.cc.cc.lib stdenv.cc.cc.lib
]; ];
env.GIT_HASH = self.shortRev or self.dirtyShortRev or "dev";
env.LD_LIBRARY_PATH = lib.makeLibraryPath [ pkgs.openssl ]; env.LD_LIBRARY_PATH = lib.makeLibraryPath [ pkgs.openssl ];
meta = { meta = {

View file

@ -116,7 +116,7 @@
<main class="mx-auto flex w-full max-w-5xl flex-col gap-8 px-6 py-10"> <main class="mx-auto flex w-full max-w-5xl flex-col gap-8 px-6 py-10">
{% include "partials/nav.html" %} {% block content %}{% endblock %} {% include "partials/nav.html" %} {% block content %}{% endblock %}
<footer class="mt-8 text-center text-xs tracking-widest text-text-muted" style="font-variant: small-caps"> <footer class="mt-8 text-center text-xs tracking-widest text-text-muted" style="font-variant: small-caps">
<p>B{rew}log by <a href="https://jnsgr.uk" class="text-text-muted hover:text-accent transition" target="_blank" rel="noreferrer noopener">jnsgruk</a> · {{ version_info.version }} · <a href="https://github.com/jnsgruk/brewlog/commit/{{ version_info.commit }}" class="text-text-muted hover:text-accent transition" target="_blank" rel="noreferrer noopener">{{ version_info.commit }}</a></p> <p>B{rew}log by <a href="https://jnsgr.uk" class="text-text-muted hover:text-accent transition" target="_blank" rel="noreferrer noopener">jnsgruk</a> · <a href="https://github.com/jnsgruk/brewlog/commit/{{ version_info.commit }}" class="text-text-muted hover:text-accent transition" target="_blank" rel="noreferrer noopener">{{ version_info.commit }}</a></p>
</footer> </footer>
</main> </main>
</body> </body>