From 0b32492fd6133e2f650d10ad9c3629d863346a0d Mon Sep 17 00:00:00 2001 From: Eli Ribble Date: Mon, 20 Apr 2026 01:58:44 +0000 Subject: [PATCH] Add version information to build output --- default.nix | 15 +++++++++++++++ version.go | 6 ++++++ 2 files changed, 21 insertions(+) create mode 100644 version.go diff --git a/default.nix b/default.nix index 65e44f62..f8b6db60 100644 --- a/default.nix +++ b/default.nix @@ -1,6 +1,21 @@ { pkgs ? import { }, proj ? pkgs.proj }: pkgs.buildGoModule rec { + # 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 + 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 + ''); + ldflags = [ + "-s" + "-w" + "-X main.Version=${version}" + "-X main.Commit=${gitRevision}" + ]; meta = { description = "Nidus Sync"; homepage = "https://github.com/Gleipnir-Technology/nidus-sync"; diff --git a/version.go b/version.go new file mode 100644 index 00000000..e2f1bc4b --- /dev/null +++ b/version.go @@ -0,0 +1,6 @@ +package main + +var ( + Version = "dev" + Commit = "none" +)