Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

fix: restore write permission on export directory after copytree on Nix (#10041)

Wally6027d82ea97b
diff --git a/marimo/_server/export/exporter.py b/marimo/_server/export/exporter.py
index ce18001843..8395ebec50 100644
--- a/marimo/_server/export/exporter.py
+++ b/marimo/_server/export/exporter.py
@@ -736,13 +736,21 @@ class Exporter:
dirpath.mkdir(parents=True, exist_ok=True)
import shutil
+ import stat
shutil.copytree(
ROOT,
dirpath,
dirs_exist_ok=True,
+ copy_function=shutil.copyfile,
ignore=(shutil.ignore_patterns("index.html")),
)
+ # copytree calls copystat() on directories, which may copy read-only permissions from the source (e.g., /nix/store).
+ # Restore the write bit so marimo can create additional files.
+ dirpath.chmod(dirpath.stat().st_mode | stat.S_IWUSR)
+ assets_dir = dirpath / "assets"
+ if assets_dir.is_dir():
+ assets_dir.chmod(assets_dir.stat().st_mode | stat.S_IWUSR)
def export_public_folder(
self, directory: Path, marimo_file: MarimoPath
diff --git a/tests/_server/export/test_exporter.py b/tests/_server/export/test_exporter.py
index 9c68905b43..d31e5e6e6f 100644
--- a/tests/_server/export/test_exporter.py
+++ b/tests/_server/export/test_exporter.py
@@ -2229,3 +2229,38 @@ class TestPDFExport:
sys.modules["playwright.async_api"] = orig_playwright
else:
sys.modules.pop("playwright.async_api", None)
+
+
+ sys.platform == "win32",
+ reason="Unix permission bits not supported on Windows",
+)
+def test_export_assets_preserves_write_permission(
+ tmp_path: Path,
+) -> None:
+ """Test export_assets keeps output writable when source is read-only."""
+ import stat
+
+ src = tmp_path / "nix-store" / "_static"
+ src.mkdir(parents=True)
+ (src / "file.txt").write_text("hello")
+ sub = src / "assets"
+ sub.mkdir()
+ (sub / "nested.txt").write_text("marimo")
+
+ # 555 simulates /nix/store permissions
+ src.chmod(0o555)
+ sub.chmod(0o555)
+
+ dest = tmp_path / "output"
+ dest.mkdir()
+
+ with patch("marimo._server.export.exporter.ROOT", src):
+ Exporter().export_assets(dest)
+
+ assert dest.stat().st_mode & stat.S_IWUSR, (
+ "export_assets made the output directory read-only"
+ )
+ assert (dest / "assets").stat().st_mode & stat.S_IWUSR, (
+ "export_assets made the assets subdirectory read-only"
+ )