1
0
Fork 0
mirror of https://github.com/nix-community/home-manager.git synced 2024-12-14 11:57:55 +00:00

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.
This commit is contained in:
Robert Helgesson 2022-10-28 22:51:35 +02:00
parent 213a06295d
commit 423211401c
No known key found for this signature in database
GPG key ID: 36BDAA14C2797E89
2 changed files with 35 additions and 36 deletions

View file

@ -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

View file

@ -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.
'';
};
};
};
}