diff --git a/configure.ac b/configure.ac
index c6cb782d8f6e37e29a590b7b6a2f771d4f42033c..b8d51916a626822988f22758cfbe496bcc997914 100644
--- a/configure.ac
+++ b/configure.ac
@@ -63,6 +63,11 @@ AC_ARG_WITH(xml-flags, AC_HELP_STRING([--with-xml-flags=FLAGS],
   xmlflags=$withval, xmlflags=)
 AC_SUBST(xmlflags)
 
+AC_ARG_WITH(store-dir, AC_HELP_STRING([--with-store-dir=PATH],
+  [path of the Nix store]),
+  storedir=$withval, storedir='${prefix}/store')
+AC_SUBST(storedir)
+
 AC_CHECK_LIB(pthread, pthread_mutex_init)
 
 AM_CONFIG_HEADER([config.h])
diff --git a/nix.spec.in b/nix.spec.in
index 6fdd93e9f2e9856f321991ac627437ba13db095d..e2537960e23e6730e1b0c680efa90cf16fb593ea 100644
--- a/nix.spec.in
+++ b/nix.spec.in
@@ -24,6 +24,7 @@ make
 %install
 rm -rf $RPM_BUILD_ROOT
 make DESTDIR=$RPM_BUILD_ROOT install
+(cd src/nix-store && make DESTDIR=$RPM_BUILD_ROOT init-state-local)
 strip $RPM_BUILD_ROOT/%{_prefix}/bin/* || true
 
 %clean
diff --git a/src/libmain/Makefile.am b/src/libmain/Makefile.am
index 6d70b0406acc8e25f8b12472d33ee7bcb7cd6903..72126f1135c42116f602792dcc4b139562c62418 100644
--- a/src/libmain/Makefile.am
+++ b/src/libmain/Makefile.am
@@ -3,7 +3,7 @@ noinst_LIBRARIES = libmain.a
 libmain_a_SOURCES = shared.cc shared.hh
 
 AM_CXXFLAGS = \
- -DNIX_STORE_DIR=\"$(prefix)/store\" \
+ -DNIX_STORE_DIR=\"$(storedir)\" \
  -DNIX_DATA_DIR=\"$(datadir)\" \
  -DNIX_STATE_DIR=\"$(localstatedir)/nix\" \
  -DNIX_LOG_DIR=\"$(localstatedir)/log/nix\" \
diff --git a/src/nix-store/Makefile.am b/src/nix-store/Makefile.am
index 3a152e3e4b3d03eec7486d53e6e1cd3bd94ee1ca..76d3a6c6bedc4a1dd1e17ecae22620b52b0c1848 100644
--- a/src/nix-store/Makefile.am
+++ b/src/nix-store/Makefile.am
@@ -12,7 +12,7 @@ main.o: help.txt.hh
 AM_CXXFLAGS = \
  -I.. -I../../externals/inst/include -I../libutil -I../libstore -I../libmain
 
-install-data-local:
+init-state-local:
 	$(INSTALL) -d $(DESTDIR)$(localstatedir)/nix
 	$(INSTALL) -d $(DESTDIR)$(localstatedir)/nix/db
 	$(INSTALL) -d $(DESTDIR)$(localstatedir)/log/nix