From 2bb7537602d7572035fcc5b61fff9369fb04f2c4 Mon Sep 17 00:00:00 2001 From: Brian Picciano Date: Thu, 19 Dec 2024 11:51:37 +0100 Subject: [PATCH] Automatically include 'git describe' output in version text --- default.nix | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/default.nix b/default.nix index 44fac61..2063e75 100644 --- a/default.nix +++ b/default.nix @@ -3,7 +3,7 @@ hostSystem ? buildSystem, pkgsNix ? (import ./nix/pkgs.nix), - revision ? "dev", + revision ? null, releaseName ? "dev", }: let @@ -20,12 +20,22 @@ in rec { - version = pkgs.stdenv.mkDerivation { + version = let + revisionFile = if builtins.isNull revision + then pkgsNative.stdenv.mkDerivation { + name = "revision.txt"; + nativeBuildInputs = [ pkgsNative.git ]; + src = ./.git; + phases = [ "installPhase" ]; + installPhase = '' + git -c safe.directory='*' -C $src describe --tags > $out + ''; + } + else pkgsNative.writeText "revision.txt" revision; + in pkgs.stdenv.mkDerivation { name = "isle-version"; - inherit buildSystem hostSystem revision releaseName; - - nativeBuildInputs = [ pkgsNative.git ]; + inherit buildSystem hostSystem revisionFile releaseName; goVersion = pkgs.go.version; garageVersion = garageNix.version; @@ -36,13 +46,13 @@ in rec { versionFile=version - echo "Release: $releaseName" >> "$versionFile" - echo "Platform: $hostSystem" >> "$versionFile" - echo "Git Revision: $revision" >> "$versionFile" - echo "Go Version: $goVersion" >> "$versionFile" - echo "Garage Version: $garageVersion" >> "$versionFile" - echo "NixPkgs Version: $nixpkgsVersion" >> "$versionFile" - echo "Build Platform: $buildSystem" >> "$versionFile" + echo "Release: $releaseName" >> "$versionFile" + echo "Platform: $hostSystem" >> "$versionFile" + echo "Git Revision: $(cat $revisionFile)" >> "$versionFile" + echo "Go Version: $goVersion" >> "$versionFile" + echo "Garage Version: $garageVersion" >> "$versionFile" + echo "NixPkgs Version: $nixpkgsVersion" >> "$versionFile" + echo "Build Platform: $buildSystem" >> "$versionFile" mkdir -p "$out"/share cp "$versionFile" "$out"/share