modify from https://github.com/NixOS/nixpkgs/pull/262462
diff --git a/common/flatpak-run.c b/common/flatpak-run.c
index 94ad013..5c9f55e 100644
--- a/common/flatpak-run.c
+++ b/common/flatpak-run.c
@@ -871,6 +871,49 @@ out:
return res;
}
+static void
+get_gnu_closure (GHashTable *closure, const gchar *source_path)
+{
+ if (g_file_test (source_path, G_FILE_TEST_IS_SYMLINK))
+ {
+ g_autofree gchar *path = g_malloc(PATH_MAX);
+ realpath(source_path, path);
+ if (g_str_has_prefix(path, "/gnu/store/"))
+ {
+ *strchr(path + strlen("/gnu/store/"), '/') = 0;
+ g_hash_table_add(closure, g_steal_pointer (&path));
+ }
+ }
+ else if (g_file_test (source_path, G_FILE_TEST_IS_DIR))
+ {
+ g_autoptr(GDir) dir = g_dir_open(source_path, 0, NULL);
+ const gchar *file_name;
+ while ((file_name = g_dir_read_name(dir)))
+ {
+ g_autofree gchar *path = g_build_filename (source_path, file_name, NULL);
+ get_gnu_closure (closure, path);
+ }
+ }
+}
+
+static void
+add_gnu_store_symlink_targets (FlatpakBwrap *bwrap, const gchar *source_path)
+{
+ GHashTable *closure = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
+
+ get_gnu_closure(closure, source_path);
+
+ GHashTableIter iter;
+ gpointer path;
+ g_hash_table_iter_init(&iter, closure);
+ while (g_hash_table_iter_next(&iter, &path, NULL))
+ {
+ flatpak_bwrap_add_args (bwrap, "--ro-bind", path, path, NULL);
+ }
+
+ g_hash_table_destroy(closure);
+}
+
static void
add_font_path_args (FlatpakBwrap *bwrap)
{
@@ -898,6 +946,18 @@ add_font_path_args (FlatpakBwrap *bwrap)
"\t