aboutsummaryrefslogtreecommitdiff
path: root/home-manager/modules/programs/aria2.nix
blob: d1317ff7616cd97b5a86d100d0ce8179a55478ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
{ config, lib, pkgs, ... }:

with lib;

let
  cfg = config.programs.aria2;

  formatLine = n: v:
    let
      formatValue = v:
        if builtins.isBool v then
          (if v then "true" else "false")
        else
          toString v;
    in "${n}=${formatValue v}";
in {
  meta.maintainers = [ hm.maintainers.justinlovinger ];

  options.programs.aria2 = {
    enable = mkEnableOption "aria2";

    settings = mkOption {
      type = with types; attrsOf (oneOf [ bool float int str ]);
      default = { };
      description = ''
        Options to add to <filename>aria2.conf</filename> file.
        See
        <citerefentry>
          <refentrytitle>aria2c</refentrytitle>
          <manvolnum>1</manvolnum>
        </citerefentry>
        for options.
      '';
      example = literalExample ''
        {
          listen-port = 60000;
          dht-listen-port = 60000;
          seed-ratio = 1.0;
          max-upload-limit = "50K";
          ftp-pasv = true;
        }
      '';
    };

    extraConfig = mkOption {
      type = types.lines;
      default = "";
      description = ''
        Extra lines added to <filename>aria2.conf</filename> file.
      '';
    };
  };

  config = mkIf cfg.enable {
    home.packages = [ pkgs.aria2 ];

    xdg.configFile."aria2/aria2.conf".text = concatStringsSep "\n" ([ ]
      ++ mapAttrsToList formatLine cfg.settings
      ++ optional (cfg.extraConfig != "") cfg.extraConfig);
  };
}