Draft
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implementation Complete ✓
The Motion camera system has been fully implemented and is ready for deployment to the misfit host.
What Was Implemented
Files Created
modules/motion.nix- Main Motion service modulehosts/misfit/motion.nix- Host-specific configurationFiles Modified
hosts/misfit/default.nix- Added module imports../../modules/motion.nix./motion.nixhosts/misfit/jellyfin.nix- Extended activation script/data/Camerasdirectory creation/data/Cameras/recordingssubdirectory/data/Cameras/snapshotssubdirectoryArchitecture Overview
```
┌─────────────────────────────────────────┐
│ Home Assistant (localhost:8123) │
│ - Ready for camera integration │
└─────────────────┬───────────────────────┘
│ HTTP/MJPEG
│ localhost:8080-8081
┌─────────────────▼───────────────────────┐
│ Motion Daemon (systemd service) │
│ - Video capture & encoding │
│ - Motion detection │
│ - MJPEG streaming │
│ - Continuous recording (720p, 15fps) │
└─────────────────┬───────────────────────┘
│
┌─────────────────▼───────────────────────┐
│ Storage: /data/Cameras/ │
│ - recordings/ (7-day retention) │
│ - snapshots/ (motion events) │
│ - motion.log (daemon logs) │
└─────────────────────────────────────────┘
```
Deployment Instructions
Step 1: Deploy to Misfit
From the misfit host, run:
```bash
cd /path/to/nix-home
nixos-rebuild switch --flake '.#misfit' --use-remote-sudo
```
Step 2: Verify Service Status
```bash
Check motion daemon status
systemctl status motion
Check cleanup timer status
systemctl status motion-cleanup.timer
View motion logs
journalctl -u motion -f
```
Step 3: Verify Directory Structure
```bash
Check directories were created
ls -la /data/Cameras/
Verify ownership
Should be: motion:motion
ls -la /data/Cameras/recordings/
ls -la /data/Cameras/snapshots/
```
Step 4: Test Camera Access
```bash
Test web interface (from misfit)
curl http://localhost:8080
Test MJPEG stream (from misfit)
curl http://localhost:8081
```
Step 5: Access from Local Network
From another device on your local network:
```bash
Web interface
http://misfit.local:8080
MJPEG stream
http://misfit.local:8081
```
Configuration Details
Motion Service Options
The service is configured with:
/data/Cameraslocalhost:8080(local only)8081(accessible on local network)Storage Estimates
Security Features
motionsystem usermotionuser added tovideogroupHome Assistant Integration (Optional)
To integrate with Home Assistant, add to
hosts/misfit/configuration.nix:```nix
services.home-assistant = {
enable = true;
... existing config ...
config = {
# ... existing config ...
};
};
```
Then rebuild and restart Home Assistant:
```bash
nixos-rebuild switch --flake '.#misfit'
systemctl restart home-assistant
```
Troubleshooting
Motion Service Won't Start
```bash
Check detailed logs
journalctl -u motion -n 50
Verify video device exists
ls -la /dev/video*
Check if motion user has video group access
groups motion
```
No Video Device Found
If
/dev/video0doesn't exist:dmesg | grep videomodules/motion.nixto use RTSP URL instead of/dev/video0```nix
In motionConfigFile, change:
videodevice rtsp://username:password@camera-ip:554/stream
```
Recordings Not Appearing
```bash
Check permissions
ls -la /data/Cameras/recordings/
Verify motion can write
sudo -u motion touch /data/Cameras/recordings/test.txt
Check disk space
df -h /data
```
Cleanup Not Working
```bash
Check timer status
systemctl status motion-cleanup.timer
Manually trigger cleanup
systemctl start motion-cleanup
Check timer logs
journalctl -u motion-cleanup
```
Advanced Configuration
Multiple Cameras
To add more cameras, edit
modules/motion.nixmotion.conf:```conf
Camera 1
camera /etc/motion/camera1.conf
Camera 2
camera /etc/motion/camera2.conf
```
Create separate config files for each camera with different devices/URLs.
Hardware Acceleration
For better performance with multiple cameras, enable VAAPI:
```nix
In modules/motion.nix motionConfigFile
movie_codec mp4:h264_vaapi
```
Ensure Intel GPU drivers are loaded on misfit.
Public Access (Optional)
To add public HTTPS access via Caddy:
In
modules/caddy.nix, add:```nix
"camera.yuanw.me" = {
useACMEHost = "yuanw.me";
extraConfig = ''
reverse_proxy localhost:8080
basicauth {
admin $2a$14$... # bcrypt hash
}
'';
};
```
Then open firewall port in
hosts/misfit/configuration.nix:```nix
networking.firewall.allowedTCPPorts = [
... existing ports ...
80 443 # for Caddy reverse proxy
];
```
Testing Checklist
systemctl status motionshows activesystemctl status motion-cleanup.timer/data/Cameras/{recordings,snapshots}existmotion:motionowns directoriescurl http://localhost:8080curl http://localhost:8081/data/Cameras/recordings/journalctl -u motionNext Steps
Files Changed Summary
```
modules/motion.nix (new, 182 lines)
hosts/misfit/motion.nix (new, 10 lines)
hosts/misfit/default.nix (modified, +2 lines)
hosts/misfit/jellyfin.nix (modified, +3 lines)
```
Ready to deploy! 🚀