|
| 1 | +# Nix Development Environment & Cachix Setup |
| 2 | + |
| 3 | +This document explains how to set up and maintain the Nix development environment for PeerSwap, including Cachix binary cache configuration. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +PeerSwap uses Nix flakes for reproducible development environments and Cachix for fast binary caching. This setup provides: |
| 8 | +- Deterministic build environments across all platforms |
| 9 | +- Fast CI/CD builds through binary caching |
| 10 | +- Consistent developer experience |
| 11 | + |
| 12 | +## Quick Start for Developers |
| 13 | + |
| 14 | +### Prerequisites |
| 15 | + |
| 16 | +1. **Install Nix** (if not already installed): |
| 17 | +```bash |
| 18 | +# Multi-user installation (recommended) |
| 19 | +curl -L https://nixos.org/nix/install | sh -s -- --daemon |
| 20 | + |
| 21 | +# Enable flakes |
| 22 | +mkdir -p ~/.config/nix |
| 23 | +echo "experimental-features = nix-command flakes" >> ~/.config/nix/nix.conf |
| 24 | +``` |
| 25 | +2. **Install direnv** (optional but recommended): |
| 26 | +```bash |
| 27 | +# On macOS |
| 28 | +brew install direnv |
| 29 | + |
| 30 | +# On Linux |
| 31 | +curl -sfL https://direnv.net/install.sh | bash |
| 32 | + |
| 33 | +# Add to shell profile |
| 34 | +echo 'eval "$(direnv hook bash)"' >> ~/.bashrc # or ~/.zshrc |
| 35 | +``` |
| 36 | + |
| 37 | +### Development Environment |
| 38 | +```bash |
| 39 | +git clone https://github.com/YusukeShimizu/peerswap.git |
| 40 | +cd peerswap |
| 41 | + |
| 42 | +# With direnv (automatic) |
| 43 | +direnv allow |
| 44 | + |
| 45 | +# Without direnv (manual) |
| 46 | +nix develop |
| 47 | +``` |
| 48 | +### Binary Cache (Cachix) |
| 49 | + |
| 50 | +The project automatically uses the `peerswap` Cachix cache for faster builds. If you don't have Cachix installed: |
| 51 | + |
| 52 | +```bash |
| 53 | +# Install Cachix |
| 54 | +nix profile install nixpkgs#cachix |
| 55 | + |
| 56 | +# Use the cache (done automatically by .envrc) |
| 57 | +cachix use peerswap |
| 58 | +``` |
| 59 | + |
| 60 | +## Maintainer Setup Guide |
| 61 | + |
| 62 | +### 1. Cachix Cache Creation |
| 63 | + |
| 64 | +1. **Create Cachix account**: |
| 65 | + - Visit https://app.cachix.org/ |
| 66 | + - Sign up with GitHub account |
| 67 | + - Verify email address |
| 68 | + |
| 69 | +2. **Access existing cache**: |
| 70 | + - The cache `peerswap` already exists at https://app.cachix.org/cache/peerswap |
| 71 | + - Ensure you have admin access to this cache |
| 72 | + - If you don't have access, contact the cache owner |
| 73 | + |
| 74 | +### 2. Authentication Token |
| 75 | + |
| 76 | +1. **Generate token**: |
| 77 | + - Go to cache dashboard → `peerswap` (https://app.cachix.org/cache/peerswap) |
| 78 | + - Navigate to "Auth tokens" tab |
| 79 | + - Click "Generate token" |
| 80 | + - Select permissions: **Push** (required for CI) |
| 81 | + - Copy the generated token |
| 82 | + |
| 83 | +2. **Add GitHub repository secret**: |
| 84 | + - Go to GitHub repository: Settings → Secrets and variables → Actions |
| 85 | + - Click "New repository secret" |
| 86 | + - Name: `CACHIX_AUTH_TOKEN` |
| 87 | + - Value: Paste the token from step 1 |
| 88 | + - Click "Add secret" |
| 89 | + |
| 90 | +### 3. Local Cache Push |
| 91 | + |
| 92 | +To push from local development to the cache: |
| 93 | + |
| 94 | +```bash |
| 95 | +# Create a profile and push to cache |
| 96 | +nix develop --profile dev-profile |
| 97 | +cachix push peerswap dev-profile |
| 98 | +``` |
| 99 | + |
| 100 | +## How It Works |
| 101 | + |
| 102 | +### Local Development |
| 103 | + |
| 104 | +The `.envrc` file automatically configures Cachix: |
| 105 | + |
| 106 | +```bash |
| 107 | +use flake |
| 108 | + |
| 109 | +# Setup Cachix for development |
| 110 | +if command -v cachix >/dev/null 2>&1; then |
| 111 | + cachix use peerswap |
| 112 | +fi |
| 113 | +``` |
| 114 | + |
| 115 | +## References |
| 116 | + |
| 117 | +- [Nix Flakes](https://nixos.wiki/wiki/Flakes) |
| 118 | +- [Cachix Documentation](https://docs.cachix.org/) |
| 119 | +- [GitHub Actions + Nix](https://nix.dev/guides/recipes/continuous-integration-github-actions) |
0 commit comments