Compare commits

...

2 Commits

Author SHA1 Message Date
Danilo Reyes
0b86143646 Refactor lidarr-mb-gap NixOS module to use configurable home directory
- Introduced a `home` option for the lidarr-mb-gap service, allowing users to specify a custom home directory.
- Updated paths for `reportDir`, `envFile`, and `sshKeyFile` to be relative to the new `home` option, enhancing flexibility and maintainability.
- Adjusted systemd tmpfiles rules and user home directory settings to align with the new configuration structure.
2025-11-11 16:49:59 -06:00
Danilo Reyes
578b9d316a Add vpsPort option to lidarr-mb-gap NixOS module
- Introduced a new configuration option `vpsPort` to specify the SSH port for VPS connections, defaulting to 22.
- Updated the rsync command to utilize the new `vpsPort` option for improved flexibility in SSH configurations.
2025-11-11 16:46:28 -06:00

View File

@@ -6,8 +6,7 @@
}: }:
let let
reportDir = "/var/lib/lidarr-mb-gap/reports"; defaultHome = "/var/lib/lidarr-mb-gap";
envFile = "/var/lib/lidarr-mb-gap/.env";
# Determine which package to use # Determine which package to use
lidarrMbGapPackage = lidarrMbGapPackage =
@@ -25,6 +24,12 @@ in
options.services.lidarr-mb-gap = { options.services.lidarr-mb-gap = {
enable = lib.mkEnableOption "Lidarr MusicBrainz Gap Reporter"; enable = lib.mkEnableOption "Lidarr MusicBrainz Gap Reporter";
home = lib.mkOption {
type = lib.types.str;
default = defaultHome;
description = "Home directory for the lidarr-mb-gap user";
};
package = lib.mkOption { package = lib.mkOption {
type = lib.types.nullOr lib.types.package; type = lib.types.nullOr lib.types.package;
default = null; default = null;
@@ -39,13 +44,15 @@ in
reportDir = lib.mkOption { reportDir = lib.mkOption {
type = lib.types.str; type = lib.types.str;
default = reportDir; default = "${config.services.lidarr-mb-gap.home}/reports";
defaultText = lib.literalExpression ''"''${home}/reports"'';
description = "Directory where reports will be generated"; description = "Directory where reports will be generated";
}; };
envFile = lib.mkOption { envFile = lib.mkOption {
type = lib.types.str; type = lib.types.str;
default = envFile; default = "${config.services.lidarr-mb-gap.home}/.env";
defaultText = lib.literalExpression ''"''${home}/.env"'';
description = "Path to .env file with LIDARR_URL and LIDARR_API_KEY"; description = "Path to .env file with LIDARR_URL and LIDARR_API_KEY";
}; };
@@ -72,11 +79,18 @@ in
default = "/var/www/html"; default = "/var/www/html";
description = "Path on VPS where reports should be synced"; description = "Path on VPS where reports should be synced";
}; };
vpsPort = lib.mkOption {
type = lib.types.port;
default = 22;
description = "SSH port for VPS connection";
};
sshKeyFile = lib.mkOption { sshKeyFile = lib.mkOption {
type = lib.types.nullOr lib.types.str; type = lib.types.str;
default = null; default = "${config.services.lidarr-mb-gap.home}/.ssh/id_ed25519";
description = "Path to SSH private key file for rsync. If null, uses default SSH key location."; defaultText = lib.literalExpression ''"''${home}/.ssh/id_ed25519"'';
description = "Path to SSH private key file for rsync";
}; };
sshKnownHosts = lib.mkOption { sshKnownHosts = lib.mkOption {
@@ -102,13 +116,13 @@ in
config = lib.mkIf config.services.lidarr-mb-gap.enable { config = lib.mkIf config.services.lidarr-mb-gap.enable {
systemd.tmpfiles.rules = [ systemd.tmpfiles.rules = [
"d ${config.services.lidarr-mb-gap.reportDir} 0755 lidarr-mb-gap lidarr-mb-gap -" "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 -" "d ${config.services.lidarr-mb-gap.home}/.ssh 0700 lidarr-mb-gap lidarr-mb-gap -"
]; ];
users.users.lidarr-mb-gap = { users.users.lidarr-mb-gap = {
isSystemUser = true; isSystemUser = true;
group = "lidarr-mb-gap"; group = "lidarr-mb-gap";
home = "/var/lib/lidarr-mb-gap"; home = config.services.lidarr-mb-gap.home;
createHome = true; createHome = true;
}; };
@@ -144,14 +158,12 @@ in
(config.services.lidarr-mb-gap.syncToVPS && config.services.lidarr-mb-gap.vpsHost != null) (config.services.lidarr-mb-gap.syncToVPS && config.services.lidarr-mb-gap.vpsHost != null)
'' ''
# Set up SSH options # Set up SSH options
SSH_OPTS="" SSH_OPTS="-i ${config.services.lidarr-mb-gap.sshKeyFile}"
${lib.optionalString (config.services.lidarr-mb-gap.sshKeyFile != null) ''
SSH_OPTS="-i ${config.services.lidarr-mb-gap.sshKeyFile}"
''}
# Use SSH options with rsync (use full path to ssh) # Use SSH options with rsync (use full path to ssh)
${pkgs.rsync}/bin/rsync -avz --delete \ ${pkgs.rsync}/bin/rsync -avz --delete \
-e "${pkgs.openssh}/bin/ssh $SSH_OPTS -o StrictHostKeyChecking=yes" \ -e "${pkgs.openssh}/bin/ssh $SSH_OPTS -p ${toString config.services.lidarr-mb-gap.vpsPort} -o \
StrictHostKeyChecking=yes" \
${config.services.lidarr-mb-gap.reportDir}/ \ ${config.services.lidarr-mb-gap.reportDir}/ \
${config.services.lidarr-mb-gap.vpsHost}:${config.services.lidarr-mb-gap.vpsPath}/ ${config.services.lidarr-mb-gap.vpsHost}:${config.services.lidarr-mb-gap.vpsPath}/
'' ''