/cfg: config option for persistent storage of sysrepo's data

Change-Id: Ie29c1488f32b1739d2e6a197041de1883f848fe0
diff --git a/board/czechlight/common/overlay/usr/lib/systemd/system/multi-user.target.wants/sysrepo-persistent-cfg.service b/board/czechlight/common/overlay/usr/lib/systemd/system/multi-user.target.wants/sysrepo-persistent-cfg.service
deleted file mode 120000
index 810aa4b..0000000
--- a/board/czechlight/common/overlay/usr/lib/systemd/system/multi-user.target.wants/sysrepo-persistent-cfg.service
+++ /dev/null
@@ -1 +0,0 @@
-../sysrepo-persistent-cfg.service
\ No newline at end of file
diff --git a/configs/czechlight_clearfog_defconfig b/configs/czechlight_clearfog_defconfig
index ce20748..9d0c85e 100644
--- a/configs/czechlight_clearfog_defconfig
+++ b/configs/czechlight_clearfog_defconfig
@@ -68,6 +68,7 @@
 BR2_PACKAGE_HOST_GENIMAGE=y
 BR2_PACKAGE_HOST_MTOOLS=y
 CZECHLIGHT_CFG_FS_SIZE="256M"
+CZECHLIGHT_CFG_FS_PERSIST_SYSREPO=y
 CZECHLIGHT_RAUC_ROOTFS=y
 CZECHLIGHT_RAUC_COMPATIBLE="czechlight-clearfog"
 CZECHLIGHT_RAUC_SLOT_A_ROOTFS_DEV="/dev/mmcblk0p1"
diff --git a/package/czechlight-cfg-fs/Config.in b/package/czechlight-cfg-fs/Config.in
index d44d14a..3974d6c 100644
--- a/package/czechlight-cfg-fs/Config.in
+++ b/package/czechlight-cfg-fs/Config.in
@@ -17,4 +17,14 @@
 	  accommodate all configuration, but small enough to fit within the
 	  corresponding partition.
 
+if BR2_PACKAGE_SYSREPO
+
+config CZECHLIGHT_CFG_FS_PERSIST_SYSREPO
+	bool "Persist sysrepo configuration into /cfg"
+	default Y
+	help
+	  Save sysrepo's YANG files into /cfg upon changes
+
+endif # BR2_PACKAGE_SYSREPO
+
 endif # BR2_PACKAGE_CZECHLIGHT_CFG_FS
diff --git a/package/czechlight-cfg-fs/czechlight-cfg-fs.mk b/package/czechlight-cfg-fs/czechlight-cfg-fs.mk
index 6798e68..9f28965 100644
--- a/package/czechlight-cfg-fs/czechlight-cfg-fs.mk
+++ b/package/czechlight-cfg-fs/czechlight-cfg-fs.mk
@@ -24,6 +24,12 @@
 		$(BR2_EXTERNAL_CZECHLIGHT_PATH)/package/czechlight-cfg-fs/cfg-restore-etc.service \
 		$(TARGET_DIR)/usr/lib/systemd/system/cfg-restore-etc.service
 	ln -sf ../cfg-restore-etc.service $(TARGET_DIR)/usr/lib/systemd/system/local-fs.target.wants/
+	$(ifeq ($(CZECHLIGHT_CFG_FS_PERSIST_SYSREPO),y))
+		$(INSTALL) -D -m 0644 \
+			$(BR2_EXTERNAL_CZECHLIGHT_PATH)/package/czechlight-cfg-fs/sysrepo-persistent-cfg.service \
+			$(TARGET_DIR)/usr/lib/systemd/system/
+		ln -sf ../sysrepo-persistent-cfg.service $(TARGET_DIR)/usr/lib/systemd/system/multi-user.target.wants/
+	$(endif)
 endef
 
 $(eval $(generic-package))
diff --git a/board/czechlight/common/overlay/usr/lib/systemd/system/sysrepo-persistent-cfg.service b/package/czechlight-cfg-fs/sysrepo-persistent-cfg.service
similarity index 100%
rename from board/czechlight/common/overlay/usr/lib/systemd/system/sysrepo-persistent-cfg.service
rename to package/czechlight-cfg-fs/sysrepo-persistent-cfg.service