-
-
Notifications
You must be signed in to change notification settings - Fork 14.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create qbittorrent-nox service #279716
Create qbittorrent-nox service #279716
Changes from all commits
71095c7
23fc6ca
0c52251
0e29d0e
793e454
55ee8e5
a3926f6
d19093d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -356,6 +356,7 @@ in | |
rstudio-server = 324; | ||
localtimed = 325; | ||
automatic-timezoned = 326; | ||
qbittorrent-nox = 327; | ||
|
||
# When adding a uid, make sure it doesn't match an existing gid. And don't use uids above 399! | ||
|
||
|
@@ -666,6 +667,7 @@ in | |
rstudio-server = 324; | ||
localtimed = 325; | ||
automatic-timezoned = 326; | ||
qbittorrent-nox = 327; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same note as the |
||
|
||
# When adding a gid, make sure it doesn't match an existing | ||
# uid. Users and groups with the same name should have equal | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,141 @@ | ||||||||||||||||||
{ config, lib, pkgs, ... }: | ||||||||||||||||||
|
||||||||||||||||||
with lib; | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you should avoid this kind of use of with to address #208242 for this module. use inherits where you find yourself excessively reusing |
||||||||||||||||||
|
||||||||||||||||||
let | ||||||||||||||||||
cfg = config.services.qbittorrent-nox; | ||||||||||||||||||
in { | ||||||||||||||||||
options = { | ||||||||||||||||||
services = { | ||||||||||||||||||
qbittorrent-nox = { | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would instead name it |
||||||||||||||||||
enable = mkEnableOption (lib.mdDoc "qbittorrent-nox daemon"); | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Related to my proposition to rename the module:
Suggested change
|
||||||||||||||||||
|
||||||||||||||||||
web = { | ||||||||||||||||||
port = mkOption { | ||||||||||||||||||
type = types.port; | ||||||||||||||||||
default = 8080; | ||||||||||||||||||
description = lib.mdDoc '' | ||||||||||||||||||
qbittorrent-nox web UI port. | ||||||||||||||||||
''; | ||||||||||||||||||
Comment on lines
+17
to
+19
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||
}; | ||||||||||||||||||
openFirewall = mkOption { | ||||||||||||||||||
type = types.bool; | ||||||||||||||||||
default = false; | ||||||||||||||||||
description = lib.mdDoc '' | ||||||||||||||||||
Whether to open the firewall for the ports in | ||||||||||||||||||
{option}`services.qbittorrent-nox.web.port`. | ||||||||||||||||||
''; | ||||||||||||||||||
Comment on lines
+24
to
+27
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's only one port in that option
Suggested change
|
||||||||||||||||||
}; | ||||||||||||||||||
}; | ||||||||||||||||||
|
||||||||||||||||||
torrenting = { | ||||||||||||||||||
port = mkOption { | ||||||||||||||||||
type = types.port; | ||||||||||||||||||
default = 48197; | ||||||||||||||||||
description = lib.mdDoc '' | ||||||||||||||||||
qbittorrent-nox web UI port. | ||||||||||||||||||
''; | ||||||||||||||||||
Comment on lines
+35
to
+37
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||
}; | ||||||||||||||||||
|
||||||||||||||||||
openFirewall = mkOption { | ||||||||||||||||||
default = false; | ||||||||||||||||||
type = types.bool; | ||||||||||||||||||
description = lib.mdDoc '' | ||||||||||||||||||
Whether to open the firewall for the ports in | ||||||||||||||||||
{option}`services.qbittorrent-nox.torrenting.port`. | ||||||||||||||||||
''; | ||||||||||||||||||
Comment on lines
+43
to
+46
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's only one port in that option
Suggested change
|
||||||||||||||||||
}; | ||||||||||||||||||
}; | ||||||||||||||||||
|
||||||||||||||||||
dataDir = mkOption { | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is a dataDir true here for qbit, profiles seems to be the way it manages itself, a profilesdir commandline option is available. |
||||||||||||||||||
type = types.path; | ||||||||||||||||||
default = "/var/lib/qbittorrent-nox"; | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||
description = lib.mdDoc '' | ||||||||||||||||||
The directory where qbittorrent-nox will create files. | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is that the downloaded files? Or state files? Assuming the latter:
Suggested change
|
||||||||||||||||||
''; | ||||||||||||||||||
}; | ||||||||||||||||||
|
||||||||||||||||||
user = mkOption { | ||||||||||||||||||
type = types.str; | ||||||||||||||||||
default = "qbittorrent"; | ||||||||||||||||||
description = lib.mdDoc '' | ||||||||||||||||||
User account under which qbittorrent-nox runs. | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||
''; | ||||||||||||||||||
}; | ||||||||||||||||||
|
||||||||||||||||||
group = mkOption { | ||||||||||||||||||
type = types.str; | ||||||||||||||||||
default = "qbittorrent"; | ||||||||||||||||||
description = lib.mdDoc '' | ||||||||||||||||||
Group under which qbittorrent-nox runs. | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||
''; | ||||||||||||||||||
}; | ||||||||||||||||||
|
||||||||||||||||||
package = mkPackageOption pkgs "qbittorrent-nox" { }; | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We usually put the
Suggested change
|
||||||||||||||||||
}; | ||||||||||||||||||
}; | ||||||||||||||||||
}; | ||||||||||||||||||
|
||||||||||||||||||
config = mkIf cfg.enable { | ||||||||||||||||||
|
||||||||||||||||||
services.qbittorrent-nox.package = mkDefault (pkgs.qbittorrent-nox); | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is useless, |
||||||||||||||||||
|
||||||||||||||||||
systemd.tmpfiles.rules = [ | ||||||||||||||||||
"d '${cfg.dataDir}' 0770 ${cfg.user} ${cfg.group}" | ||||||||||||||||||
"d '${cfg.dataDir}/.config' 0770 ${cfg.user} ${cfg.group}" | ||||||||||||||||||
"d '${cfg.dataDir}/.config/qBittorrent' 0770 ${cfg.user} ${cfg.group}" | ||||||||||||||||||
]; | ||||||||||||||||||
Comment on lines
+83
to
+87
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use |
||||||||||||||||||
|
||||||||||||||||||
systemd.services.qbittorrent-nox = { | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same note about renaming the service
Suggested change
|
||||||||||||||||||
after = [ "network.target" "local-fs.target" "network-online.target" "nss-lookup.target" ]; | ||||||||||||||||||
wantedBy = [ "multi-user.target" ]; | ||||||||||||||||||
path = [ cfg.package ]; | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not needed, better served by systemd's service hardening options. |
||||||||||||||||||
unitConfig = { | ||||||||||||||||||
Description = "qBittorrent-nox Daemon"; | ||||||||||||||||||
Documentation = "man:qbittorrent-nox(1)"; | ||||||||||||||||||
}; | ||||||||||||||||||
serviceConfig = { | ||||||||||||||||||
ExecStart = '' | ||||||||||||||||||
${cfg.package}/bin/qbittorrent-nox \ | ||||||||||||||||||
--profile=${cfg.dataDir} \ | ||||||||||||||||||
--webui-port=${toString cfg.web.port} \ | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. neither port options should be done with the command line options, qbittorrent has a configuration file we can define these in, we know where its state will be after all |
||||||||||||||||||
--torrenting-port=${toString cfg.torrenting.port} | ||||||||||||||||||
''; | ||||||||||||||||||
Type = "exec"; | ||||||||||||||||||
User = cfg.user; | ||||||||||||||||||
Group = cfg.group; | ||||||||||||||||||
UMask = "0002"; | ||||||||||||||||||
PrivateTmp = "false"; | ||||||||||||||||||
TimeoutStopSec = 1800; | ||||||||||||||||||
}; | ||||||||||||||||||
# preStart = preStart; | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dead code. |
||||||||||||||||||
}; | ||||||||||||||||||
|
||||||||||||||||||
networking.firewall = mkMerge [ | ||||||||||||||||||
(mkIf (cfg.torrenting.openFirewall) { | ||||||||||||||||||
allowedTCPPorts = [ cfg.torrenting.port ]; | ||||||||||||||||||
allowedUDPPorts = [ cfg.torrenting.port ]; | ||||||||||||||||||
}) | ||||||||||||||||||
(mkIf (cfg.web.openFirewall) { | ||||||||||||||||||
allowedTCPPorts = [ cfg.web.port ]; | ||||||||||||||||||
}) | ||||||||||||||||||
]; | ||||||||||||||||||
|
||||||||||||||||||
environment.systemPackages = [ cfg.package ]; | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why? |
||||||||||||||||||
|
||||||||||||||||||
users.users = mkIf (cfg.user == "qbittorrent") { | ||||||||||||||||||
qbittorrent = { | ||||||||||||||||||
group = cfg.group; | ||||||||||||||||||
uid = config.ids.uids.qbittorrent-nox; | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As explained, please refrain from adding more
Suggested change
|
||||||||||||||||||
home = cfg.dataDir; | ||||||||||||||||||
description = "qbittorrent daemon user"; | ||||||||||||||||||
}; | ||||||||||||||||||
}; | ||||||||||||||||||
|
||||||||||||||||||
users.groups = mkIf (cfg.group == "qbittorrent") { | ||||||||||||||||||
qbittorrent = { | ||||||||||||||||||
gid = config.ids.gids.qbittorrent-nox; | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same remark as for
Suggested change
|
||||||||||||||||||
}; | ||||||||||||||||||
}; | ||||||||||||||||||
}; | ||||||||||||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import ./make-test-python.nix ({ pkgs, ...} : { | ||
name = "qbittorrent-nox"; | ||
meta = with pkgs.lib.maintainers; { | ||
maintainers = [ camilosampedro ]; | ||
}; | ||
|
||
nodes = { | ||
simple = { | ||
services.qbittorrent-nox = { | ||
enable = true; | ||
package = pkgs.qbittorrent-nox; | ||
port = 8091; | ||
web = { | ||
enable = true; | ||
openFirewall = true; | ||
}; | ||
}; | ||
}; | ||
|
||
}; | ||
|
||
testScript = '' | ||
start_all() | ||
|
||
simple.wait_for_unit("qbittorrent-nox") | ||
simple.wait_for_open_port(8091) | ||
simple.wait_until_succeeds("curl --fail http://simple:8091") | ||
''; | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shouldn't be done anymore, you should use (in order of preference):
DynamicUser
(potentially withUser
if you need a named user)users.users.<name>
.Given the usual approach for HTPC/seedbox services, using
users.users
is probably the way to go.