fork/home-manager

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

Robert HelgessonMerge PR #421575790441

master
1.9 KiB76 linesraw
1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6
7  cfg = config.programs.yt-dlp;
8
9  renderSettings = mapAttrsToList (name: value:
10    if isBool value then
11      if value then "--${name}" else "--no-${name}"
12    else
13      "--${name} ${toString value}");
14
15in {
16  meta.maintainers = [ ];
17
18  options.programs.yt-dlp = {
19    enable = mkEnableOption "yt-dlp";
20
21    package = mkOption {
22      type = types.package;
23      default = pkgs.yt-dlp;
24      defaultText = literalExpression "pkgs.yt-dlp";
25      description = "Package providing the {command}`yt-dlp` tool.";
26    };
27
28    settings = mkOption {
29      type = with types; attrsOf (oneOf [ bool int str ]);
30      default = { };
31      example = literalExpression ''
32        {
33          embed-thumbnail = true;
34          embed-subs = true;
35          sub-langs = "all";
36          downloader = "aria2c";
37          downloader-args = "aria2c:'-c -x8 -s8 -k1M'";
38        }
39      '';
40      description = ''
41        Configuration written to
42        {file}`$XDG_CONFIG_HOME/yt-dlp/config`.
43
44        Options must be specified in their "long form", for
45        example, `update = true;` instead of `U = true;`.
46        Short options can be specified in the `extraConfig` option.
47        See <https://github.com/yt-dlp/yt-dlp#configuration>
48        for explanation about possible values.
49      '';
50    };
51
52    extraConfig = mkOption {
53      type = types.lines;
54      default = "";
55      example = ''
56        --update
57        -F
58      '';
59      description = ''
60        Extra configuration to add to
61        {file}`$XDG_CONFIG_HOME/yt-dlp/config`.
62      '';
63    };
64  };
65
66  config = mkIf cfg.enable {
67    home.packages = [ cfg.package ];
68
69    xdg.configFile."yt-dlp/config" =
70      mkIf (cfg.settings != { } || cfg.extraConfig != "") {
71        text = concatStringsSep "\n"
72          (remove "" (renderSettings cfg.settings ++ [ cfg.extraConfig ]))
73          + "\n";
74      };
75  };
76}