From 2a4d5e6f44f9eb0d04ee3a779e138ae1017d6b95 Mon Sep 17 00:00:00 2001 From: Robert Helgesson Date: Thu, 27 Oct 2022 14:47:50 +0200 Subject: [PATCH] home-environment: add hm-version file This commits adds a file `hm-version` to the generated generation directory. This file will contain the release version, and if available, the Git commit hash. (cherry picked from commit 32fe7d2ebb7e338ad95a3ea9393fc6ad681368ce) --- modules/home-environment.nix | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/modules/home-environment.nix b/modules/home-environment.nix index b83cf1d1e..dfbcbdc6b 100644 --- a/modules/home-environment.nix +++ b/modules/home-environment.nix @@ -676,6 +676,33 @@ in ${activationCmds} ''; + + getVersion = pkgs.writeShellScript "get-hm-version" '' + set -euo pipefail + + cd "${../.}" || exit 1 + + # Get the base release and initialize an empty version suffix. + release=$(< .release) + suffix="" + + # If we are in a Git repo then update the suffix to be + # + # .git.HASH + # + # where HASH are the first 8 characters of the commit hash. + if [[ -f .git/HEAD ]]; then + ref=$(sed '/ref:/ { s/.* //; }' .git/HEAD) + if [[ -f ".git/$ref" ]]; then + hash=$(< ".git/$ref") + if [[ -n "$hash" ]]; then + suffix=".git.''${hash:0:8}" + fi + fi + fi + + echo "$release$suffix" + ''; in pkgs.runCommand "home-manager-generation" @@ -685,6 +712,8 @@ in '' mkdir -p $out + ${getVersion} > $out/hm-version + cp ${activationScript} $out/activate mkdir $out/bin