diff --git a/compile_fw b/compile_fw
index 2a2fc820aaaf9ebbb2e8a5d216eacfb079d8d323..958c70e9e25c1c4b69f4cf0041018bbb27298f53 100755
--- a/compile_fw
+++ b/compile_fw
@@ -397,7 +397,7 @@ gen_lists() {
 	_report "Generating package lists for updater"
 	[ -n "${TARGET_BOARD}" ] || _die "You need to specify target board!"
 	mkdir -p bin/packages/lists
-	"${SRC_DIR}"/helpers/generate_userlists.sh --model "${TARGET_BOARD}" --branch "${PUBLISH_BRANCH}" --src "${SRC_DIR}" bin/packages/lists
+	"${SRC_DIR}"/helpers/generate_userlists.sh --model "${TARGET_BOARD}" --branch "${PUBLISH_BRANCH}" --src "${SRC_DIR}/lists" bin/packages/lists
 }
 
 build_help="	Builds everything"
diff --git a/helpers/generate_userlists.sh b/helpers/generate_userlists.sh
index 965dd32973547fbebf893fc6c065e9ce2c4d6937..dab5f16e2c85082db21309965e18c41750c9bccb 100755
--- a/helpers/generate_userlists.sh
+++ b/helpers/generate_userlists.sh
@@ -2,7 +2,8 @@
 set -e
 
 MINIMAL=false
-SRC_DIR="$(pwd)"
+LISTS_DIR=
+OUTPUT_PATH=
 while [ $# -gt 0 ]; do
 	case "$1" in
 		-h|--help)
@@ -13,12 +14,12 @@ while [ $# -gt 0 ]; do
 			echo "  --help, -h"
 			echo "    Prints this help text."
 			echo "  --model (turris|omnia|mox)"
-			echo "    Target Turris model. Currently only turris or omnia are supported."
+			echo "    Target Turris model."
 			echo "  --branch BRANCH"
 			echo "    Target branch for which this userlist is generated."
 			echo "  --minimal"
 			echo "    Generate userlists for minimal branch. (This adds nightly as a fallback branch)"
-			echo "  --src"
+			echo "  --src PATH"
 			echo "    Source directory with list to process"
 			exit
 			;;
@@ -39,10 +40,15 @@ while [ $# -gt 0 ]; do
 			;;
 		--src)
 			shift
-			SRC_DIR="$(cd "$1"; pwd)"
+			LISTS_DIR="$1"
 			;;
 		*)
-			OUTPUT_PATH="$1"
+			if [ -z "$OUTPUT_PATH" ]; then
+				OUTPUT_PATH="$1"
+			else
+				echo "Unknown option: $1"
+				exit 1
+			fi
 			;;
 	esac
 	shift
@@ -52,7 +58,6 @@ done
 	echo "You have to specify output path." >&2
 	exit 1
 }
-OUTPUT_PATH="$(cd "$OUTPUT_PATH"; pwd)"
 [ -z "$BOARD" ] && {
 	echo "Missing --model option." >&2
 	exit 1
@@ -61,24 +66,23 @@ OUTPUT_PATH="$(cd "$OUTPUT_PATH"; pwd)"
 	echo "Missing --branch option." >&2
 	exit 1
 }
-[ -d "$SRC_DIR" ] || {
-	echo "$0 have to be run in Turris OS root directory." >&2
+[ -d "$LISTS_DIR" ] || {
+	echo "Valid --src directory has to be specified" >&2
+	exit 1
+}
+[ -f Makefile -a -f feeds.conf ] || {
+	echo "This script has to be run in OpenWRT build directory" >&2
 	exit 1
 }
 
 mkdir -p $OUTPUT_PATH
 
-M4ARGS="--include=lists -D _INCLUDE_=lists/ -D _BRANCH_=$BRANCH -D _BOARD_=$BOARD"
+M4ARGS="--include=$LISTS_DIR -D _INCLUDE_=$LISTS_DIR/ -D _BRANCH_=$BRANCH -D _BOARD_=$BOARD"
 $MINIMAL && M4ARGS="$M4ARGS -D _BRANCH_FALLBACK_=nightly"
 
-sed -i 's|subdirs = {"base"[^}]*}|subdirs = {"core" , "base" '"$(
-	cat "$SRC_DIR"/feeds.conf | sed 's|#.*||' | grep '.' | sed 's|src-git \([^[:blank:]]*\) .*|, "\1"|' | tr '\n' ' '
-)}|" "$SRC_DIR/lists/repository.m4"
-
-cd "$SRC_DIR"
-for f in $(find lists -name '*.lua.m4'); do
-	m4 $M4ARGS $f > "$OUTPUT_PATH/$(basename $f | sed s/\.m4$//)"
+for f in $(find "$LISTS_DIR" -name '*.lua.m4'); do
+	m4 $M4ARGS $f > "$OUTPUT_PATH/$(basename "$f" | sed s/\.m4$//)"
 done
-for f in $(find lists -name '*.lua'); do
-	cp $f "$OUTPUT_PATH/$(basename $f)"
+for f in $(find "$LISTS_DIR" -name '*.lua'); do
+	cp $f "$OUTPUT_PATH/$(basename "$f")"
 done
diff --git a/lists/repository.m4 b/lists/repository.m4
index 38386f6bad25127ce553f7e004e1efba0eca589a..02967e7d0decd90783d4dd2c3ab79972585d5265 100644
--- a/lists/repository.m4
+++ b/lists/repository.m4
@@ -3,8 +3,7 @@ dnl We expect this to be include in base.lua just after utils.m4
 divert(-1)
 
 # This is definition of subrepositories
-# TODO generate this dynamically from feed.conf.default
-pushdef(`SUBDIRS',``subdirs = {"base", "turrispackages", "php", "hardware", "lucics", "packages", "routing", "management", "telephony", "printing"}'')
+pushdef(`SUBDIRS',`subdirs = {"base", "core" esyscmd(`awk "/src-git/{printf \", \\\"%s\\\"\", \$'`2}" feeds.conf')}')
 
 divert(0)dnl
 dnl