cli/yt-dlp: extraConfig -> settings, use attrs
This commit is contained in:
parent
202de6511f
commit
fed2b4f064
1 changed files with 57 additions and 13 deletions
|
|
@ -8,6 +8,38 @@
|
|||
let
|
||||
name = "yt-dlp";
|
||||
cfg = config.nixowos.cli.${name};
|
||||
|
||||
serialize =
|
||||
let
|
||||
serializeValue =
|
||||
value: prepend:
|
||||
if builtins.isBool value then
|
||||
""
|
||||
else
|
||||
prepend
|
||||
+ (
|
||||
if builtins.isString value then
|
||||
value
|
||||
else if builtins.isList value then
|
||||
builtins.concatStringsSep "," value
|
||||
else if builtins.isAttrs value then
|
||||
lib.concatMapAttrsStringSep "," (key: value: "${key}:${value}") value
|
||||
else
|
||||
abort "invalid ${name} config value: ${value}"
|
||||
);
|
||||
in
|
||||
|
||||
set:
|
||||
lib.strings.concatMapAttrsStringSep "\n" (
|
||||
key: value:
|
||||
if builtins.isBool value && !value then
|
||||
""
|
||||
else if builtins.stringLength key == 1 then
|
||||
"-${key}${serializeValue value ""}"
|
||||
else
|
||||
"--${key}${serializeValue value "="}"
|
||||
) set
|
||||
+ "\n";
|
||||
in
|
||||
{
|
||||
options.nixowos.cli.${name} = {
|
||||
|
|
@ -15,25 +47,37 @@ in
|
|||
|
||||
package = lib.mkPackageOption pkgs name { };
|
||||
|
||||
extraConfig = lib.mkOption {
|
||||
type = lib.types.listOf lib.types.str;
|
||||
description = "List of commandline arguments";
|
||||
default = [
|
||||
"--no-write-auto-subs"
|
||||
"--sub-langs=all,-live_chat"
|
||||
settings = lib.mkOption {
|
||||
type =
|
||||
with lib.types;
|
||||
attrsOf (oneOf [
|
||||
bool
|
||||
str
|
||||
(listOf str)
|
||||
(attrsOf str)
|
||||
]);
|
||||
|
||||
"--embed-subs"
|
||||
"--embed-metadata"
|
||||
"--embed-chapters"
|
||||
"--sponsorblock-mark=all"
|
||||
|
||||
"--paths=temp:/tmp"
|
||||
default = {
|
||||
no-write-auto-subs = true;
|
||||
sub-langs = [
|
||||
"all"
|
||||
"-live_chat"
|
||||
];
|
||||
|
||||
embed-subs = true;
|
||||
embed-metadata = true;
|
||||
embed-chapters = true;
|
||||
sponsorblock-mark = "all";
|
||||
|
||||
paths = {
|
||||
"temp" = "/tmp";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
config = lib.mkIf cfg.enable {
|
||||
environment.systemPackages = [ cfg.package ];
|
||||
environment.etc."${name}.conf".text = builtins.concatStringsSep "\n" cfg.extraConfig;
|
||||
environment.etc."${name}.conf".text = serialize cfg.settings;
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue