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.
This commit is contained in:
Danilo Reyes
2025-11-11 16:49:59 -06:00
parent 578b9d316a
commit 0b86143646

View File

@@ -6,8 +6,7 @@
}:
let
reportDir = "/var/lib/lidarr-mb-gap/reports";
envFile = "/var/lib/lidarr-mb-gap/.env";
defaultHome = "/var/lib/lidarr-mb-gap";
# Determine which package to use
lidarrMbGapPackage =
@@ -25,6 +24,12 @@ in
options.services.lidarr-mb-gap = {
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 {
type = lib.types.nullOr lib.types.package;
default = null;
@@ -39,13 +44,15 @@ in
reportDir = lib.mkOption {
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";
};
envFile = lib.mkOption {
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";
};
@@ -80,9 +87,10 @@ in
};
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.";
type = lib.types.str;
default = "${config.services.lidarr-mb-gap.home}/.ssh/id_ed25519";
defaultText = lib.literalExpression ''"''${home}/.ssh/id_ed25519"'';
description = "Path to SSH private key file for rsync";
};
sshKnownHosts = lib.mkOption {
@@ -108,13 +116,13 @@ in
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 -"
"d ${config.services.lidarr-mb-gap.home}/.ssh 0700 lidarr-mb-gap lidarr-mb-gap -"
];
users.users.lidarr-mb-gap = {
isSystemUser = true;
group = "lidarr-mb-gap";
home = "/var/lib/lidarr-mb-gap";
home = config.services.lidarr-mb-gap.home;
createHome = true;
};
@@ -150,10 +158,7 @@ in
(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 (use full path to ssh)
${pkgs.rsync}/bin/rsync -avz --delete \