fork/home-manager

git clone https://git.julia.blue/fork/home-manager

Robert HelgessonMerge PR #421575790441

master
1.3 KiB58 linesraw
1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6  cfg = config.programs.aria2;
7
8  formatLine = n: v:
9    let
10      formatValue = v:
11        if builtins.isBool v then
12          (if v then "true" else "false")
13        else
14          toString v;
15    in "${n}=${formatValue v}";
16in {
17  meta.maintainers = [ hm.maintainers.justinlovinger ];
18
19  options.programs.aria2 = {
20    enable = mkEnableOption "aria2";
21
22    settings = mkOption {
23      type = with types; attrsOf (oneOf [ bool float int str ]);
24      default = { };
25      description = ''
26        Options to add to {file}`aria2.conf` file.
27        See
28        {manpage}`aria2c(1)`
29        for options.
30      '';
31      example = literalExpression ''
32        {
33          listen-port = 60000;
34          dht-listen-port = 60000;
35          seed-ratio = 1.0;
36          max-upload-limit = "50K";
37          ftp-pasv = true;
38        }
39      '';
40    };
41
42    extraConfig = mkOption {
43      type = types.lines;
44      default = "";
45      description = ''
46        Extra lines added to {file}`aria2.conf` file.
47      '';
48    };
49  };
50
51  config = mkIf cfg.enable {
52    home.packages = [ pkgs.aria2 ];
53
54    xdg.configFile."aria2/aria2.conf".text = concatStringsSep "\n" ([ ]
55      ++ mapAttrsToList formatLine cfg.settings
56      ++ optional (cfg.extraConfig != "") cfg.extraConfig);
57  };
58}