nixos/version: fix case where .git is a symlink
Beforec9214c394b
and9d396d2e42
if .git is symlink the version would gracefully default to no git revision. With those changes an exception is thrown instead. This introduces a new function `pathIsGitRepo` that checks if `commitIdFromGitRepo` fails without error so we don't have to reimplement this logic again and can fail gracefully.
This commit is contained in:
parent
21f74cc3ab
commit
46773a15b3
|
@ -101,7 +101,7 @@ let
|
||||||
inherit (sources) pathType pathIsDirectory cleanSourceFilter
|
inherit (sources) pathType pathIsDirectory cleanSourceFilter
|
||||||
cleanSource sourceByRegex sourceFilesBySuffices
|
cleanSource sourceByRegex sourceFilesBySuffices
|
||||||
commitIdFromGitRepo cleanSourceWith pathHasContext
|
commitIdFromGitRepo cleanSourceWith pathHasContext
|
||||||
canCleanSource pathIsRegularFile;
|
canCleanSource pathIsRegularFile pathIsGitRepo;
|
||||||
inherit (modules) evalModules unifyModuleSyntax
|
inherit (modules) evalModules unifyModuleSyntax
|
||||||
applyIfFunction mergeModules
|
applyIfFunction mergeModules
|
||||||
mergeModules' mergeOptionDecls evalOptionValue mergeDefinitions
|
mergeModules' mergeOptionDecls evalOptionValue mergeDefinitions
|
||||||
|
|
|
@ -105,6 +105,7 @@ rec {
|
||||||
in type == "directory" || lib.any (ext: lib.hasSuffix ext base) exts;
|
in type == "directory" || lib.any (ext: lib.hasSuffix ext base) exts;
|
||||||
in cleanSourceWith { inherit filter; src = path; };
|
in cleanSourceWith { inherit filter; src = path; };
|
||||||
|
|
||||||
|
pathIsGitRepo = path: (builtins.tryEval (commitIdFromGitRepo path)).success;
|
||||||
|
|
||||||
# Get the commit id of a git repo
|
# Get the commit id of a git repo
|
||||||
# Example: commitIdFromGitRepo <nixpkgs/.git>
|
# Example: commitIdFromGitRepo <nixpkgs/.git>
|
||||||
|
|
|
@ -191,7 +191,7 @@ rec {
|
||||||
let
|
let
|
||||||
revisionFile = "${toString ./..}/.git-revision";
|
revisionFile = "${toString ./..}/.git-revision";
|
||||||
gitRepo = "${toString ./..}/.git";
|
gitRepo = "${toString ./..}/.git";
|
||||||
in if builtins.pathExists gitRepo
|
in if lib.pathIsGitRepo gitRepo
|
||||||
then lib.commitIdFromGitRepo gitRepo
|
then lib.commitIdFromGitRepo gitRepo
|
||||||
else if lib.pathExists revisionFile then lib.fileContents revisionFile
|
else if lib.pathExists revisionFile then lib.fileContents revisionFile
|
||||||
else default;
|
else default;
|
||||||
|
|
|
@ -6,6 +6,7 @@ let
|
||||||
cfg = config.system.nixos;
|
cfg = config.system.nixos;
|
||||||
|
|
||||||
gitRepo = "${toString pkgs.path}/.git";
|
gitRepo = "${toString pkgs.path}/.git";
|
||||||
|
gitRepoValid = lib.pathIsGitRepo gitRepo;
|
||||||
gitCommitId = lib.substring 0 7 (commitIdFromGitRepo gitRepo);
|
gitCommitId = lib.substring 0 7 (commitIdFromGitRepo gitRepo);
|
||||||
in
|
in
|
||||||
|
|
||||||
|
@ -91,8 +92,8 @@ in
|
||||||
# These defaults are set here rather than up there so that
|
# These defaults are set here rather than up there so that
|
||||||
# changing them would not rebuild the manual
|
# changing them would not rebuild the manual
|
||||||
version = mkDefault (cfg.release + cfg.versionSuffix);
|
version = mkDefault (cfg.release + cfg.versionSuffix);
|
||||||
revision = mkIf (pathExists gitRepo) (mkDefault gitCommitId);
|
revision = mkIf gitRepoValid (mkDefault gitCommitId);
|
||||||
versionSuffix = mkIf (pathExists gitRepo) (mkDefault (".git." + gitCommitId));
|
versionSuffix = mkIf gitRepoValid (mkDefault (".git." + gitCommitId));
|
||||||
};
|
};
|
||||||
|
|
||||||
# Generate /etc/os-release. See
|
# Generate /etc/os-release. See
|
||||||
|
|
Loading…
Reference in a new issue