-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
nixos/qbittorrent: init #287923
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
Merged
Merged
nixos/qbittorrent: init #287923
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,238 @@ | ||
| { | ||
| config, | ||
| pkgs, | ||
| lib, | ||
| utils, | ||
| ... | ||
| }: | ||
| let | ||
| cfg = config.services.qbittorrent; | ||
| inherit (builtins) concatStringsSep isAttrs isString; | ||
| inherit (lib) | ||
| literalExpression | ||
| getExe | ||
| mkEnableOption | ||
| mkOption | ||
| mkPackageOption | ||
| mkIf | ||
| maintainers | ||
| escape | ||
| collect | ||
| mapAttrsRecursive | ||
| optionals | ||
| ; | ||
| inherit (lib.types) | ||
| str | ||
| port | ||
| path | ||
| nullOr | ||
| listOf | ||
| attrsOf | ||
| anything | ||
| submodule | ||
| ; | ||
| inherit (lib.generators) toINI mkKeyValueDefault mkValueStringDefault; | ||
| gendeepINI = toINI { | ||
| mkKeyValue = | ||
| let | ||
| sep = "="; | ||
| in | ||
| k: v: | ||
| if isAttrs v then | ||
| concatStringsSep "\n" ( | ||
| collect isString ( | ||
| mapAttrsRecursive ( | ||
| path: value: | ||
| "${escape [ sep ] (concatStringsSep "\\" ([ k ] ++ path))}${sep}${mkValueStringDefault { } value}" | ||
| ) v | ||
| ) | ||
| ) | ||
| else | ||
| mkKeyValueDefault { } sep k v; | ||
| }; | ||
| configFile = pkgs.writeText "qBittorrent.conf" (gendeepINI cfg.serverConfig); | ||
| in | ||
| { | ||
| options.services.qbittorrent = { | ||
| enable = mkEnableOption "qbittorrent, BitTorrent client"; | ||
|
|
||
| package = mkPackageOption pkgs "qbittorrent-nox" { }; | ||
|
|
||
| user = mkOption { | ||
| type = str; | ||
| default = "qbittorrent"; | ||
| description = "User account under which qbittorrent runs."; | ||
| }; | ||
|
|
||
| group = mkOption { | ||
| type = str; | ||
| default = "qbittorrent"; | ||
| description = "Group under which qbittorrent runs."; | ||
| }; | ||
|
|
||
| profileDir = mkOption { | ||
| type = path; | ||
| default = "/var/lib/qBittorrent/"; | ||
| description = "the path passed to qbittorrent via --profile."; | ||
| }; | ||
|
|
||
| openFirewall = mkEnableOption "opening both the webuiPort and torrentPort over TCP in the firewall"; | ||
|
|
||
| webuiPort = mkOption { | ||
| default = 8080; | ||
| type = nullOr port; | ||
| description = "the port passed to qbittorrent via `--webui-port`"; | ||
| }; | ||
|
|
||
| torrentingPort = mkOption { | ||
| default = null; | ||
| type = nullOr port; | ||
| description = "the port passed to qbittorrent via `--torrenting-port`"; | ||
| }; | ||
|
|
||
| serverConfig = mkOption { | ||
| default = { }; | ||
| type = submodule { | ||
| freeformType = attrsOf (attrsOf anything); | ||
| }; | ||
| description = '' | ||
| Free-form settings mapped to the `qBittorrent.conf` file in the profile. | ||
| Refer to [Explanation-of-Options-in-qBittorrent](https://github.com/qbittorrent/qBittorrent/wiki/Explanation-of-Options-in-qBittorrent). | ||
| The Password_PBKDF2 format is oddly unique, you will likely want to use [this tool](https://codeberg.org/feathecutie/qbittorrent_password) to generate the format. | ||
| Alternatively you can run qBittorrent independently first and use its webUI to generate the format. | ||
|
|
||
| Optionally an alternative webUI can be easily set. VueTorrent for example: | ||
| ```nix | ||
| { | ||
| Preferences = { | ||
| WebUI = { | ||
| AlternativeUIEnabled = true; | ||
| RootFolder = "''${pkgs.vuetorrent}/share/vuetorrent"; | ||
| }; | ||
| }; | ||
| } | ||
| ]; | ||
| ``` | ||
| ''; | ||
| example = literalExpression '' | ||
| { | ||
| LegalNotice.Accepted = true; | ||
| Preferences = { | ||
| WebUI = { | ||
| Username = "user"; | ||
| Password_PBKDF2 = "generated ByteArray."; | ||
| }; | ||
| General.Locale = "en"; | ||
| }; | ||
| } | ||
| ''; | ||
| }; | ||
|
|
||
| extraArgs = mkOption { | ||
| type = listOf str; | ||
| default = [ ]; | ||
| description = '' | ||
| Extra arguments passed to qbittorrent. See `qbittorrent -h`, or the [source code](https://github.com/qbittorrent/qBittorrent/blob/master/src/app/cmdoptions.cpp), for the available arguments. | ||
| ''; | ||
| example = [ | ||
| "--confirm-legal-notice" | ||
| ]; | ||
| }; | ||
| }; | ||
| config = mkIf cfg.enable { | ||
| systemd = { | ||
| tmpfiles.settings = { | ||
| qbittorrent = { | ||
| "${cfg.profileDir}/qBittorrent/"."d" = { | ||
| mode = "755"; | ||
| inherit (cfg) user group; | ||
| }; | ||
| "${cfg.profileDir}/qBittorrent/config/"."d" = { | ||
| mode = "755"; | ||
| inherit (cfg) user group; | ||
| }; | ||
| "${cfg.profileDir}/qBittorrent/config/qBittorrent.conf"."L+" = mkIf (cfg.serverConfig != { }) { | ||
| mode = "1400"; | ||
| inherit (cfg) user group; | ||
| argument = "${configFile}"; | ||
| }; | ||
| }; | ||
| }; | ||
| services.qbittorrent = { | ||
| description = "qbittorrent BitTorrent client"; | ||
| wants = [ "network-online.target" ]; | ||
| after = [ | ||
| "local-fs.target" | ||
| "network-online.target" | ||
| "nss-lookup.target" | ||
| ]; | ||
| wantedBy = [ "multi-user.target" ]; | ||
| restartTriggers = optionals (cfg.serverConfig != { }) [ configFile ]; | ||
|
|
||
| serviceConfig = { | ||
| Type = "simple"; | ||
| User = cfg.user; | ||
| Group = cfg.group; | ||
| ExecStart = utils.escapeSystemdExecArgs ( | ||
| [ | ||
| (getExe cfg.package) | ||
| "--profile=${cfg.profileDir}" | ||
| ] | ||
| ++ optionals (cfg.webuiPort != null) [ "--webui-port=${toString cfg.webuiPort}" ] | ||
| ++ optionals (cfg.torrentingPort != null) [ "--torrenting-port=${toString cfg.torrentingPort}" ] | ||
| ++ cfg.extraArgs | ||
| ); | ||
| TimeoutStopSec = 1800; | ||
eclairevoyant marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| # https://github.com/qbittorrent/qBittorrent/pull/6806#discussion_r121478661 | ||
| PrivateTmp = false; | ||
|
|
||
| PrivateNetwork = false; | ||
| RemoveIPC = true; | ||
| NoNewPrivileges = true; | ||
| PrivateDevices = true; | ||
| PrivateUsers = true; | ||
| ProtectHome = "yes"; | ||
| ProtectProc = "invisible"; | ||
| ProcSubset = "pid"; | ||
| ProtectSystem = "full"; | ||
| ProtectClock = true; | ||
| ProtectHostname = true; | ||
| ProtectKernelLogs = true; | ||
| ProtectKernelModules = true; | ||
| ProtectKernelTunables = true; | ||
| ProtectControlGroups = true; | ||
| RestrictAddressFamilies = [ | ||
| "AF_INET" | ||
| "AF_INET6" | ||
| "AF_NETLINK" | ||
| ]; | ||
| RestrictNamespaces = true; | ||
| RestrictRealtime = true; | ||
| RestrictSUIDSGID = true; | ||
| LockPersonality = true; | ||
| MemoryDenyWriteExecute = true; | ||
| SystemCallArchitectures = "native"; | ||
| CapabilityBoundingSet = ""; | ||
| SystemCallFilter = [ "@system-service" ]; | ||
| }; | ||
| }; | ||
| }; | ||
|
|
||
| users = { | ||
| users = mkIf (cfg.user == "qbittorrent") { | ||
| qbittorrent = { | ||
| inherit (cfg) group; | ||
| isSystemUser = true; | ||
| }; | ||
| }; | ||
| groups = mkIf (cfg.group == "qbittorrent") { qbittorrent = { }; }; | ||
| }; | ||
|
|
||
| networking.firewall.allowedTCPPorts = mkIf cfg.openFirewall ( | ||
| optionals (cfg.webuiPort != null) [ cfg.webuiPort ] | ||
| ++ optionals (cfg.torrentingPort != null) [ cfg.torrentingPort ] | ||
| ); | ||
| }; | ||
| meta.maintainers = with maintainers; [ fsnkty ]; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I noticed that
qBittorrent.confis created withmode = 1400. Why is the sticky bit set?Also, it looks like permissions are ignored for symlinks anyway: https://www.man7.org/linux/man-pages/man5/tmpfiles.d.5.html#:~:text=L%2C%20L+%2C%20L?.
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.
if my memory is right, setting it made qbittorrent unable to overwrite the symlink or otherwise within it with a directory/file.
if this is the case for the stickybit also then I'm not sure why I observed this behavior.
anyone willing to confirm qbittorrents behavior is consistent with/without this set, please do share.
Uh oh!
There was an error while loading. Please reload this page.
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.
A PR was made a couple days ago, changing this behavior. We could continue this discussion there: #482534.