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:
@@ -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
|
||||
|
||||
@@ -3,6 +3,17 @@
|
||||
let
|
||||
reportDir = "/var/lib/lidarr-mb-gap/reports";
|
||||
envFile = "/var/lib/lidarr-mb-gap/.env";
|
||||
|
||||
# Determine which package to use
|
||||
lidarrMbGapPackage = if config.services.lidarr-mb-gap.package != null
|
||||
then config.services.lidarr-mb-gap.package
|
||||
else if config.services.lidarr-mb-gap.src != null
|
||||
then import ../nix/package.nix {
|
||||
inherit pkgs;
|
||||
lib = pkgs.lib;
|
||||
src = config.services.lidarr-mb-gap.src;
|
||||
}
|
||||
else throw "services.lidarr-mb-gap: Either 'package' or 'src' must be set.";
|
||||
in
|
||||
{
|
||||
options.services.lidarr-mb-gap = {
|
||||
@@ -55,11 +66,35 @@ in
|
||||
default = "/var/www/html";
|
||||
description = "Path on VPS where reports should be synced";
|
||||
};
|
||||
|
||||
sshKeyFile = lib.mkOption {
|
||||
type = lib.types.nullOr lib.types.str;
|
||||
default = null;
|
||||
description = "Path to SSH private key file for rsync. If null, uses default SSH key location.";
|
||||
};
|
||||
|
||||
sshKnownHosts = lib.mkOption {
|
||||
type = lib.types.attrsOf (lib.types.submodule {
|
||||
options = {
|
||||
hostNames = lib.mkOption {
|
||||
type = lib.types.listOf lib.types.str;
|
||||
description = "List of hostnames/IPs for this known host";
|
||||
};
|
||||
publicKey = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
description = "SSH public key for the host";
|
||||
};
|
||||
};
|
||||
});
|
||||
default = {};
|
||||
description = "SSH known hosts configuration for the VPS (same format as programs.ssh.knownHosts)";
|
||||
};
|
||||
};
|
||||
|
||||
config = lib.mkIf config.services.lidarr-mb-gap.enable {
|
||||
systemd.tmpfiles.rules = [
|
||||
"d ${config.services.lidarr-mb-gap.reportDir} 0755 lidarr-mb-gap lidarr-mb-gap -"
|
||||
"d /var/lib/lidarr-mb-gap/.ssh 0700 lidarr-mb-gap lidarr-mb-gap -"
|
||||
];
|
||||
|
||||
users.users.lidarr-mb-gap = {
|
||||
@@ -70,6 +105,8 @@ in
|
||||
};
|
||||
|
||||
users.groups.lidarr-mb-gap = {};
|
||||
|
||||
programs.ssh.knownHosts = config.services.lidarr-mb-gap.sshKnownHosts;
|
||||
|
||||
systemd.services.lidarr-mb-gap = {
|
||||
description = "Generate Lidarr MusicBrainz Gap Report";
|
||||
@@ -96,7 +133,15 @@ in
|
||||
|
||||
# Sync to VPS if enabled
|
||||
${lib.optionalString (config.services.lidarr-mb-gap.syncToVPS && config.services.lidarr-mb-gap.vpsHost != null) ''
|
||||
# Set up SSH options
|
||||
SSH_OPTS=""
|
||||
${lib.optionalString (config.services.lidarr-mb-gap.sshKeyFile != null) ''
|
||||
SSH_OPTS="-i ${config.services.lidarr-mb-gap.sshKeyFile}"
|
||||
''}
|
||||
|
||||
# Use SSH options with rsync
|
||||
${pkgs.rsync}/bin/rsync -avz --delete \
|
||||
-e "ssh $SSH_OPTS -o StrictHostKeyChecking=yes" \
|
||||
${config.services.lidarr-mb-gap.reportDir}/ \
|
||||
${config.services.lidarr-mb-gap.vpsHost}:${config.services.lidarr-mb-gap.vpsPath}/
|
||||
''}
|
||||
|
||||
Reference in New Issue
Block a user