Use commit time not build time

Can't use build time in pure evaluation mode.
This commit is contained in:
Eli Ribble 2026-05-19 15:03:09 +00:00
parent f4ace63fdc
commit 496b9b34bc
No known key found for this signature in database

View file

@ -1,31 +1,41 @@
{ pkgs ? import <nixpkgs> { }, proj ? pkgs.proj }:
let
# Get commit timestamp at eval time (pure)
getCommitTime =
if builtins.pathExists ./.git
then builtins.replaceStrings ["\n"] [""] (builtins.readFile (
pkgs.runCommand "git-commit-time" {} ''
${pkgs.git}/bin/git -C ${./.} log -1 --format=%ct > $out
''
))
else "0";
in
pkgs.buildGoModule rec {
buildTime = builtins.currentTime;
# Try to get git info, fallback to version if .git doesn't exist
# Note: This runs at eval time, so it captures the version when you build
pname = "nidus-sync";
version = "0.0.12";
src = ./.;
gitRevision =
if builtins.pathExists ./.git
then pkgs.lib.commitIdFromGitRepo ./.git
else "unknown";
gitDescribe = builtins.readFile (pkgs.runCommand "git-describe" {} ''
${pkgs.git}/bin/git -C ${./.} describe --always --dirty --tags 2>/dev/null > $out || echo "${version}" > $out
'');
buildTime = getCommitTime;
ldflags = [
"-s"
"-w"
"-X main.Version=${version}"
"-X main.Commit=${gitRevision}"
"-X main.BuildTime=${toString buildTime}"
"-X main.BuildTime=${buildTime}"
];
meta = {
description = "Nidus Sync";
homepage = "https://github.com/Gleipnir-Technology/nidus-sync";
};
pname = "nidus-sync";
src = ./.;
subPackages = [];
version = "0.0.12";
vendorHash = "sha256-jlPS8lWdNPj60BMUcCrxteLuc7RXEXDtzlwjsFBJg0Y=";
buildInputs = [ pkgs.proj ];