treefmt-nix formatting
This commit is contained in:
+30
-20
@@ -1,17 +1,25 @@
|
|||||||
{ config, pkgs, lib, ... }:
|
{
|
||||||
let
|
config,
|
||||||
|
pkgs,
|
||||||
|
lib,
|
||||||
|
...
|
||||||
|
}: let
|
||||||
cfg = config.nixarr.sabnzbd;
|
cfg = config.nixarr.sabnzbd;
|
||||||
nixarr = config.nixarr;
|
nixarr = config.nixarr;
|
||||||
ini-file-target = "${cfg.stateDir}/sabnzbd.ini";
|
ini-file-target = "${cfg.stateDir}/sabnzbd.ini";
|
||||||
concatStringsCommaIfExists = with lib.strings; stringList: (
|
concatStringsCommaIfExists = with lib.strings;
|
||||||
optionalString (builtins.length stringList > 0) (
|
stringList: (
|
||||||
concatStringsSep "," stringList
|
optionalString (builtins.length stringList > 0) (
|
||||||
)
|
concatStringsSep "," stringList
|
||||||
);
|
)
|
||||||
|
);
|
||||||
|
|
||||||
user-configs = {
|
user-configs = {
|
||||||
misc = {
|
misc = {
|
||||||
host = if cfg.openFirewall then "0.0.0.0" else "127.0.0.1";
|
host =
|
||||||
|
if cfg.openFirewall
|
||||||
|
then "0.0.0.0"
|
||||||
|
else "127.0.0.1";
|
||||||
port = cfg.guiPort;
|
port = cfg.guiPort;
|
||||||
download_dir = "${nixarr.mediaDir}/usenet/.incomplete";
|
download_dir = "${nixarr.mediaDir}/usenet/.incomplete";
|
||||||
complete_dir = "${nixarr.mediaDir}/usenet/manual";
|
complete_dir = "${nixarr.mediaDir}/usenet/manual";
|
||||||
@@ -28,22 +36,25 @@ let
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
compiled-configs = {misc = (user-configs.misc // api-key-configs.misc);};
|
compiled-configs = {misc = user-configs.misc // api-key-configs.misc;};
|
||||||
|
|
||||||
ini-base-config-file = pkgs.writeTextFile {
|
ini-base-config-file = pkgs.writeTextFile {
|
||||||
name = "base-config.ini";
|
name = "base-config.ini";
|
||||||
text = lib.generators.toINI {} compiled-configs;
|
text = lib.generators.toINI {} compiled-configs;
|
||||||
};
|
};
|
||||||
|
|
||||||
mkSedEditValue = name: value: ''sed -E 's%(\b${name} ?= ?).*%\1${builtins.toString value}%g' '';
|
mkSedEditValue = name: value: ''sed -E 's%(\b${name} ?= ?).*%\1${builtins.toString value}%g' '';
|
||||||
|
|
||||||
user-config-set-cmds = with lib.attrsets; mapAttrsToList (
|
user-config-set-cmds = with lib.attrsets;
|
||||||
group-n: group-v: (
|
mapAttrsToList (
|
||||||
mapAttrsToList (
|
group-n: group-v: (
|
||||||
n: v: "${mkSedEditValue n v} \\\n"
|
mapAttrsToList (
|
||||||
) group-v
|
n: v: "${mkSedEditValue n v} \\\n"
|
||||||
|
)
|
||||||
|
group-v
|
||||||
|
)
|
||||||
)
|
)
|
||||||
) user-configs;
|
user-configs;
|
||||||
|
|
||||||
fix-config-permissions-script = pkgs.writeShellApplication {
|
fix-config-permissions-script = pkgs.writeShellApplication {
|
||||||
name = "sabnzbd-fix-config-permissions";
|
name = "sabnzbd-fix-config-permissions";
|
||||||
@@ -99,7 +110,7 @@ let
|
|||||||
|
|
||||||
api_key_value=$(initool get ${ini-file-target} misc api_key -v)
|
api_key_value=$(initool get ${ini-file-target} misc api_key -v)
|
||||||
nzb_key_value=$(initool get ${ini-file-target} misc nzb_key -v)
|
nzb_key_value=$(initool get ${ini-file-target} misc nzb_key -v)
|
||||||
|
|
||||||
if ${bashCheckIfEmptyStr "api_key_value"} || ${bashCheckIfEmptyStr "nzb_key_value"}; then
|
if ${bashCheckIfEmptyStr "api_key_value"} || ${bashCheckIfEmptyStr "nzb_key_value"}; then
|
||||||
cp --preserve ${ini-file-target}{,.tmp}
|
cp --preserve ${ini-file-target}{,.tmp}
|
||||||
api_uuid=$(uuidgen --random | tr -d '-')
|
api_uuid=$(uuidgen --random | tr -d '-')
|
||||||
@@ -111,9 +122,8 @@ let
|
|||||||
fi
|
fi
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
in
|
in {
|
||||||
{
|
systemd.tmpfiles.rules = ["C ${cfg.stateDir}/sabnzbd.ini - - - - ${ini-base-config-file}"];
|
||||||
systemd.tmpfiles.rules = [ "C ${cfg.stateDir}/sabnzbd.ini - - - - ${ini-base-config-file}" ];
|
|
||||||
systemd.services.sabnzbd.serviceConfig.ExecStartPre = lib.mkBefore [
|
systemd.services.sabnzbd.serviceConfig.ExecStartPre = lib.mkBefore [
|
||||||
("+" + fix-config-permissions-script + "/bin/sabnzbd-fix-config-permissions")
|
("+" + fix-config-permissions-script + "/bin/sabnzbd-fix-config-permissions")
|
||||||
(gen-uuids-script + "/bin/sabnzbd-set-random-api-uuids")
|
(gen-uuids-script + "/bin/sabnzbd-set-random-api-uuids")
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ in {
|
|||||||
|
|
||||||
whitelistHostnames = mkOption {
|
whitelistHostnames = mkOption {
|
||||||
type = types.listOf types.str;
|
type = types.listOf types.str;
|
||||||
default = [ config.networking.hostName ];
|
default = [config.networking.hostName];
|
||||||
defaultText = "[ config.networking.hostName ]";
|
defaultText = "[ config.networking.hostName ]";
|
||||||
example = ''[ "mediaserv" "media.example.com" ]'';
|
example = ''[ "mediaserv" "media.example.com" ]'';
|
||||||
description = ''
|
description = ''
|
||||||
@@ -71,7 +71,7 @@ in {
|
|||||||
|
|
||||||
whitelistRanges = mkOption {
|
whitelistRanges = mkOption {
|
||||||
type = types.listOf types.str;
|
type = types.listOf types.str;
|
||||||
default = [ ];
|
default = [];
|
||||||
defaultText = "[ ]";
|
defaultText = "[ ]";
|
||||||
example = ''[ "192.168.1.0/24" "10.0.0.0/23" ]'';
|
example = ''[ "192.168.1.0/24" "10.0.0.0/23" ]'';
|
||||||
description = ''
|
description = ''
|
||||||
@@ -93,7 +93,7 @@ in {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
imports = [ ./config.nix ];
|
imports = [./config.nix];
|
||||||
|
|
||||||
config = mkIf cfg.enable {
|
config = mkIf cfg.enable {
|
||||||
systemd.tmpfiles.rules = [
|
systemd.tmpfiles.rules = [
|
||||||
@@ -107,7 +107,7 @@ in {
|
|||||||
configFile = "${cfg.stateDir}/sabnzbd.ini";
|
configFile = "${cfg.stateDir}/sabnzbd.ini";
|
||||||
};
|
};
|
||||||
|
|
||||||
networking.firewall.allowedTCPPorts = mkIf cfg.openFirewall [ cfg.guiPort ];
|
networking.firewall.allowedTCPPorts = mkIf cfg.openFirewall [cfg.guiPort];
|
||||||
|
|
||||||
systemd.services.sabnzbd.serviceConfig = {
|
systemd.services.sabnzbd.serviceConfig = {
|
||||||
Restart = "on-failure";
|
Restart = "on-failure";
|
||||||
|
|||||||
Reference in New Issue
Block a user