Automatically include 'git describe' output in version text

This commit is contained in:
Brian Picciano 2024-12-19 11:51:37 +01:00
parent 40b2db580e
commit 2bb7537602

View File

@ -3,7 +3,7 @@
hostSystem ? buildSystem, hostSystem ? buildSystem,
pkgsNix ? (import ./nix/pkgs.nix), pkgsNix ? (import ./nix/pkgs.nix),
revision ? "dev", revision ? null,
releaseName ? "dev", releaseName ? "dev",
}: let }: let
@ -20,12 +20,22 @@
in rec { 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"; name = "isle-version";
inherit buildSystem hostSystem revision releaseName; inherit buildSystem hostSystem revisionFile releaseName;
nativeBuildInputs = [ pkgsNative.git ];
goVersion = pkgs.go.version; goVersion = pkgs.go.version;
garageVersion = garageNix.version; garageVersion = garageNix.version;
@ -36,13 +46,13 @@ in rec {
versionFile=version versionFile=version
echo "Release: $releaseName" >> "$versionFile" echo "Release: $releaseName" >> "$versionFile"
echo "Platform: $hostSystem" >> "$versionFile" echo "Platform: $hostSystem" >> "$versionFile"
echo "Git Revision: $revision" >> "$versionFile" echo "Git Revision: $(cat $revisionFile)" >> "$versionFile"
echo "Go Version: $goVersion" >> "$versionFile" echo "Go Version: $goVersion" >> "$versionFile"
echo "Garage Version: $garageVersion" >> "$versionFile" echo "Garage Version: $garageVersion" >> "$versionFile"
echo "NixPkgs Version: $nixpkgsVersion" >> "$versionFile" echo "NixPkgs Version: $nixpkgsVersion" >> "$versionFile"
echo "Build Platform: $buildSystem" >> "$versionFile" echo "Build Platform: $buildSystem" >> "$versionFile"
mkdir -p "$out"/share mkdir -p "$out"/share
cp "$versionFile" "$out"/share cp "$versionFile" "$out"/share