diff --git a/src/fix.cc b/src/fix.cc
index 5c4297bfb760b9209e2b22e256410de3e3ebb278..445d682837ffc6bee2893f6085f1473a258e1785 100644
--- a/src/fix.cc
+++ b/src/fix.cc
@@ -131,7 +131,7 @@ static Expr evalExpr(Expr e)
         string srcPath = searchPath(s1);
         string dstPath;
         Hash hash;
-        addToStore(srcPath, dstPath, hash);
+        addToStore(srcPath, dstPath, hash, true);
         return ATmake("Path(<str>, Hash(<str>), [])",
             dstPath.c_str(), ((string) hash).c_str());
     }
diff --git a/src/store.cc b/src/store.cc
index 435ac5cc69cef9ef33fc4cb0ef555f278f654f13..12de50ec64245f7461c57d4f4b2060acd75e434e 100644
--- a/src/store.cc
+++ b/src/store.cc
@@ -224,24 +224,23 @@ string expandHash(const Hash & hash, const string & target,
 }
 
     
-void addToStore(string srcPath, string & dstPath, Hash & hash)
+void addToStore(string srcPath, string & dstPath, Hash & hash,
+    bool deterministicName)
 {
     srcPath = absPath(srcPath);
-
     hash = hashPath(srcPath);
 
+    string baseName = baseNameOf(srcPath);
+    dstPath = canonPath(nixStore + "/" + (string) hash + "-" + baseName);
+
     try {
         /* !!! should not use the substitutes! */
-        dstPath = expandHash(hash, "", nixStore);
+        dstPath = expandHash(hash, deterministicName ? dstPath : "", nixStore);
         return;
     } catch (...) {
     }
     
-    string baseName = baseNameOf(srcPath);
-    dstPath = canonPath(nixStore + "/" + (string) hash + "-" + baseName);
-
     copyPath(srcPath, dstPath);
-
     registerPath(dstPath, hash);
 }
 
diff --git a/src/store.hh b/src/store.hh
index 8b41478a24af386337832eafb536b8035f052bc8..82fb2e12a1090b763382f05eb21a9e58facc3d17 100644
--- a/src/store.hh
+++ b/src/store.hh
@@ -30,7 +30,8 @@ string expandHash(const Hash & hash, const string & target = "",
 
 /* Copy a file to the nixStore directory and register it in dbRefs.
    Return the hash code of the value. */
-void addToStore(string srcPath, string & dstPath, Hash & hash);
+void addToStore(string srcPath, string & dstPath, Hash & hash,
+    bool deterministicName = false);
 
 /* Delete a value from the nixStore directory. */
 void deleteFromStore(const string & path);