From d78b3488a76d251701ab58a9b7f0dd092b806c1e Mon Sep 17 00:00:00 2001 From: Robert Helgesson Date: Fri, 28 Oct 2022 22:51:35 +0200 Subject: [PATCH] home-environment: update hm-version generation Instead of home-made script use the Nixpkgs library functions. This will hopefully be more robust and give more accurate results. (cherry picked from commit 423211401c245934db5052e3867cac704f658544) --- modules/home-environment.nix | 37 +----------------------------------- modules/misc/version.nix | 34 +++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 36 deletions(-) diff --git a/modules/home-environment.nix b/modules/home-environment.nix index 636681023..9c0a7a1cf 100644 --- a/modules/home-environment.nix +++ b/modules/home-environment.nix @@ -676,41 +676,6 @@ in ${activationCmds} ''; - - getVersion = pkgs.writeShellScript "get-hm-version" '' - set -euo pipefail - - dir="${../.}" - - # Apparently, dir is not always set to the Home Manager directory. - if [[ ! -d $dir ]]; then - echo "" - exit 0 - fi - - cd "$dir" || 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" @@ -720,7 +685,7 @@ in '' mkdir -p $out - ${getVersion} > $out/hm-version + echo "${config.home.version.full}" > $out/hm-version cp ${activationScript} $out/activate diff --git a/modules/misc/version.nix b/modules/misc/version.nix index 9673c0ffa..8f6a3fcbc 100644 --- a/modules/misc/version.nix +++ b/modules/misc/version.nix @@ -30,5 +30,39 @@ with lib; conversion or moving files. ''; }; + + home.version = { + full = mkOption { + internal = true; + readOnly = true; + type = types.str; + default = let + inherit (config.home.version) release revision; + suffix = + optionalString (revision != null) "+${substring 0 8 revision}"; + in "${release}${suffix}"; + example = "22.05+213a0629"; + description = "The full Home Manager version."; + }; + + release = mkOption { + internal = true; + readOnly = true; + type = types.str; + default = fileContents ../../.release; + example = "22.05"; + description = "The Home Manager release."; + }; + + revision = mkOption { + internal = true; + type = types.nullOr types.str; + default = let gitRepo = "${toString ./../..}/.git"; + in if pathIsGitRepo gitRepo then commitIdFromGitRepo gitRepo else null; + description = '' + The Git revision from which this Home Manager configuration was built. + ''; + }; + }; }; }