diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc
index d7cd0b088d98622bf998a7124a12bfbe076db0e4..9199b12063a0d8bc245cb327202a288cccbdcb1f 100644
--- a/src/libstore/local-store.cc
+++ b/src/libstore/local-store.cc
@@ -602,10 +602,10 @@ static void canonicalisePathMetaData_(const Path & path, uid_t fromUid, InodesSe
        users group); we check for this case below. */
     if (st.st_uid != geteuid()) {
 #if HAVE_LCHOWN
-        if (lchown(path.c_str(), geteuid(), (gid_t) -1) == -1)
+        if (lchown(path.c_str(), geteuid(), getegid()) == -1)
 #else
         if (!S_ISLNK(st.st_mode) &&
-            chown(path.c_str(), geteuid(), (gid_t) -1) == -1)
+            chown(path.c_str(), geteuid(), getegid()) == -1)
 #endif
             throw SysError(format("changing owner of ‘%1%’ to %2%")
                 % path % geteuid());