Skip to content

Commit ec5daeb

Browse files
authored
Add Declutarr package, update module (#154)
* Add Declutarr package * Update Declutarr module using new package
1 parent ec82c04 commit ec5daeb

File tree

7 files changed

+153
-16
lines changed

7 files changed

+153
-16
lines changed
Lines changed: 96 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,111 @@
1-
{ config, lib, ... }:
1+
{ config, lib, pkgs, ... }:
22

33
with lib;
44

5-
let cfg = config.services.declutarr;
5+
let
6+
cfg = config.services.declutarr;
7+
format = pkgs.formats.yaml { };
8+
configFile = if cfg.config != null then
9+
format.generate "configuration.yaml" cfg.config
10+
else
11+
cfg.configFile;
612
in {
713
options.services.declutarr = {
814
enable = mkEnableOption "Enable Declutarr";
915

10-
configFile = mkOption { type = types.path; };
16+
package = mkOption {
17+
type = types.package;
18+
default = pkgs.declutarr;
19+
};
20+
21+
dataDir = mkOption {
22+
type = types.path;
23+
default = "/var/lib/declutarr";
24+
};
25+
26+
user = mkOption {
27+
type = types.str;
28+
default = "declutarr";
29+
};
1130

12-
extraVolumes = mkOption {
13-
type = types.listOf types.path;
14-
default = [ ];
31+
group = mkOption {
32+
type = types.str;
33+
default = "declutarr";
34+
};
35+
36+
config = mkOption {
37+
type = types.nullOr format.type;
38+
default = null;
39+
};
40+
41+
configFile = mkOption {
42+
type = types.nullOr types.path;
43+
default = null;
44+
};
45+
46+
environmentFile = mkOption {
47+
type = types.nullOr types.path;
48+
default = null;
1549
};
1650
};
1751

1852
config = mkIf cfg.enable {
19-
virtualisation.oci-containers.containers.declutarr = {
20-
image = "ghcr.io/manimatter/decluttarr:dev";
21-
environment = { TZ = config.time.timeZone; };
22-
volumes = [ "${cfg.configFile}:/app/config/config.yaml" ]
23-
++ (map (vol: "${vol}:${vol}") cfg.extraVolumes);
53+
assertions = [{
54+
assertion = !(cfg.config != null && cfg.configFile != null);
55+
message =
56+
"Only one of `config` or `configFile` can be configured at the same time";
57+
}];
58+
59+
systemd.tmpfiles.settings."10-declutarr" = {
60+
${cfg.dataDir} = {
61+
"d" = {
62+
inherit (cfg) user group;
63+
mode = "0777";
64+
};
65+
};
66+
67+
"${cfg.dataDir}/config" = {
68+
"d" = {
69+
inherit (cfg) user group;
70+
mode = "0777";
71+
};
72+
};
73+
74+
"${cfg.dataDir}/logs" = {
75+
"d" = {
76+
inherit (cfg) user group;
77+
mode = "0777";
78+
};
79+
};
80+
};
81+
82+
users = {
83+
users.declutarr = mkIf (cfg.user == "declutarr") {
84+
inherit (cfg) group;
85+
isSystemUser = true;
86+
};
87+
88+
groups = mkIf (cfg.group == "declutarr") { declutarr = { }; };
89+
};
90+
91+
systemd.services.declutarr = {
92+
enable = true;
93+
wants = [ "network.online.target" ];
94+
after = [ "network.online.target" ];
95+
wantedBy = [ "multi-user.target" ];
96+
preStart = ''
97+
ln -sf ${configFile} ${cfg.dataDir}/config/config.yaml
98+
'';
99+
serviceConfig = {
100+
WorkingDirectory = cfg.dataDir;
101+
EnvironmentFile = [ cfg.environmentFile ];
102+
ExecStart = lib.getExe cfg.package;
103+
ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
104+
User = cfg.user;
105+
Group = cfg.group;
106+
Restart = "on-failure";
107+
ReadWritePaths = [ cfg.dataDir ];
108+
};
24109
};
25110
};
26111
}

modules/overlays/default.nix

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
# This is to pick up bugfix here: https://github.com/thanos-io/thanos/issues/7923
2121
inherit (nixpkgs-master) thanos;
2222

23-
inherit (self'.packages) bentopdf fileflows mongodb-ce-6_0 tracearr;
23+
inherit (self'.packages)
24+
bentopdf declutarr fileflows mongodb-ce-6_0 tracearr;
2425
};
2526
};
2627
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{ python3Packages, fetchFromGitHub, makeWrapper }:
2+
3+
python3Packages.buildPythonApplication rec {
4+
name = "declutarr";
5+
version = "2.0.0";
6+
7+
src = fetchFromGitHub {
8+
owner = "ManiMatter";
9+
repo = "decluttarr";
10+
tag = "v${version}";
11+
hash = "sha256-3mB5+ao3w+CkyTS/o1O9/7UXOoGkA/mTpJNEQxUTa9Q=";
12+
};
13+
14+
pyproject = true;
15+
16+
build-system = with python3Packages; [ setuptools ];
17+
18+
dependencies = with python3Packages; [
19+
requests
20+
python-dateutil
21+
pytest
22+
pytest-asyncio
23+
black
24+
pylint
25+
autoflake
26+
isort
27+
pyyaml-env-tag
28+
demjson3
29+
ruff
30+
watchdog
31+
];
32+
33+
nativeBuildInputs = [ makeWrapper ];
34+
35+
installPhase = ''
36+
runHook preInstall
37+
38+
mkdir -p $out/bin $out/libexec/declutarr
39+
cp -R main.py src tests $out/libexec/declutarr
40+
41+
makeWrapper "${python3Packages.python.interpreter}" "$out/bin/declutarr" \
42+
--set PYTHONPATH "$PYTHONPATH" \
43+
--add-flags "$out/libexec/declutarr/main.py"
44+
45+
runHook postInstall
46+
'';
47+
48+
# TODO: Actually run tests
49+
doCheck = false;
50+
51+
meta.mainProgram = "declutarr";
52+
}

modules/packages/default.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ _: {
22
perSystem = { pkgs, ... }: {
33
packages = {
44
bentopdf = pkgs.callPackage ./bentopdf { };
5+
declutarr = pkgs.callPackage ./declutarr { };
56
fileflows = pkgs.callPackage ./fileflows { };
67
mongodb-ce-6_0 = pkgs.callPackage ./mongodb-ce-6_0 { };
78
tracearr = pkgs.callPackage ./tracearr { };

modules/profiles/media-management/declutarr/default.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@
5151
}];
5252
};
5353
};
54+
owner = config.services.declutarr.user;
55+
inherit (config.services.declutarr) group;
5456
mode = "0700";
5557
};
5658

5759
services.declutarr = {
5860
enable = true;
5961
configFile = config.sops.templates.declutarr_config.path;
60-
extraVolumes =
61-
[ "/mnt/blockbuster/media/movies" "/mnt/blockbuster/media/tv" ];
6262
};
6363
}

modules/profiles/media-management/radarr/default.nix

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
owner = config.services.radarr.user;
3838
inherit (config.services.radarr) group;
3939
mode = "0660";
40-
restartUnits = [ "radarr.service" ];
4140
};
4241
};
4342

modules/profiles/media-management/sonarr/default.nix

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
owner = config.services.sonarr.user;
4040
inherit (config.services.sonarr) group;
4141
mode = "0660";
42-
restartUnits = [ "sonarr.service" ];
4342
};
4443
};
4544

0 commit comments

Comments
 (0)