diff --git a/cli/yt-dlp.nix b/cli/yt-dlp.nix index f998787..90126db 100644 --- a/cli/yt-dlp.nix +++ b/cli/yt-dlp.nix @@ -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" + default = { + no-write-auto-subs = true; + sub-langs = [ + "all" + "-live_chat" + ]; - "--paths=temp:/tmp" - ]; + 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; }; }