summary refs log tree commit diff
path: root/nixos
diff options
context:
space:
mode:
authorFranz Pletz <fpletz@fnordicwalking.de>2020-01-20 00:44:07 +0100
committerFranz Pletz <fpletz@fnordicwalking.de>2020-01-20 00:53:44 +0100
commit46773a15b3af302c3fb2a6e31fb589553a903099 (patch)
treee114d7663484ab94f159082a4095f2e95d198f4f /nixos
parent21f74cc3aba4dd4c8540b35f8cd0873bef15a2d6 (diff)
downloadnixpkgs-46773a15b3af302c3fb2a6e31fb589553a903099.tar
nixpkgs-46773a15b3af302c3fb2a6e31fb589553a903099.tar.gz
nixpkgs-46773a15b3af302c3fb2a6e31fb589553a903099.tar.bz2
nixpkgs-46773a15b3af302c3fb2a6e31fb589553a903099.tar.lz
nixpkgs-46773a15b3af302c3fb2a6e31fb589553a903099.tar.xz
nixpkgs-46773a15b3af302c3fb2a6e31fb589553a903099.tar.zst
nixpkgs-46773a15b3af302c3fb2a6e31fb589553a903099.zip
nixos/version: fix case where .git is a symlink
Before c9214c394b248e1f26e45dbe1be2bd82363af3a6 and
9d396d2e426b9a765de0b8999aa214f1259633e6 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.
Diffstat (limited to 'nixos')
-rw-r--r--nixos/modules/misc/version.nix5
1 files changed, 3 insertions, 2 deletions
diff --git a/nixos/modules/misc/version.nix b/nixos/modules/misc/version.nix
index ddbd3963cc5..8a85035ceb7 100644
--- a/nixos/modules/misc/version.nix
+++ b/nixos/modules/misc/version.nix
@@ -6,6 +6,7 @@ let
   cfg = config.system.nixos;
 
   gitRepo      = "${toString pkgs.path}/.git";
+  gitRepoValid = lib.pathIsGitRepo gitRepo;
   gitCommitId  = lib.substring 0 7 (commitIdFromGitRepo gitRepo);
 in
 
@@ -91,8 +92,8 @@ in
       # These defaults are set here rather than up there so that
       # changing them would not rebuild the manual
       version = mkDefault (cfg.release + cfg.versionSuffix);
-      revision      = mkIf (pathExists gitRepo) (mkDefault            gitCommitId);
-      versionSuffix = mkIf (pathExists gitRepo) (mkDefault (".git." + gitCommitId));
+      revision      = mkIf gitRepoValid (mkDefault            gitCommitId);
+      versionSuffix = mkIf gitRepoValid (mkDefault (".git." + gitCommitId));
     };
 
     # Generate /etc/os-release.  See