- Rust 100%
nixnfs #
A NFSv3 server that exposes the Nix store as a virtual filesystem.
Instead of requiring store paths to exist locally, nixnfs downloads them on demand from a binary cache (substituter) such as cache.nixos.org when they are first accessed over NFS. Once downloaded, a store path's contents are unpacked into a local cache directory and served like regular files.
This lets any NFS-capable client mount the nix store and transparently access arbitrary derivations without a local Nix installation.
Status #
Work in progress. The downloading, coordination and scanning machinery is
functional and tested, while the NFS frontend (src/fs.rs) is still under
development and not yet wired up as a server binary.
How it works #
NFS client ──NFSv3──> nixnfs
│
├─ downloader fetch .narinfo + NAR from substituter,
│ decompress (bzip2/xz/zstd), unpack
├─ coordinator actor that tracks per-path states
│ (Unknown/Downloading/Available/Unavailable),
│ deduplicates concurrent downloads and
│ hands out refcounted leases
├─ cache actor that answers filename lookups
│ within already-unpacked store paths
└─ scanner walks an unpacked store path and builds
id<->path maps used as NFS fileids
- A client looks up a store path name such as
phjdj95xm103nxhkg0j5sb1806hc8jgg-busybox-1.37.0over NFS. - The coordinator is asked to acquire that path. If it is already available locally, a lease is returned immediately; otherwise a download is started and concurrent requests wait for it to finish.
- The downloader fetches
<hash>.narinfofrom the substituter, downloads the referenced NAR, decompresses it and unpacks it into<cache-dir>/<hash>. - The scanner indexes the unpacked tree, mapping stable u32 fileids to
paths so they can be addressed by NFS file handles
(
nix hash (20 bytes) + fileid (4 bytes)).
Building #
Requires a recent Rust toolchain.
cargo build
Usage #
It provides an example download-nar binary which downloads and unpacks a
single NAR from a binary cache, which is useful for testing:
cargo run --bin download-nar -- \
--nixhash phjdj95xm103nxhkg0j5sb1806hc8jgg \
--output busybox \
[--cache-server https://cache.nixos.org/]
The main NFS server binary is not yet enabled.
Testing #
Unit tests:
cargo test
End-to-end tests that talk to https://cache.nixos.org are behind the e2e
feature:
cargo test --features e2e
License #
MIT. See LICENSE.