From dca9a6af5fb7557d88c76e256cb6837bbff3c439 Mon Sep 17 00:00:00 2001 From: Matt Nish-Lapidus Date: Wed, 26 Mar 2025 13:17:09 -0400 Subject: [PATCH] beets --- modules/home/beets/config.yaml | 2 +- modules/system/qbittorrent-nox.nix | 123 +++++++++++++++++++++++++++++ 2 files changed, 124 insertions(+), 1 deletion(-) create mode 100644 modules/system/qbittorrent-nox.nix diff --git a/modules/home/beets/config.yaml b/modules/home/beets/config.yaml index 51ab8e5..6d94a4e 100644 --- a/modules/home/beets/config.yaml +++ b/modules/home/beets/config.yaml @@ -65,7 +65,7 @@ plex: port: 32400 token: "DpUEsDtn43fiMEyzsTZ3" paths: - default: %the{$albumartist}/$album%aunique{}/%if{$multidisc,$disc-}$track - $title + default: %the{$albumartist}{$artistdisambig}/$album%aunique{}/%if{$multidisc,$disc-}$track - $title comp: Various Artists/$album%aunique{}/$album%aunique{}/%if{$multidisc,$disc-}$track - $title ui: diff --git a/modules/system/qbittorrent-nox.nix b/modules/system/qbittorrent-nox.nix new file mode 100644 index 0000000..52785c3 --- /dev/null +++ b/modules/system/qbittorrent-nox.nix @@ -0,0 +1,123 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + cfg = config.services.qbittorrent; + UID = 888; + GID = 888; +in +{ + options.services.qbittorrent = { + enable = mkEnableOption (lib.mdDoc "qBittorrent headless"); + + dataDir = mkOption { + type = types.path; + default = "/var/lib/qbittorrent"; + description = lib.mdDoc '' + The directory where qBittorrent stores its data files. + ''; + }; + + user = mkOption { + type = types.str; + default = "qbittorrent"; + description = lib.mdDoc '' + User account under which qBittorrent runs. + ''; + }; + + group = mkOption { + type = types.str; + default = "qbittorrent"; + description = lib.mdDoc '' + Group under which qBittorrent runs. + ''; + }; + + port = mkOption { + type = types.port; + default = 8080; + description = lib.mdDoc '' + qBittorrent web UI port. + ''; + }; + + openFirewall = mkOption { + type = types.bool; + default = false; + description = lib.mdDoc '' + Open services.qBittorrent.port to the outside network. + ''; + }; + + package = mkOption { + type = types.package; + default = pkgs.qbittorrent-nox; + defaultText = literalExpression "pkgs.qbittorrent-nox"; + description = lib.mdDoc '' + The qbittorrent package to use. + ''; + }; + }; + + config = mkIf cfg.enable { + networking.firewall = mkIf cfg.openFirewall { + allowedTCPPorts = [ cfg.port ]; + }; + + systemd.services.qbittorrent = { + # based on the plex.nix service module and + # https://github.com/qbittorrent/qBittorrent/blob/master/dist/unix/systemd/qbittorrent-nox%40.service.in + description = "qBittorrent-nox service"; + documentation = [ "man:qbittorrent-nox(1)" ]; + after = [ "network.target" ]; + wantedBy = [ "multi-user.target" ]; + + serviceConfig = { + Type = "simple"; + User = cfg.user; + Group = cfg.group; + + # Run the pre-start script with full permissions (the "!" prefix) so it + # can create the data directory if necessary. + ExecStartPre = let + preStartScript = pkgs.writeScript "qbittorrent-run-prestart" '' + #!${pkgs.bash}/bin/bash + + # Create data directory if it doesn't exist + if ! test -d "$QBT_PROFILE"; then + echo "Creating initial qBittorrent data directory in: $QBT_PROFILE" + install -d -m 0755 -o "${cfg.user}" -g "${cfg.group}" "$QBT_PROFILE" + fi + ''; + in + "!${preStartScript}"; + + #ExecStart = "${pkgs.qbittorrent-nox}/bin/qbittorrent-nox"; + ExecStart = "${cfg.package}/bin/qbittorrent-nox"; + # To prevent "Quit & shutdown daemon" from working; we want systemd to + # manage it! + #Restart = "on-success"; + #UMask = "0002"; + #LimitNOFILE = cfg.openFilesLimit; + }; + + environment = { + QBT_PROFILE=cfg.dataDir; + QBT_WEBUI_PORT=toString cfg.port; + }; + }; + + users.users = mkIf (cfg.user == "qbittorrent") { + qbittorrent = { + group = cfg.group; + uid = UID; + }; + }; + + users.groups = mkIf (cfg.group == "qbittorrent") { + qbittorrent = { gid = GID; }; + }; + }; +}