fix: replace Cachix with Magic Nix Cache in CI workflow

- Use DeterminateSystems/nix-installer-action for Nix installation
- Use DeterminateSystems/magic-nix-cache-action for caching (free, no setup)
- Update documentation to remove Cachix references
- Add nix branch to CI triggers
This commit is contained in:
Arunavo Ray
2025-12-17 10:30:07 +05:30
parent 9968775210
commit 3993d679e6
5 changed files with 86 additions and 132 deletions

View File

@@ -1,15 +1,16 @@
name: Nix Build and Cache name: Nix Build
permissions:
contents: read
on: on:
push: push:
branches: [main] branches: [main, nix]
tags: tags:
- 'v*' - 'v*'
pull_request: pull_request:
branches: [main] branches: [main]
permissions:
contents: read
jobs: jobs:
build: build:
strategy: strategy:
@@ -20,24 +21,28 @@ jobs:
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- uses: cachix/install-nix-action@v24 - name: Install Nix
with: uses: DeterminateSystems/nix-installer-action@main
extra_nix_config: |
experimental-features = nix-command flakes
- uses: cachix/cachix-action@v12 - name: Setup Nix Cache
with: uses: DeterminateSystems/magic-nix-cache-action@main
name: gitea-mirror # Your cache name
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
- name: Build package
run: nix build --print-build-logs
- name: Check flake - name: Check flake
run: nix flake check run: nix flake check
- name: Test run (dry run) - name: Build package
run: nix build --print-build-logs
- name: Verify binary
run: | run: |
# Just verify the binary exists and is executable # Verify the binary exists and is executable
test -x ./result/bin/gitea-mirror test -x ./result/bin/gitea-mirror
./result/bin/gitea-mirror --version || echo "Version check skipped" echo "✅ Binary exists and is executable"
# Show package info
ls -la ./result/bin/
- name: Test --help flag
run: |
# Test that the binary can at least show help/version info
./result/bin/gitea-mirror --version 2>&1 || echo "Note: --version may not be implemented"

View File

@@ -1,6 +1,6 @@
# Nix Distribution - Ready to Use! 🎉 # Nix Distribution - Ready to Use!
## Current Status: WORKS NOW ## Current Status: WORKS NOW
Your Nix package is **already distributable**! Users can run it directly from GitHub without any additional setup on your end. Your Nix package is **already distributable**! Users can run it directly from GitHub without any additional setup on your end.
@@ -31,32 +31,14 @@ That's it! No releases, no CI, no infrastructure needed. It works right now.
### For Basic Usage: **NO** ### For Basic Usage: **NO**
Users can already use it from GitHub. No CI or releases required. Users can already use it from GitHub. No CI or releases required.
### For Better UX: **Recommended** ### For CI Validation: **Already Set Up**
Set up binary caching so users don't compile from source. GitHub Actions validates builds on every push with Magic Nix Cache (free, no setup).
--- ---
## Next Steps (Optional but Recommended) ## Next Steps (Optional)
### Option 1: Add Binary Cache (5 minutes) ### Option 1: Release Versioning (2 minutes)
**Why:** Users download pre-built binaries instead of compiling (much faster!)
**How:**
1. Create free account at https://cachix.org/
2. Create cache named `gitea-mirror`
3. Add GitHub secret: `CACHIX_AUTH_TOKEN`
4. GitHub Actions workflow already created at `.github/workflows/nix-build.yml`
5. Add to your docs:
```bash
# Users run once
cachix use gitea-mirror
# Then they get fast binary downloads
nix run github:RayLabsHQ/gitea-mirror
```
### Option 2: Release Versioning (2 minutes)
**Why:** Users can pin to specific versions **Why:** Users can pin to specific versions
@@ -72,7 +54,7 @@ nix run github:RayLabsHQ/gitea-mirror/v3.8.11
No additional CI needed - tags work automatically with flakes! No additional CI needed - tags work automatically with flakes!
### Option 3: Submit to nixpkgs (Long Term) ### Option 2: Submit to nixpkgs (Long Term)
**Why:** Maximum discoverability and trust **Why:** Maximum discoverability and trust
@@ -85,21 +67,21 @@ No additional CI needed - tags work automatically with flakes!
## Files Created ## Files Created
### Essential (Already Working) ### Essential (Already Working)
- ✅ `flake.nix` - Package definition - `flake.nix` - Package definition
- ✅ `flake.lock` - Dependency lock file - `flake.lock` - Dependency lock file
- ✅ `.envrc` - direnv integration - `.envrc` - direnv integration
### Documentation ### Documentation
- ✅ `NIX.md` - Quick reference for users - `NIX.md` - Quick reference for users
- ✅ `docs/NIX_DEPLOYMENT.md` - Complete deployment guide - `docs/NIX_DEPLOYMENT.md` - Complete deployment guide
- ✅ `docs/NIX_DISTRIBUTION.md` - Distribution guide for you (maintainer) - `docs/NIX_DISTRIBUTION.md` - Distribution guide for you (maintainer)
- ✅ `README.md` - Updated with Nix instructions - `README.md` - Updated with Nix instructions
### CI (Optional, Already Set Up) ### CI (Already Set Up)
- ✅ `.github/workflows/nix-build.yml` - Builds + caches to Cachix - `.github/workflows/nix-build.yml` - Builds and validates on Linux + macOS
### Updated ### Updated
- ✅ `.gitignore` - Added Nix artifacts - `.gitignore` - Added Nix artifacts
--- ---
@@ -107,12 +89,11 @@ No additional CI needed - tags work automatically with flakes!
| Setup | Time | User Experience | What You Need | | Setup | Time | User Experience | What You Need |
|-------|------|----------------|---------------| |-------|------|----------------|---------------|
| **Direct GitHub** | 0 min | Slow (build from source) | Nothing! Works now | | **Direct GitHub** | 0 min | Slow (build from source) | Nothing! Works now |
| **+ Cachix** | 5 min | Fast (binary download) | Cachix account + token |
| **+ Git Tags** | 2 min | Versionable | Just push tags | | **+ Git Tags** | 2 min | Versionable | Just push tags |
| **+ nixpkgs** | Hours | Official/Trusted | PR review process | | **+ nixpkgs** | Hours | Official/Trusted | PR review process |
**Recommendation:** Start with Direct GitHub (already works!), add Cachix this week for better UX. **Recommendation:** Direct GitHub works now. Add git tags for versioning. Consider nixpkgs submission once stable.
--- ---
@@ -175,17 +156,12 @@ Users can always use latest from main: `nix run github:RayLabsHQ/gitea-mirror`
## Summary ## Summary
**✅ Ready to distribute RIGHT NOW** **Ready to distribute RIGHT NOW**
- Just commit and push your `flake.nix` - Just commit and push your `flake.nix`
- Users can run directly from GitHub - Users can run directly from GitHub
- No CI, releases, or infrastructure required - CI validates builds automatically
**🚀 Recommended next: Add Cachix (5 minutes)** **Optional: Submit to nixpkgs**
- Much better user experience
- Workflow already created
- Free for public projects
**📦 Optional later: Submit to nixpkgs**
- Maximum discoverability - Maximum discoverability
- Official Nix repository - Official Nix repository
- Do this once package is stable - Do this once package is stable

2
NIX.md
View File

@@ -172,7 +172,7 @@ services.gitea-mirror = {
- **[docs/NIX_DISTRIBUTION.md](docs/NIX_DISTRIBUTION.md)** - Distribution guide for maintainers - **[docs/NIX_DISTRIBUTION.md](docs/NIX_DISTRIBUTION.md)** - Distribution guide for maintainers
- How users consume the package - How users consume the package
- Setting up binary cache (Cachix) - CI build caching
- Releasing new versions - Releasing new versions
- Submitting to nixpkgs - Submitting to nixpkgs

View File

@@ -449,31 +449,34 @@ To migrate from Docker to Nix while keeping your data:
## CI/CD Integration ## CI/CD Integration
Example GitHub Actions workflow: Example GitHub Actions workflow (see `.github/workflows/nix-build.yml`):
```yaml ```yaml
name: Build with Nix name: Nix Build
on: [push, pull_request] on: [push, pull_request]
permissions:
contents: read
jobs: jobs:
build: build:
runs-on: ubuntu-latest strategy:
matrix:
os: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- uses: cachix/install-nix-action@v24 - uses: DeterminateSystems/nix-installer-action@main
with: - uses: DeterminateSystems/magic-nix-cache-action@main
extra_nix_config: |
experimental-features = nix-command flakes
- uses: cachix/cachix-action@v12
with:
name: gitea-mirror
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
- run: nix build
- run: nix flake check - run: nix flake check
# Note: GitHub Actions runner usually has flakes enabled by install-nix-action - run: nix build --print-build-logs
``` ```
This uses:
- **Determinate Nix Installer** - Fast, reliable Nix installation with flakes enabled by default
- **Magic Nix Cache** - Free caching using GitHub Actions cache (no account needed)
## Resources ## Resources
- [Nix Manual](https://nixos.org/manual/nix/stable/) - [Nix Manual](https://nixos.org/manual/nix/stable/)

View File

@@ -36,39 +36,21 @@ nix run github:RayLabsHQ/gitea-mirror/v3.8.11
--- ---
### Method 2: Binary Cache (Recommended) ### Method 2: CI Build Caching
Pre-build packages and cache them so users download binaries instead of building: The GitHub Actions workflow uses **Magic Nix Cache** (by Determinate Systems) to cache builds:
#### Setup: Cachix (Free for Public Projects) - **Zero configuration required** - no accounts or tokens needed
- **Automatic** - CI workflow handles everything
- **Uses GitHub Actions cache** - fast, reliable, free
1. **Create account:** https://cachix.org/ #### How It Works:
2. **Create cache:** `gitea-mirror` (public)
3. **Add secret to GitHub:** `Settings → Secrets → CACHIX_AUTH_TOKEN`
4. **GitHub Actions builds automatically** (see `.github/workflows/nix-build.yml`)
#### User Experience: 1. GitHub Actions builds the package on each push/PR
2. Build artifacts are cached in GitHub Actions cache
3. Subsequent builds reuse cached dependencies (faster CI)
```bash Note: This caches CI builds. Users still build locally, but the flake.lock ensures reproducibility.
# First time: Configure cache
cachix use gitea-mirror
# Or add to nix.conf:
# substituters = https://cache.nixos.org https://gitea-mirror.cachix.org
# trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= gitea-mirror.cachix.org-1:YOUR_KEY_HERE
# Then use normally - downloads pre-built binaries!
nix run github:RayLabsHQ/gitea-mirror
```
**Pros:**
- Fast installation (no compilation)
- Reduced bandwidth/CPU for users
- Professional experience
**Cons:**
- Requires Cachix account (free for public)
- Requires CI setup
--- ---
@@ -115,14 +97,13 @@ Already working! Users can:
nix run github:RayLabsHQ/gitea-mirror nix run github:RayLabsHQ/gitea-mirror
``` ```
### Phase 2: Binary Cache (Recommended Next) ### Phase 2: CI Build Validation ✅
Set up Cachix for faster installs: GitHub Actions workflow validates builds on every push/PR:
1. Create Cachix cache - Uses Magic Nix Cache for fast CI builds
2. Add `CACHIX_AUTH_TOKEN` secret to GitHub - Tests on both Linux and macOS
3. Workflow already created in `.github/workflows/nix-build.yml` - No setup required - works automatically
4. Add instructions to docs
### Phase 3: Version Releases (Optional) ### Phase 3: Version Releases (Optional)
@@ -158,17 +139,7 @@ nix run --extra-experimental-features 'nix-command flakes' github:RayLabsHQ/gite
nix profile install --extra-experimental-features 'nix-command flakes' github:RayLabsHQ/gitea-mirror nix profile install --extra-experimental-features 'nix-command flakes' github:RayLabsHQ/gitea-mirror
``` ```
#### Option 2: With Binary Cache (Faster) #### Option 2: Pin to Specific Version
```bash
# One-time setup
cachix use gitea-mirror
# Then install (downloads pre-built binary)
nix profile install github:RayLabsHQ/gitea-mirror
```
#### Option 3: Pin to Specific Version
```bash ```bash
# Pin to git tag # Pin to git tag
@@ -181,7 +152,7 @@ nix run github:RayLabsHQ/gitea-mirror/abc123def
inputs.gitea-mirror.url = "github:RayLabsHQ/gitea-mirror/v3.8.11"; inputs.gitea-mirror.url = "github:RayLabsHQ/gitea-mirror/v3.8.11";
``` ```
#### Option 4: NixOS Configuration #### Option 3: NixOS Configuration
```nix ```nix
{ {
@@ -270,11 +241,11 @@ git push
2. **Test locally:** `nix flake check` 2. **Test locally:** `nix flake check`
3. **Check flake.lock:** May need update if dependencies changed 3. **Check flake.lock:** May need update if dependencies changed
### Cachix Not Working ### CI Cache Not Working
1. **Verify cache exists:** https://gitea-mirror.cachix.org 1. **Check workflow logs:** Review GitHub Actions for errors
2. **Check GitHub secret:** `CACHIX_AUTH_TOKEN` is set 2. **Clear cache:** GitHub Actions → Caches → Delete relevant cache
3. **Review workflow logs:** Ensure build + push succeeded 3. **Verify flake.lock:** May need `nix flake update` if dependencies changed
### Version Pinning Not Working ### Version Pinning Not Working
@@ -336,17 +307,16 @@ trusted-public-keys = YOUR_KEY
| Method | Setup Time | User Speed | Cost | Discoverability | | Method | Setup Time | User Speed | Cost | Discoverability |
|--------|-----------|------------|------|-----------------| |--------|-----------|------------|------|-----------------|
| Direct GitHub | 0 min | Slow (build) | Free | Low | | Direct GitHub | 0 min | Slow (build) | Free | Low |
| Cachix | 5 min | Fast (binary) | Free (public) | Medium |
| nixpkgs | Hours/days | Fast (binary) | Free | High | | nixpkgs | Hours/days | Fast (binary) | Free | High |
| Self-hosted | 30+ min | Fast (binary) | Server cost | Low | | Self-hosted cache | 30+ min | Fast (binary) | Server cost | Low |
**Recommendation:** Start with **Direct GitHub** (works now), add **Cachix** for better UX (5 min), consider **nixpkgs** later for maximum reach. **Current approach:** Direct GitHub consumption with CI validation using Magic Nix Cache. Users build locally (reproducible via flake.lock). Consider **nixpkgs** submission for maximum reach once the package is mature.
--- ---
## Resources ## Resources
- [Nix Flakes Documentation](https://nixos.wiki/wiki/Flakes) - [Nix Flakes Documentation](https://nixos.wiki/wiki/Flakes)
- [Cachix Documentation](https://docs.cachix.org/) - [Magic Nix Cache](https://github.com/DeterminateSystems/magic-nix-cache-action)
- [nixpkgs Contributing Guide](https://github.com/NixOS/nixpkgs/blob/master/CONTRIBUTING.md) - [nixpkgs Contributing Guide](https://github.com/NixOS/nixpkgs/blob/master/CONTRIBUTING.md)
- [Nix Binary Cache Setup](https://nixos.org/manual/nix/stable/package-management/binary-cache-substituter.html) - [Nix Binary Cache Setup](https://nixos.org/manual/nix/stable/package-management/binary-cache-substituter.html)