Move to setting version info explicitly in linker flags
Some checks failed
/ golint (push) Failing after 12s

We don't have go built-in VCS information in a nix build because the git
repository isn't present. After struggling to build an overlay that
would provide it, I decided this path is easier of just injecting in the
data that we need.

Issue: #5
This commit is contained in:
Eli Ribble 2026-05-19 19:45:04 +00:00
parent 81826f853e
commit d4cbfb960e
No known key found for this signature in database
8 changed files with 119 additions and 79 deletions

View file

@ -21,8 +21,32 @@
projPkg = proj.packages.${system}.default;
package = pkgs.callPackage ./default.nix {
proj = projPkg;
};
ldflags = ldflags;
proj = projPkg;
version = packageVersion;
};
# Pull VCS metadata from the flake's own git source.
# These fields are available when the flake lives inside a git checkout.
gitRevision = self.sourceInfo.rev or "dirty";
gitShortRev = self.sourceInfo.shortRev or "dirty";
gitDateTime = self.sourceInfo.lastModifiedDate or "unknown";
# Derive a human-readable version from the git date + short rev.
# lastModifiedDate is YYYYMMDDHHMMSS; pull out just YYYY-MM-DD.
packageVersion =
let
y = builtins.substring 0 4 gitDateTime;
m = builtins.substring 4 2 gitDateTime;
d = builtins.substring 6 2 gitDateTime;
in "${y}-${m}-${d}.${gitShortRev}";
ldflags = [
"-s" "-w"
"-X main.BuildTime=${gitDateTime}"
"-X main.Revision=${gitRevision}"
"-X main.Version=${packageVersion}"
];
in
{
packages.default = package;