upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/docs/how-to
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2025-11-04 10:25:53 +0000
committerDanConwayDev <DanConwayDev@protonmail.com>2025-11-04 10:25:53 +0000
commit52bad9954cdddf55ab749fd0c6387edbc766632f (patch)
treed9dd2078b70a627a71d1adb9555cee83faec5cd0 /docs/how-to
parentdb460efdd4cf34d3b6ac8c19b1b8f89f22bc279f (diff)
docs: use Diátaxis structure
Diffstat (limited to 'docs/how-to')
-rw-r--r--docs/how-to/README.md177
-rw-r--r--docs/how-to/nix-flakes.md412
2 files changed, 589 insertions, 0 deletions
diff --git a/docs/how-to/README.md b/docs/how-to/README.md
new file mode 100644
index 0000000..ed5f014
--- /dev/null
+++ b/docs/how-to/README.md
@@ -0,0 +1,177 @@
1# How-To Guides
2
3**Task-oriented documentation** - Practical solutions to common problems.
4
5---
6
7## What Are How-To Guides?
8
9How-to guides are **recipes** that show you how to solve specific problems or accomplish particular tasks.
10
11**Characteristics:**
12- ✅ Task-oriented (solve a problem)
13- ✅ Practical (actionable steps)
14- ✅ Assume basic knowledge
15- ✅ Focus on results
16- ✅ Can be followed in any order
17
18**Not how-to guides:**
19- ❌ Complete lessons for beginners (those are Tutorials)
20- ❌ Technical specifications (those are Reference)
21- ❌ Conceptual discussions (those are Explanation)
22
23---
24
25## Available How-To Guides
26
27### [Configure Nix Flakes](nix-flakes.md)
28**Problem:** Set up reproducible development environment
29**Difficulty:** Intermediate
30
31**You'll learn:**
32- Enable Nix flakes
33- Enter development environment
34- Work with subprojects
35- Troubleshoot common issues
36
37---
38
39## Planned How-To Guides
40
41### Deploy ngit-grasp
42**Status:** 🔜 Planned (waiting for main server)
43
44**Problem:** Deploy to production
45**You'll learn:**
46- Server requirements
47- Reverse proxy setup (nginx/Caddy)
48- SSL/TLS configuration
49- Monitoring and logging
50
51---
52
53### Run Compliance Tests
54**Status:** 🔜 Planned
55
56**Problem:** Test GRASP compliance
57**You'll learn:**
58- Set up test relay
59- Run integration tests
60- Interpret results
61- Add custom tests
62
63---
64
65### Upgrade nostr-sdk
66**Status:** 🔜 Planned
67
68**Problem:** Handle breaking changes in nostr-sdk
69**You'll learn:**
70- Check for breaking changes
71- Update dependencies
72- Fix compilation errors
73- Test after upgrade
74
75---
76
77### Configure Authentication
78**Status:** 🔜 Planned (feature not yet implemented)
79
80**Problem:** Secure your relay
81**You'll learn:**
82- Enable authentication
83- Configure allowed users
84- Set up rate limiting
85- Monitor access
86
87---
88
89### Backup and Restore
90**Status:** 🔜 Planned
91
92**Problem:** Protect your data
93**You'll learn:**
94- Backup Git repositories
95- Backup Nostr events
96- Restore from backup
97- Automate backups
98
99---
100
101### Migrate from ngit-relay
102**Status:** 🔜 Planned
103
104**Problem:** Switch from reference implementation
105**You'll learn:**
106- Export data from ngit-relay
107- Import to ngit-grasp
108- Update repository URLs
109- Verify migration
110
111---
112
113## How to Use How-To Guides
114
1151. **Find your problem** - Browse or search for what you need
1162. **Check prerequisites** - Make sure you have required knowledge
1173. **Follow the steps** - Adapt to your specific situation
1184. **Solve and move on** - No need to read everything
119
120**Not sure if this is what you need?**
121- New to ngit-grasp? → [Tutorials](../tutorials/)
122- Looking for technical details? → [Reference](../reference/)
123- Want to understand why? → [Explanation](../explanation/)
124
125---
126
127## Contributing How-To Guides
128
129When writing a how-to guide:
130
131**DO:**
132- ✅ Start with the problem/goal
133- ✅ List prerequisites clearly
134- ✅ Provide concrete steps
135- ✅ Include troubleshooting
136- ✅ Show examples
137- ✅ Link to related docs
138
139**DON'T:**
140- ❌ Teach basics (link to Tutorials)
141- ❌ Explain every concept (link to Explanation)
142- ❌ List all options (link to Reference)
143- ❌ Make it a tutorial (stay focused on the task)
144
145**Template:**
146```markdown
147# How-To: [Task/Problem]
148
149**Problem:** [What you're trying to accomplish]
150**Difficulty:** [Beginner/Intermediate/Advanced]
151**Time:** [Estimated time]
152
153## Prerequisites
154- [Required knowledge/tools]
155
156## Solution
157
158### Step 1: [Action]
159[Instructions]
160
161### Step 2: [Action]
162[Instructions]
163
164## Troubleshooting
165
166### [Common problem]
167**Solution:** [How to fix]
168
169## Related Documentation
170- [Links to relevant docs]
171```
172
173See [Diátaxis: How-To Guides](https://diataxis.fr/how-to-guides/) for detailed guidance.
174
175---
176
177*Part of the [ngit-grasp documentation](../README.md) using the [Diátaxis](https://diataxis.fr/) framework.*
diff --git a/docs/how-to/nix-flakes.md b/docs/how-to/nix-flakes.md
new file mode 100644
index 0000000..4242368
--- /dev/null
+++ b/docs/how-to/nix-flakes.md
@@ -0,0 +1,412 @@
1# How-To: Configure Nix Flakes for Development
2
3**Purpose:** Set up and use Nix flakes for ngit-grasp development
4**Difficulty:** Intermediate
5**Time:** 10 minutes
6
7---
8
9## Problem
10
11You want to:
12- Set up a reproducible development environment
13- Avoid "works on my machine" issues
14- Use Nix flakes with ngit-grasp
15
16---
17
18## Prerequisites
19
20- Nix installed (2.4 or later)
21- Flakes enabled in your Nix configuration
22
23---
24
25## Solution
26
27### Step 1: Enable Flakes (if not already enabled)
28
29Check if flakes are enabled:
30
31```bash
32nix flake --version
33```
34
35If you get an error, enable flakes:
36
37```bash
38# Add to ~/.config/nix/nix.conf (create if doesn't exist)
39mkdir -p ~/.config/nix
40echo "experimental-features = nix-command flakes" >> ~/.config/nix/nix.conf
41
42# Or for system-wide (requires sudo):
43echo "experimental-features = nix-command flakes" | sudo tee -a /etc/nix/nix.conf
44```
45
46Restart the Nix daemon:
47
48```bash
49# On NixOS:
50sudo systemctl restart nix-daemon
51
52# On macOS:
53sudo launchctl stop org.nixos.nix-daemon
54sudo launchctl start org.nixos.nix-daemon
55
56# On other Linux:
57sudo pkill nix-daemon
58```
59
60---
61
62### Step 2: Enter the Development Environment
63
64```bash
65cd ngit-grasp
66nix develop
67```
68
69**What this does:**
70- Reads `flake.nix` in the current directory
71- Downloads and builds all dependencies
72- Creates a shell with Rust, Git, and other tools
73- Sets environment variables
74
75**First run:** Will take several minutes to download and build
76**Subsequent runs:** Should be instant (cached)
77
78---
79
80### Step 3: Verify the Environment
81
82```bash
83# Check Rust is available
84rustc --version
85cargo --version
86
87# Check Git is available
88git --version
89
90# Check you're in the Nix shell
91echo $IN_NIX_SHELL # Should output "impure"
92```
93
94---
95
96### Step 4: Work with Subprojects
97
98ngit-grasp has a subproject (`grasp-audit`) with its own flake:
99
100```bash
101# Main project
102cd ngit-grasp
103nix develop # Uses ngit-grasp/flake.nix
104
105# Subproject
106cd grasp-audit
107nix develop # Uses grasp-audit/flake.nix
108```
109
110**Important:** Each directory has its own flake and environment!
111
112---
113
114## Common Tasks
115
116### Build the Project
117
118```bash
119cd grasp-audit
120nix develop
121cargo build
122```
123
124**Or in one command:**
125
126```bash
127cd grasp-audit
128nix develop -c cargo build
129```
130
131The `-c` flag runs a command in the Nix environment and exits.
132
133---
134
135### Run Tests
136
137```bash
138cd grasp-audit
139nix develop -c cargo test
140```
141
142---
143
144### Build Without Entering Shell
145
146```bash
147cd grasp-audit
148nix build
149```
150
151This builds the package defined in `flake.nix` outputs.
152
153---
154
155### Update Dependencies
156
157```bash
158# Update flake.lock (updates all inputs)
159nix flake update
160
161# Update specific input
162nix flake lock --update-input nixpkgs
163```
164
165**When to update:**
166- Security vulnerabilities in dependencies
167- Need newer version of Rust or other tools
168- Monthly maintenance
169
170---
171
172### Clean Nix Store
173
174```bash
175# Remove unused packages
176nix-collect-garbage
177
178# Aggressive cleanup (removes all old generations)
179nix-collect-garbage -d
180```
181
182**Warning:** This will remove all old versions. You'll need to re-download if you switch branches.
183
184---
185
186## Troubleshooting
187
188### "nix: command not found"
189
190**Problem:** Nix is not installed or not in PATH
191
192**Solution:**
193```bash
194# Install Nix (official installer)
195sh <(curl -L https://nixos.org/nix/install) --daemon
196
197# Add to PATH (if needed)
198source ~/.nix-profile/etc/profile.d/nix.sh
199```
200
201---
202
203### "experimental features not enabled"
204
205**Problem:** Flakes are not enabled
206
207**Solution:**
208```bash
209# Add to ~/.config/nix/nix.conf
210echo "experimental-features = nix-command flakes" >> ~/.config/nix/nix.conf
211
212# Restart Nix daemon (see Step 1)
213```
214
215---
216
217### "nix-shell: command not found" or wrong behavior
218
219**Problem:** Using old `nix-shell` command instead of `nix develop`
220
221**Solution:**
222```bash
223# ❌ Wrong (old Nix)
224nix-shell
225
226# ✅ Correct (Nix flakes)
227nix develop
228```
229
230**Why:** Flakes use `nix develop`, not `nix-shell`. The old command looks for `shell.nix` which doesn't exist.
231
232---
233
234### "error: getting status of '/nix/store/...': No such file or directory"
235
236**Problem:** Nix store is corrupted or incomplete
237
238**Solution:**
239```bash
240# Verify Nix store
241nix-store --verify --check-contents
242
243# Repair if needed
244nix-store --repair --verify --check-contents
245
246# If still broken, re-enter environment
247nix develop --refresh
248```
249
250---
251
252### Build fails with "cannot find crate"
253
254**Problem:** Cargo cache is stale or corrupted
255
256**Solution:**
257```bash
258# Clean Cargo cache
259cargo clean
260
261# Rebuild
262nix develop -c cargo build
263```
264
265---
266
267### "error: unable to download"
268
269**Problem:** Network issues or cache server down
270
271**Solution:**
272```bash
273# Use different substituter
274nix develop --option substituters "https://cache.nixos.org"
275
276# Or build from source (slow)
277nix develop --no-substitutes
278```
279
280---
281
282## Advanced Usage
283
284### Use direnv for Automatic Activation
285
286Install [direnv](https://direnv.net/) to automatically enter Nix environment:
287
288```bash
289# Install direnv
290nix-env -iA nixpkgs.direnv
291
292# Create .envrc
293echo "use flake" > .envrc
294
295# Allow direnv
296direnv allow
297
298# Now cd into directory automatically activates environment!
299cd ngit-grasp # Automatically runs 'nix develop'
300```
301
302---
303
304### Customize the Environment
305
306Edit `flake.nix` to add packages:
307
308```nix
309{
310 devShells.default = pkgs.mkShell {
311 buildInputs = with pkgs; [
312 # Existing packages
313 cargo
314 rustc
315
316 # Add your packages here
317 jq # JSON processor
318 ripgrep # Fast grep
319 fd # Fast find
320 ];
321 };
322}
323```
324
325Then reload:
326
327```bash
328nix develop --refresh
329```
330
331---
332
333### Pin to Specific Rust Version
334
335Edit `flake.nix`:
336
337```nix
338{
339 inputs.rust-overlay.url = "github:oxalica/rust-overlay";
340
341 outputs = { self, nixpkgs, rust-overlay }:
342 let
343 pkgs = import nixpkgs {
344 overlays = [ rust-overlay.overlays.default ];
345 };
346
347 # Pin to specific version
348 rust = pkgs.rust-bin.stable."1.75.0".default;
349 in {
350 devShells.default = pkgs.mkShell {
351 buildInputs = [ rust ];
352 };
353 };
354}
355```
356
357---
358
359## Best Practices
360
361### DO:
362- ✅ Use `nix develop` for flakes (not `nix-shell`)
363- ✅ Commit `flake.lock` to version control
364- ✅ Update flakes monthly
365- ✅ Use `-c` flag for one-off commands
366- ✅ Use direnv for automatic activation
367
368### DON'T:
369- ❌ Use `nix-shell` with flakes
370- ❌ Manually edit `flake.lock`
371- ❌ Ignore flake update warnings
372- ❌ Mix Nix and non-Nix environments
373- ❌ Commit `.direnv/` to git
374
375---
376
377## Quick Reference
378
379```bash
380# Enter environment
381nix develop
382
383# Run command in environment
384nix develop -c cargo build
385
386# Build package
387nix build
388
389# Update dependencies
390nix flake update
391
392# Show flake info
393nix flake show
394
395# Check flake
396nix flake check
397
398# Clean up
399nix-collect-garbage
400```
401
402---
403
404## Related Documentation
405
406- [Getting Started Tutorial](../tutorials/getting-started.md) - First-time setup
407- [Nix Flakes Manual](https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-flake.html)
408- [grasp-audit README](../../grasp-audit/README.md) - Subproject docs
409
410---
411
412*Part of the [ngit-grasp how-to guides](./)*