Refactor NixOS module and flake configuration for lidarr-mb-gap
- Updated `flake.nix` to streamline output definitions and improve readability. - Refactored NixOS module configurations in `nixos/lidarr-mb-gap.nix` for better structure and clarity. - Simplified the package import process in `nix/package.nix` by removing unnecessary parameters. - Enhanced example configurations in `nixos/EXAMPLE_CONFIG.nix` to align with the new structure.
This commit is contained in:
14
flake.nix
14
flake.nix
@@ -6,7 +6,8 @@
|
|||||||
flake-utils.url = "github:numtide/flake-utils";
|
flake-utils.url = "github:numtide/flake-utils";
|
||||||
};
|
};
|
||||||
|
|
||||||
outputs = { self, nixpkgs, flake-utils }:
|
outputs =
|
||||||
|
{ nixpkgs, flake-utils }:
|
||||||
let
|
let
|
||||||
# NixOS module output (not system-specific)
|
# NixOS module output (not system-specific)
|
||||||
# The module accepts a package option, which can be set from the flake's packages
|
# The module accepts a package option, which can be set from the flake's packages
|
||||||
@@ -17,7 +18,9 @@
|
|||||||
{
|
{
|
||||||
# Export NixOS modules
|
# Export NixOS modules
|
||||||
nixosModules = nixosModules;
|
nixosModules = nixosModules;
|
||||||
} // flake-utils.lib.eachDefaultSystem (system:
|
}
|
||||||
|
// flake-utils.lib.eachDefaultSystem (
|
||||||
|
system:
|
||||||
let
|
let
|
||||||
pkgs = import nixpkgs { inherit system; };
|
pkgs = import nixpkgs { inherit system; };
|
||||||
lib = pkgs.lib;
|
lib = pkgs.lib;
|
||||||
@@ -29,10 +32,12 @@
|
|||||||
{
|
{
|
||||||
devShells.default = pkgs.mkShell {
|
devShells.default = pkgs.mkShell {
|
||||||
buildInputs = [
|
buildInputs = [
|
||||||
(pkgs.python3.withPackages (ps: with ps; [
|
(pkgs.python3.withPackages (
|
||||||
|
ps: with ps; [
|
||||||
requests
|
requests
|
||||||
python-dotenv
|
python-dotenv
|
||||||
]))
|
]
|
||||||
|
))
|
||||||
pkgs.black
|
pkgs.black
|
||||||
];
|
];
|
||||||
shellHook = ''
|
shellHook = ''
|
||||||
@@ -55,4 +60,3 @@
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
{ pkgs, lib, src }:
|
{ pkgs, src }:
|
||||||
|
|
||||||
pkgs.python3Packages.buildPythonApplication {
|
pkgs.python3Packages.buildPythonApplication {
|
||||||
pname = "lidarr-mb-gap";
|
pname = "lidarr-mb-gap";
|
||||||
@@ -17,4 +17,3 @@ pkgs.python3Packages.buildPythonApplication {
|
|||||||
description = "Lidarr to MusicBrainz Missing Albums Finder";
|
description = "Lidarr to MusicBrainz Missing Albums Finder";
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
#
|
#
|
||||||
# Then in your NixOS configuration:
|
# Then in your NixOS configuration:
|
||||||
|
|
||||||
{ config, pkgs, inputs, ... }:
|
{ pkgs, inputs, ... }:
|
||||||
|
|
||||||
{
|
{
|
||||||
imports = [
|
imports = [
|
||||||
@@ -61,7 +61,7 @@
|
|||||||
#
|
#
|
||||||
# If you're not using flakes, import the module directly:
|
# If you're not using flakes, import the module directly:
|
||||||
|
|
||||||
{ config, pkgs, ... }:
|
{ ... }:
|
||||||
|
|
||||||
{
|
{
|
||||||
imports = [
|
imports = [
|
||||||
@@ -97,7 +97,7 @@
|
|||||||
# EXAMPLE 3: Minimal Configuration (No VPS Sync)
|
# EXAMPLE 3: Minimal Configuration (No VPS Sync)
|
||||||
# ============================================================================
|
# ============================================================================
|
||||||
|
|
||||||
{ config, pkgs, inputs, ... }:
|
{ pkgs, inputs, ... }:
|
||||||
|
|
||||||
{
|
{
|
||||||
imports = [
|
imports = [
|
||||||
|
|||||||
@@ -1,19 +1,26 @@
|
|||||||
{ config, lib, pkgs, ... }:
|
{
|
||||||
|
config,
|
||||||
|
lib,
|
||||||
|
pkgs,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
|
||||||
let
|
let
|
||||||
reportDir = "/var/lib/lidarr-mb-gap/reports";
|
reportDir = "/var/lib/lidarr-mb-gap/reports";
|
||||||
envFile = "/var/lib/lidarr-mb-gap/.env";
|
envFile = "/var/lib/lidarr-mb-gap/.env";
|
||||||
|
|
||||||
# Determine which package to use
|
# Determine which package to use
|
||||||
lidarrMbGapPackage = if config.services.lidarr-mb-gap.package != null
|
lidarrMbGapPackage =
|
||||||
then config.services.lidarr-mb-gap.package
|
if config.services.lidarr-mb-gap.package != null then
|
||||||
else if config.services.lidarr-mb-gap.src != null
|
config.services.lidarr-mb-gap.package
|
||||||
then import ../nix/package.nix {
|
else if config.services.lidarr-mb-gap.src != null then
|
||||||
|
import ../nix/package.nix {
|
||||||
inherit pkgs;
|
inherit pkgs;
|
||||||
lib = pkgs.lib;
|
lib = pkgs.lib;
|
||||||
src = config.services.lidarr-mb-gap.src;
|
src = config.services.lidarr-mb-gap.src;
|
||||||
}
|
}
|
||||||
else throw "services.lidarr-mb-gap: Either 'package' or 'src' must be set.";
|
else
|
||||||
|
throw "services.lidarr-mb-gap: Either 'package' or 'src' must be set.";
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
options.services.lidarr-mb-gap = {
|
options.services.lidarr-mb-gap = {
|
||||||
@@ -74,7 +81,8 @@ in
|
|||||||
};
|
};
|
||||||
|
|
||||||
sshKnownHosts = lib.mkOption {
|
sshKnownHosts = lib.mkOption {
|
||||||
type = lib.types.attrsOf (lib.types.submodule {
|
type = lib.types.attrsOf (
|
||||||
|
lib.types.submodule {
|
||||||
options = {
|
options = {
|
||||||
hostNames = lib.mkOption {
|
hostNames = lib.mkOption {
|
||||||
type = lib.types.listOf lib.types.str;
|
type = lib.types.listOf lib.types.str;
|
||||||
@@ -85,7 +93,8 @@ in
|
|||||||
description = "SSH public key for the host";
|
description = "SSH public key for the host";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
});
|
}
|
||||||
|
);
|
||||||
default = { };
|
default = { };
|
||||||
description = "SSH known hosts configuration for the VPS (same format as programs.ssh.knownHosts)";
|
description = "SSH known hosts configuration for the VPS (same format as programs.ssh.knownHosts)";
|
||||||
};
|
};
|
||||||
@@ -132,19 +141,22 @@ in
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Sync to VPS if enabled
|
# Sync to VPS if enabled
|
||||||
${lib.optionalString (config.services.lidarr-mb-gap.syncToVPS && config.services.lidarr-mb-gap.vpsHost != null) ''
|
${lib.optionalString
|
||||||
|
(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=""
|
||||||
${lib.optionalString (config.services.lidarr-mb-gap.sshKeyFile != null) ''
|
${lib.optionalString (config.services.lidarr-mb-gap.sshKeyFile != null) ''
|
||||||
SSH_OPTS="-i ${config.services.lidarr-mb-gap.sshKeyFile}"
|
SSH_OPTS="-i ${config.services.lidarr-mb-gap.sshKeyFile}"
|
||||||
''}
|
''}
|
||||||
|
|
||||||
# Use SSH options with rsync
|
# Use SSH options with rsync (use full path to ssh)
|
||||||
${pkgs.rsync}/bin/rsync -avz --delete \
|
${pkgs.rsync}/bin/rsync -avz --delete \
|
||||||
-e "ssh $SSH_OPTS -o StrictHostKeyChecking=yes" \
|
-e "${pkgs.openssh}/bin/ssh $SSH_OPTS -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}/
|
||||||
''}
|
''
|
||||||
|
}
|
||||||
'';
|
'';
|
||||||
StandardOutput = "journal";
|
StandardOutput = "journal";
|
||||||
StandardError = "journal";
|
StandardError = "journal";
|
||||||
@@ -161,4 +173,3 @@ in
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user