Refactor Nix package definition and enhance README for lidarr-mb-gap

- Updated `flake.nix` to import the new Nix package definition from `nix/package.nix`, streamlining the build process for the lidarr-mb-gap application.
- Enhanced the README.md to include new features such as NixOS module support for automated deployment, detailed deployment instructions, and configuration options for SSH and output directories.
- Added sections for troubleshooting output file issues and clarified the structure of the project, including new files for deployment and web serving.
This commit is contained in:
Danilo Reyes
2025-11-11 11:11:47 -06:00
parent e6f96107aa
commit a6d2e7f7df
5 changed files with 216 additions and 21 deletions

View File

@@ -34,6 +34,13 @@ Add the module to your NixOS configuration. You have two options:
syncToVPS = true;
vpsHost = "user@vps"; # Your SSH host alias
vpsPath = "/var/www/html";
sshKeyFile = "/var/lib/lidarr-mb-gap/.ssh/id_ed25519";
sshKnownHosts = {
vps = {
hostNames = [ "vps" "vps.example.com" ];
publicKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI..."; # Get from ssh-keyscan
};
};
};
}
```
@@ -62,6 +69,18 @@ Add the module to your NixOS configuration. You have two options:
services.lidarr-mb-gap.reportDir = "/var/lib/lidarr-mb-gap/reports";
services.lidarr-mb-gap.envFile = "/var/lib/lidarr-mb-gap/.env";
services.lidarr-mb-gap.runInterval = "daily";
# Optional: SSH configuration for VPS sync
services.lidarr-mb-gap.syncToVPS = true;
services.lidarr-mb-gap.vpsHost = "user@vps";
services.lidarr-mb-gap.vpsPath = "/var/www/html";
services.lidarr-mb-gap.sshKeyFile = "/var/lib/lidarr-mb-gap/.ssh/id_ed25519";
services.lidarr-mb-gap.sshKnownHosts = {
vps = {
hostNames = [ "vps" "vps.example.com" ];
publicKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI...";
};
};
}
./configuration.nix
];
@@ -100,20 +119,96 @@ sudo chmod 600 /var/lib/lidarr-mb-gap/.env
### 3. Configure SSH for rsync (if using auto-sync)
If you enabled `syncToVPS`, set up SSH key authentication:
If you enabled `syncToVPS`, you need to set up SSH key authentication for the `lidarr-mb-gap` user.
#### Step 1: Generate SSH Key Pair
```bash
# On the server
ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519_lidarr
ssh-copy-id -i ~/.ssh/id_ed25519_lidarr.pub user@vps
# Generate a dedicated SSH key for the service
sudo -u lidarr-mb-gap ssh-keygen -t ed25519 -f /var/lib/lidarr-mb-gap/.ssh/id_ed25519 -N ""
# Add to ~/.ssh/config
Host vps
HostName your-vps-ip-or-domain
User your-username
IdentityFile ~/.ssh/id_ed25519_lidarr
# Or generate as your user and copy it
ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519_lidarr -N ""
sudo mkdir -p /var/lib/lidarr-mb-gap/.ssh
sudo cp ~/.ssh/id_ed25519_lidarr /var/lib/lidarr-mb-gap/.ssh/id_ed25519
sudo cp ~/.ssh/id_ed25519_lidarr.pub /var/lib/lidarr-mb-gap/.ssh/id_ed25519.pub
sudo chown -R lidarr-mb-gap:lidarr-mb-gap /var/lib/lidarr-mb-gap/.ssh
sudo chmod 600 /var/lib/lidarr-mb-gap/.ssh/id_ed25519
sudo chmod 644 /var/lib/lidarr-mb-gap/.ssh/id_ed25519.pub
```
#### Step 2: Add Public Key to VPS
```bash
# Copy the public key to your VPS
sudo -u lidarr-mb-gap cat /var/lib/lidarr-mb-gap/.ssh/id_ed25519.pub | ssh user@vps "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"
# Or manually:
# 1. Display the public key:
sudo -u lidarr-mb-gap cat /var/lib/lidarr-mb-gap/.ssh/id_ed25519.pub
# 2. On your VPS, add it to ~/.ssh/authorized_keys (or the target user's authorized_keys)
```
#### Step 3: Get VPS Host Key (for known_hosts)
```bash
# Get the VPS host key fingerprint
ssh-keyscan -t ed25519 your-vps-hostname-or-ip
# This will output something like:
# your-vps-hostname ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI...
```
#### Step 4: Configure in NixOS
Add SSH configuration to your NixOS config:
```nix
services.lidarr-mb-gap = {
enable = true;
# ... other options ...
syncToVPS = true;
vpsHost = "user@vps-hostname"; # or "user@vps.example.com"
vpsPath = "/var/www/html";
# Path to SSH private key (optional, defaults to ~/.ssh/id_ed25519)
sshKeyFile = "/var/lib/lidarr-mb-gap/.ssh/id_ed25519";
# SSH known hosts (prevents host key verification prompts)
sshKnownHosts = {
vps = {
hostNames = [ "vps-hostname" "vps.example.com" "1.2.3.4" ]; # All possible hostnames/IPs
publicKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI..."; # From ssh-keyscan output
};
};
};
```
**Alternative: Manual Setup (if not using NixOS config)**
If you prefer to set up SSH keys manually without NixOS configuration:
```bash
# The service will use default SSH key location: /var/lib/lidarr-mb-gap/.ssh/id_ed25519
# Just ensure the key exists and is properly configured
```
#### Step 5: Test SSH Connection
Before enabling the service, test that SSH works:
```bash
# Test SSH connection as the service user
sudo -u lidarr-mb-gap ssh -i /var/lib/lidarr-mb-gap/.ssh/id_ed25519 user@vps "echo 'SSH connection successful'"
# Or if using default key location:
sudo -u lidarr-mb-gap ssh user@vps "echo 'SSH connection successful'"
```
If this works, rsync should work too. If you get host key verification errors, make sure you've configured `sshKnownHosts` in your NixOS config.
### 4. Build and Switch
```bash