aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Lovinger <git@justinlovinger.com>2020-04-28 14:38:41 -0400
committerRobert Helgesson <robert@rycee.net>2020-05-03 13:21:52 +0200
commit1dd226fde7e50d6e7a6de5b9ceb3ef1a7808b056 (patch)
tree754d7db05e90b6901a9ca810d33f14dc048345a3
parentded327b9fc4a10bd77265a077a2880c1b5b87567 (diff)
aria2: add module
PR #1202
-rw-r--r--.github/CODEOWNERS2
-rw-r--r--modules/misc/news.nix7
-rw-r--r--modules/modules.nix1
-rw-r--r--modules/programs/aria2.nix61
-rw-r--r--tests/default.nix1
-rw-r--r--tests/modules/programs/aria2/default.nix1
-rw-r--r--tests/modules/programs/aria2/settings.nix41
7 files changed, 114 insertions, 0 deletions
diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS
index 98d2957abab..b31ef883c30 100644
--- a/.github/CODEOWNERS
+++ b/.github/CODEOWNERS
@@ -22,6 +22,8 @@
/modules/misc/xdg-user-dirs.nix @pacien
+/modules/programs/aria2.nix @JustinLovinger
+
/modules/programs/autorandr.nix @uvNikita
/modules/programs/bash.nix @rycee
diff --git a/modules/misc/news.nix b/modules/misc/news.nix
index 2be9b701c1e..9cfdb572eaf 100644
--- a/modules/misc/news.nix
+++ b/modules/misc/news.nix
@@ -1496,6 +1496,13 @@ in
A new module is available: 'programs.i3status'
'';
}
+
+ {
+ time = "2020-05-03T11:21:42+00:00";
+ message = ''
+ A new module is available: 'programs.aria2'
+ '';
+ }
];
};
}
diff --git a/modules/modules.nix b/modules/modules.nix
index f01975e9178..ae114857a61 100644
--- a/modules/modules.nix
+++ b/modules/modules.nix
@@ -45,6 +45,7 @@ let
(loadModule ./programs/afew.nix { })
(loadModule ./programs/alacritty.nix { })
(loadModule ./programs/alot.nix { })
+ (loadModule ./programs/aria2.nix { })
(loadModule ./programs/astroid.nix { })
(loadModule ./programs/autorandr.nix { })
(loadModule ./programs/bash.nix { })
diff --git a/modules/programs/aria2.nix b/modules/programs/aria2.nix
new file mode 100644
index 00000000000..d1317ff7616
--- /dev/null
+++ b/modules/programs/aria2.nix
@@ -0,0 +1,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);
+ };
+}
diff --git a/tests/default.nix b/tests/default.nix
index c6dcecbeae0..f63f8f0cf05 100644
--- a/tests/default.nix
+++ b/tests/default.nix
@@ -36,6 +36,7 @@ import nmt {
./modules/misc/fontconfig
./modules/programs/alacritty
./modules/programs/alot
+ ./modules/programs/aria2
./modules/programs/bash
./modules/programs/browserpass
./modules/programs/fish
diff --git a/tests/modules/programs/aria2/default.nix b/tests/modules/programs/aria2/default.nix
new file mode 100644
index 00000000000..2964841d098
--- /dev/null
+++ b/tests/modules/programs/aria2/default.nix
@@ -0,0 +1 @@
+{ aria2-settings = ./settings.nix; }
diff --git a/tests/modules/programs/aria2/settings.nix b/tests/modules/programs/aria2/settings.nix
new file mode 100644
index 00000000000..0b5a52d90c5
--- /dev/null
+++ b/tests/modules/programs/aria2/settings.nix
@@ -0,0 +1,41 @@
+{ config, lib, pkgs, ... }:
+
+with lib;
+
+{
+ config = {
+ programs.aria2 = {
+ enable = true;
+
+ settings = {
+ listen-port = 60000;
+ dht-listen-port = 60000;
+ seed-ratio = 1.0;
+ max-upload-limit = "50K";
+ ftp-pasv = true;
+ };
+
+ extraConfig = ''
+ # Extra aria2 configuration.
+ '';
+ };
+
+ nixpkgs.overlays =
+ [ (self: super: { aria2 = pkgs.writeScriptBin "dummy-aria2" ""; }) ];
+
+ nmt.script = ''
+ assertFileContent \
+ home-files/.config/aria2/aria2.conf \
+ ${
+ pkgs.writeText "aria2-expected-config.conf" ''
+ dht-listen-port=60000
+ ftp-pasv=true
+ listen-port=60000
+ max-upload-limit=50K
+ seed-ratio=1.000000
+ # Extra aria2 configuration.
+ ''
+ }
+ '';
+ };
+}