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";
|
||||
};
|
||||
|
||||
outputs = { self, nixpkgs, flake-utils }:
|
||||
outputs =
|
||||
{ nixpkgs, flake-utils }:
|
||||
let
|
||||
# NixOS module output (not system-specific)
|
||||
# The module accepts a package option, which can be set from the flake's packages
|
||||
@@ -17,7 +18,9 @@
|
||||
{
|
||||
# Export NixOS modules
|
||||
nixosModules = nixosModules;
|
||||
} // flake-utils.lib.eachDefaultSystem (system:
|
||||
}
|
||||
// flake-utils.lib.eachDefaultSystem (
|
||||
system:
|
||||
let
|
||||
pkgs = import nixpkgs { inherit system; };
|
||||
lib = pkgs.lib;
|
||||
@@ -29,10 +32,12 @@
|
||||
{
|
||||
devShells.default = pkgs.mkShell {
|
||||
buildInputs = [
|
||||
(pkgs.python3.withPackages (ps: with ps; [
|
||||
(pkgs.python3.withPackages (
|
||||
ps: with ps; [
|
||||
requests
|
||||
python-dotenv
|
||||
]))
|
||||
]
|
||||
))
|
||||
pkgs.black
|
||||
];
|
||||
shellHook = ''
|
||||
@@ -55,4 +60,3 @@
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
{ pkgs, lib, src }:
|
||||
{ pkgs, src }:
|
||||
|
||||
pkgs.python3Packages.buildPythonApplication {
|
||||
pname = "lidarr-mb-gap";
|
||||
@@ -17,4 +17,3 @@ pkgs.python3Packages.buildPythonApplication {
|
||||
description = "Lidarr to MusicBrainz Missing Albums Finder";
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
#
|
||||
# Then in your NixOS configuration:
|
||||
|
||||
{ config, pkgs, inputs, ... }:
|
||||
{ pkgs, inputs, ... }:
|
||||
|
||||
{
|
||||
imports = [
|
||||
@@ -61,7 +61,7 @@
|
||||
#
|
||||
# If you're not using flakes, import the module directly:
|
||||
|
||||
{ config, pkgs, ... }:
|
||||
{ ... }:
|
||||
|
||||
{
|
||||
imports = [
|
||||
@@ -97,7 +97,7 @@
|
||||
# EXAMPLE 3: Minimal Configuration (No VPS Sync)
|
||||
# ============================================================================
|
||||
|
||||
{ config, pkgs, inputs, ... }:
|
||||
{ pkgs, inputs, ... }:
|
||||
|
||||
{
|
||||
imports = [
|
||||
|
||||
@@ -1,19 +1,26 @@
|
||||
{ config, lib, pkgs, ... }:
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
|
||||
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 {
|
||||
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.";
|
||||
else
|
||||
throw "services.lidarr-mb-gap: Either 'package' or 'src' must be set.";
|
||||
in
|
||||
{
|
||||
options.services.lidarr-mb-gap = {
|
||||
@@ -74,7 +81,8 @@ in
|
||||
};
|
||||
|
||||
sshKnownHosts = lib.mkOption {
|
||||
type = lib.types.attrsOf (lib.types.submodule {
|
||||
type = lib.types.attrsOf (
|
||||
lib.types.submodule {
|
||||
options = {
|
||||
hostNames = lib.mkOption {
|
||||
type = lib.types.listOf lib.types.str;
|
||||
@@ -85,7 +93,8 @@ in
|
||||
description = "SSH public key for the host";
|
||||
};
|
||||
};
|
||||
});
|
||||
}
|
||||
);
|
||||
default = { };
|
||||
description = "SSH known hosts configuration for the VPS (same format as programs.ssh.knownHosts)";
|
||||
};
|
||||
@@ -132,19 +141,22 @@ in
|
||||
}
|
||||
|
||||
# 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
|
||||
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 SSH options with rsync (use full path to ssh)
|
||||
${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.vpsHost}:${config.services.lidarr-mb-gap.vpsPath}/
|
||||
''}
|
||||
''
|
||||
}
|
||||
'';
|
||||
StandardOutput = "journal";
|
||||
StandardError = "journal";
|
||||
@@ -161,4 +173,3 @@ in
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user