diff --git a/configure.ac b/configure.ac
index 57861063de4326a3e8b0e61167d3a0c44f5773cf..4dea89c95b690092f290a9127f93272873b6f8b2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -11,6 +11,8 @@ AC_PROG_CC
 AC_PROG_CXX
 AC_PROG_RANLIB
 
+AC_PATH_PROG(wget, wget)
+
 AC_CHECK_LIB(pthread, pthread_mutex_init)
 
 AM_CONFIG_HEADER([config.h])
diff --git a/corepkgs/fetchurl/fetchurl.sh b/corepkgs/fetchurl/fetchurl.sh.in
similarity index 65%
rename from corepkgs/fetchurl/fetchurl.sh
rename to corepkgs/fetchurl/fetchurl.sh.in
index 7b6243974d3f637206699ae543e28a74d93e3eaf..dc92c7ee50d83e582174a77a63dd637fe2841c0e 100644
--- a/corepkgs/fetchurl/fetchurl.sh
+++ b/corepkgs/fetchurl/fetchurl.sh.in
@@ -1,9 +1,9 @@
 #! /bin/sh
 
 echo "downloading $url into $out..."
-wget "$url" -O "$out" || exit 1
+@wget@ "$url" -O "$out" || exit 1
 
-actual=$(md5sum -b $out | cut -c1-32)
+actual=$(@bindir@/nix-hash --flat $out)
 if ! test "$actual" == "$md5"; then
     echo "hash is $actual, expected $md5"
     exit 1
diff --git a/substitute.mk b/substitute.mk
index af3549253ca9a322c1bde23fb8fef4d5584a623c..8527cf6fd1ee9bd5d109ae493122a0ed9b64b944 100644
--- a/substitute.mk
+++ b/substitute.mk
@@ -4,5 +4,6 @@
 	 -e s^@bindir\@^$(bindir)^g \
 	 -e s^@sysconfdir\@^$(sysconfdir)^g \
 	 -e s^@localstatedir\@^$(localstatedir)^g \
+	 -e s^@wget\@^$(wget)^g \
 	 < $< > $@ || rm $@
 	chmod +x $@