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:
@@ -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";
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -80,9 +87,10 @@ in
|
|||||||
};
|
};
|
||||||
|
|
||||||
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 {
|
||||||
@@ -108,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;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -150,10 +158,7 @@ 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 \
|
||||||
|
|||||||
Reference in New Issue
Block a user