Skip to content

Commit 11f2fd4

Browse files
committed
harmonia-file-* crates: async file tree traits, NAR via traits, cap-tokio
Introduces three new crates implementing a generic async file tree abstraction mirroring nix's `SourceAccessor` / `FileSystemObjectSink` architecture (NixOS/nix#15392): **`harmonia-file-core`**: Generic types (`FileTree`, `FileSystemObject`), async traits (`FileSystemSource`, `FileSystemSink`, `DirectorySink`, `RegularFileSink`), in-memory implementation, listing functions, and serde matching `nix nar ls --json`. **`harmonia-file-fd`**: Filesystem `FileSystemSource` (`DirSource`) and `FileSystemSink` (`DirSlotSink`) via `cap-tokio`. Uses `openat`/`fstatat`, mmap for large files. Lazy child thunks — directory handles opened on demand. **`harmonia-file-nar`** (renamed from `harmonia-nar`): NAR dump/restore now goes through `FileSystemSource`/`FileSystemSink` traits via `dump_source` and `restore_to_sink`. The old `walkdir`-based `NarDumper` and direct-IO `NarRestorer` are replaced. `parse_nar_listing` produces `FileTree<NarFileInfo>` from NAR streams. Other changes: - `harmonia-cache/narlist.rs` uses `DirSource` + `list_deep` (async, no `spawn_blocking`) - All harmonia workspace deps use `{ workspace = true }` - Dependency diagram groups `file-*` crates, shows isolated nodes - Architecture docs updated - Uses `cap-tokio` (bytecodealliance/cap-std#414) for async capability-based filesystem access
1 parent 63c464f commit 11f2fd4

29 files changed

Lines changed: 2147 additions & 1224 deletions

Cargo.lock

Lines changed: 132 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ members = [
1313
"harmonia-store-remote",
1414
"harmonia-store-aterm",
1515
"harmonia-file-core",
16+
"harmonia-file-fd",
1617
"harmonia-file-nar",
1718
"harmonia-protocol",
1819
"harmonia-protocol-derive",
@@ -38,8 +39,11 @@ version = "3.1.0"
3839

3940
[workspace.dependencies]
4041
async-stream = "0.3"
41-
bstr = "1.11"
42-
bytes = "1.11"
42+
bstr = "1.11"
43+
bytes = "1.11"
44+
cap-std = "3"
45+
# https://github.com/bytecodealliance/cap-std/pull/414
46+
cap-tokio = { git = "https://github.com/Ericson2314/cap-std.git", branch = "cap-tokio" }
4347
data-encoding = "2.11"
4448
derive_more = { version = "2.1", features = [ "display" ] }
4549
ed25519-dalek = "2"
@@ -92,6 +96,7 @@ tokio-test = "0.4"
9296

9397
# Internal crates
9498
harmonia-file-core = { path = "harmonia-file-core" }
99+
harmonia-file-fd = { path = "harmonia-file-fd" }
95100
harmonia-file-nar = { path = "harmonia-file-nar" }
96101
harmonia-protocol = { path = "harmonia-protocol" }
97102
harmonia-protocol-derive = { path = "harmonia-protocol-derive" }

docs/architecture/harmonia-store-structure.md

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ composed.
2222
┌────────────────────────────┬─────────────────────────┐
2323
│ Format / File │ Database │
2424
│ harmonia-file-nar │ harmonia-store-db │
25-
│ harmonia-file-core │ │
26-
│ NAR pack/unpack, types │ SQLite store metadata │
25+
│ harmonia-file-core/fd │ │
26+
│ NAR pack/unpack, file I/O │ SQLite store metadata │
2727
└────────────────────────────┴─────────────────────────┘
2828
2929
┌──────────────────────────────────────────────────────┐
@@ -49,7 +49,8 @@ composed.
4949
| [harmonia-store-aterm](../../harmonia-store-aterm/) | ATerm derivation parser |
5050
| [harmonia-store-path-info](../../harmonia-store-path-info/) | ValidPathInfo types (pure) |
5151
| [harmonia-store-db](../../harmonia-store-db/README.md) | SQLite store metadata |
52-
| [harmonia-file-core](../../harmonia-file-core/) | File tree types and serde (pure) |
52+
| [harmonia-file-core](../../harmonia-file-core/) | File tree types, traits, listing (pure) |
53+
| [harmonia-file-fd](../../harmonia-file-fd/) | Filesystem source via cap-std |
5354
| [harmonia-file-nar](../../harmonia-file-nar/README.md) | NAR archive format |
5455
| [harmonia-protocol](../../harmonia-protocol/README.md) | Daemon wire protocol |
5556
| [harmonia-protocol-derive](../../harmonia-protocol-derive/README.md) | Derive macros for protocol types |
@@ -86,14 +87,17 @@ graph BT
8687
end
8788
subgraph File
8889
file-core
90+
file-fd
8991
file-nar
9092
end
9193
bench
9294
client
9395
ssh-store
96+
file-fd --> file-core
97+
utils-hash --> utils-base-encoding
9498
file-nar --> file-core
99+
file-nar --> file-fd
95100
file-nar --> utils-io
96-
utils-hash --> utils-base-encoding
97101
store-core --> utils-base-encoding
98102
store-core --> utils-hash
99103
store-aterm --> store-core
@@ -115,6 +119,7 @@ graph BT
115119
store-nar-info --> store-path-info
116120
store-nar-info --> utils-hash
117121
cache --> file-core
122+
cache --> file-fd
118123
cache --> file-nar
119124
cache --> store-core
120125
cache --> store-db
@@ -145,14 +150,16 @@ graph BT
145150
end
146151
subgraph File
147152
file-core
153+
file-fd
148154
file-nar
149155
end
150156
bench
151157
client
152158
ssh-store
153-
file-nar --> file-core
154-
file-nar --> utils-io
159+
file-fd --> file-core
155160
utils-hash --> utils-base-encoding
161+
file-nar --> file-fd
162+
file-nar --> utils-io
156163
store-core --> utils-hash
157164
store-aterm --> store-core
158165
store-build-result --> store-core
@@ -190,8 +197,9 @@ intra-workspace dependencies.
190197
- `harmonia-store-aterm` and `harmonia-store-path-info` would typically be part of `harmonia-store-core`.
191198
However, since these data types / formats both have issues, they are instead placed in separate libraries to make sure they don't "infect" the rest of `harmonia-store-core`.
192199

193-
**File** (`harmonia-file-core`, `harmonia-file-nar`)
194-
- `harmonia-file-core`: pure file tree types and serde matching nix's JSON format.
200+
**File** (`harmonia-file-core`, `harmonia-file-fd`, `harmonia-file-nar`)
201+
- `harmonia-file-core`: pure file tree types, `FileSystemSource`/`FileSystemSink` traits, serde matching nix's JSON format.
202+
- `harmonia-file-fd`: real filesystem source via `cap-std` (openat, no symlink following).
195203
- `harmonia-file-nar`: NAR pack/unpack against generic `AsyncRead`/`AsyncWrite`. Streaming; never requires the full input in memory. Knows nothing about derivations or signatures.
196204

197205
**Database** (`harmonia-store-db`)

harmonia-cache/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,11 @@ zstd = "0.13"
4040
zstd-safe = "7"
4141
# Nix.rs-based crates
4242
bytes = { workspace = true }
43+
cap-tokio = { workspace = true }
4344
futures-core = { workspace = true }
4445
futures-util = { workspace = true }
4546
harmonia-file-core = { workspace = true }
47+
harmonia-file-fd = { workspace = true }
4648
harmonia-file-nar = { workspace = true }
4749
harmonia-store-core = { workspace = true }
4850
harmonia-store-db = { workspace = true }

0 commit comments

Comments
 (0)