Use commit time not build time
Can't use build time in pure evaluation mode.
This commit is contained in:
parent
f4ace63fdc
commit
496b9b34bc
1 changed files with 20 additions and 10 deletions
30
default.nix
30
default.nix
|
|
@ -1,31 +1,41 @@
|
||||||
{ pkgs ? import <nixpkgs> { }, proj ? pkgs.proj }:
|
{ 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 {
|
pkgs.buildGoModule rec {
|
||||||
buildTime = builtins.currentTime;
|
pname = "nidus-sync";
|
||||||
# Try to get git info, fallback to version if .git doesn't exist
|
version = "0.0.12";
|
||||||
# Note: This runs at eval time, so it captures the version when you build
|
src = ./.;
|
||||||
|
|
||||||
gitRevision =
|
gitRevision =
|
||||||
if builtins.pathExists ./.git
|
if builtins.pathExists ./.git
|
||||||
then pkgs.lib.commitIdFromGitRepo ./.git
|
then pkgs.lib.commitIdFromGitRepo ./.git
|
||||||
else "unknown";
|
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 = [
|
ldflags = [
|
||||||
"-s"
|
"-s"
|
||||||
"-w"
|
"-w"
|
||||||
"-X main.Version=${version}"
|
"-X main.Version=${version}"
|
||||||
"-X main.Commit=${gitRevision}"
|
"-X main.Commit=${gitRevision}"
|
||||||
"-X main.BuildTime=${toString buildTime}"
|
"-X main.BuildTime=${buildTime}"
|
||||||
];
|
];
|
||||||
meta = {
|
meta = {
|
||||||
description = "Nidus Sync";
|
description = "Nidus Sync";
|
||||||
homepage = "https://github.com/Gleipnir-Technology/nidus-sync";
|
homepage = "https://github.com/Gleipnir-Technology/nidus-sync";
|
||||||
};
|
};
|
||||||
pname = "nidus-sync";
|
|
||||||
src = ./.;
|
|
||||||
subPackages = [];
|
subPackages = [];
|
||||||
version = "0.0.12";
|
|
||||||
vendorHash = "sha256-jlPS8lWdNPj60BMUcCrxteLuc7RXEXDtzlwjsFBJg0Y=";
|
vendorHash = "sha256-jlPS8lWdNPj60BMUcCrxteLuc7RXEXDtzlwjsFBJg0Y=";
|
||||||
|
|
||||||
buildInputs = [ pkgs.proj ];
|
buildInputs = [ pkgs.proj ];
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue