attic
repository·main·Indexed 24 days ago
https://github.com/zhaofengli/atticA self-hostable Nix Binary Cache server backed by S3-compatible storage. It features multi-tenancy, global deduplication, and managed signing. The project includes a client CLI (attic), a daemon CLI (atticd), an administrative CLI (atticadm), and high-level Rust bindings to libnixstore for interacting with Nix stores using async/await semantics.
What's inside attic
- Attic is a self-hostable Nix Binary Cache server that uses S3-compatible storage. It is designed to provide a scalable, multi-tenant Nix cache with features like global deduplication and managed signing. It is suitable for both single-machine setups and serverless deployments (e.g., fly.io).
What is Attic
mainAttic is a self-hostable Nix Binary Cache server designed to work with S3-compatible storage providers. It provides a way to host Nix store paths with features like global deduplication and garbage collection. It is designed for scalability, supporting both single-machine setups and deployment to serverless platforms like fly.io.Access Attic CLI, daemon, and admin CLI references
mainThe Attic project provides three primary command-line interfaces for interaction. Detailed documentation for each is available in their respective reference files:
atticCLI: The main client interface for interacting with the Attic service.atticdCLI: The command-line interface for managing the Attic daemon.atticadmCLI: The administrative CLI for performing administrative tasks.
Understand the NAR chunking and compression pipeline
mainUploaded NARs follow a specific pipeline on the server: they are chunked, then compressed, and finally streamed to the storage backend (e.g., S3).
Crucially, global deduplication at the chunk level is performed using the hash of the uncompressed chunk.
Data Flow Diagram:
┌───────────────────────────────────►Chunk Hash │ ├───────────────────────────────────►Chunk Size │ ┌───────┴────┐ ┌──────────┐ ┌───────────┐ Chunk Stream──►│Chunk Hasher├─►│Compressor├─►│File Hasher├─►File Stream─►S3 └────────────┘ └──────────┘ └─────┬─────┘ │ ├───────►File Hash │ └───────►File SizeUnderstand Attic authentication via JWTs
mainAuthentication in Attic is handled using signed JSON Web Tokens (JWTs) that contain the allowed permissions. Each instance ofatticd --mode api-serveris designed to be stateless.How chunking works in Attic
mainAttic uses the FastCDC algorithm to split uploaded NARs (Nix Archive files) into smaller chunks. This process enables data deduplication by identifying and storing unique segments of data across different archives.
Chunking behavior is controlled by four primary parameters that determine when a file is chunked and the size characteristics of the resulting chunks. Note that changing these parameters will change the 'cutpoints' (the boundaries where chunks are split), which means existing chunks cannot be easily reused for new NARs, temporarily reducing the deduplication ratio.
Core features of Attic
mainAttic provides several key capabilities for managing Nix binary caches:
- Multi-Tenancy: Supports creating isolated private caches for different users or groups. Tenants are mutually untrusting and cannot access or pollute each other's views.
- Global Deduplication: Uses a content-addressed NAR Store and Chunk Store. Individual tenant caches act as restricted views of this global store; uploading a path creates a mapping to the global NAR.
- Managed Signing: The server performs signing on-the-fly when store paths are fetched. This ensures that users pushing paths do not need access to the private signing keys.
- Scalability: Designed for easy replication and deployment to serverless platforms.
- Garbage Collection: Supports LRU (Least Recently Used) garbage collection to remove unused store paths.
How deduplication and chunking work in Attic
mainAttic performs global deduplication at two levels: NAR files and chunks.
- NAR-level deduplication: If an identical NAR exists in the Global NAR Store, chunking is skipped and the NAR is directly deduplicated.
- Chunk-level deduplication: If the NAR is new, it is split into chunks using the FastCDC algorithm. Identical chunks are stored only once in the storage backend.
Key behaviors:
- Chunking threshold: Data chunking is optional and can be disabled for NARs smaller than a specific threshold. When disabled, the NAR is uploaded as a single chunk, but NAR-level deduplication still applies.
- Reassembly: During a download,
atticdreassembles the entire NAR from its constituent chunks by streaming them from the storage backend. - Chunking Strategy: Attic chunks the entire uncompressed NAR file rather than individual constituent files. This allows for larger average chunk sizes and more efficient handling of NARs containing many small files (e.g., VSCode or Zoom).
Quickstart: Spin up Attic
mainYou can set up a running instance of Attic in approximately 15 minutes. Detailed instructions are available in the official tutorial.
Visit the Attic Tutorial to begin the setup process. Attic is compatible with macOS.
Quickstart: Spin up Attic in 15 minutes
mainTo quickly set up a local development environment, use
nix shellto get the Attic binaries and runatticdin monolithic mode. This configuration uses a SQLite database and local storage.- Install Attic via Nix:
nix shell github:zhaofengli/attic- Start the server:
atticdWhen you run
atticd, it will output a configuration path (usually~/.config/attic/server.toml) and a root login command containing a JWT token. Copy this token to log in via theatticclient.nix shell github:zhaofengli/attic atticdLog in to an Attic server
mainTo authenticate the
atticclient with a server, use theattic logincommand provided by your administrator. The command follows this format:attic login <server-name> <url> <token>The client supports multiple servers simultaneously. You can reference a specific cache using either its name (if the server is set as the default) or the
server:cachesyntax.To set a specific server as the default, update the
default-serverkey in~/.config/attic/config.toml.attic login central https://attic.domain.tld/ eyJ...Configure Access Control with atticadm tokens
mainAttic uses stateless JWT tokens for authentication. You can use
atticadmto generate tokens with specific permissions for users.Restricted Access Token
To create a token that only allows a user to pull and push to a specific cache:
atticadm make-token --sub <username> --validity '<duration>' --pull <cache_name> --push <cache_name>Pattern-based Access Token
To allow a user to create and manage their own caches using a prefix (e.g.,
alice-*), use the--create-cacheflag:atticadm make-token --sub <username> --validity '<duration>' --pull '<prefix>*' --push '<prefix>*' --create-cache '<prefix>*'Use the
--dump-claimsflag to inspect the JWT claims in plain text without encoding the token.