at 25.11-pre 3.3 kB view raw
1{ 2 config, 3 lib, 4 pkgs, 5 ... 6}: 7let 8 cfg = config.services.invidious-router; 9 settingsFormat = pkgs.formats.yaml { }; 10 configFile = settingsFormat.generate "config.yaml" cfg.settings; 11in 12{ 13 meta.maintainers = [ lib.maintainers.sils ]; 14 15 options.services.invidious-router = { 16 enable = lib.mkEnableOption "the invidious-router service"; 17 port = lib.mkOption { 18 type = lib.types.port; 19 default = 8050; 20 description = '' 21 Port to bind to. 22 ''; 23 }; 24 address = lib.mkOption { 25 type = lib.types.str; 26 default = "127.0.0.1"; 27 description = '' 28 Address on which invidious-router should listen on. 29 ''; 30 }; 31 settings = lib.mkOption { 32 type = lib.types.submodule { 33 freeformType = settingsFormat.type; 34 }; 35 default = { 36 app = { 37 listen = "127.0.0.1:8050"; 38 enable_youtube_fallback = false; 39 reload_instance_list_interval = "60s"; 40 }; 41 api = { 42 enabled = true; 43 url = "https://api.invidious.io/instances.json"; 44 filter_regions = true; 45 allowed_regions = [ 46 "AT" 47 "DE" 48 "CH" 49 ]; 50 }; 51 healthcheck = { 52 path = "/"; 53 allowed_status_codes = [ 54 200 55 ]; 56 timeout = "1s"; 57 interval = "10s"; 58 filter_by_response_time = { 59 enabled = true; 60 qty_of_top_results = 3; 61 }; 62 minimum_ratio = 0.2; 63 remove_no_ratio = true; 64 text_not_present = "YouTube is currently trying to block Invidious instances"; 65 }; 66 }; 67 description = '' 68 Configuration for invidious-router. 69 Check <https://gitlab.com/gaincoder/invidious-router#configuration> 70 for configuration options. 71 ''; 72 }; 73 package = lib.mkOption { 74 type = lib.types.package; 75 default = pkgs.invidious-router; 76 defaultText = lib.literalExpression "pkgs.invidious-router"; 77 description = '' 78 The invidious-router package to use. 79 ''; 80 }; 81 nginx = { 82 enable = lib.mkEnableOption '' 83 Automatic nginx proxy configuration 84 ''; 85 domain = lib.mkOption { 86 type = lib.types.str; 87 example = "invidious-router.example.com"; 88 description = '' 89 The domain on which invidious-router should be served. 90 ''; 91 }; 92 extraDomains = lib.mkOption { 93 type = lib.types.listOf lib.types.str; 94 default = [ ]; 95 description = '' 96 Additional domains to serve invidious-router on. 97 ''; 98 }; 99 }; 100 }; 101 config = lib.mkIf cfg.enable { 102 systemd.services.invidious-router = { 103 wantedBy = [ "multi-user.target" ]; 104 serviceConfig = { 105 Restart = "on-failure"; 106 ExecStart = "${lib.getExe cfg.package} --configfile ${configFile}"; 107 DynamicUser = "yes"; 108 }; 109 }; 110 111 services.nginx.virtualHosts = lib.mkIf cfg.nginx.enable { 112 ${cfg.nginx.domain} = { 113 locations."/" = { 114 recommendedProxySettings = true; 115 proxyPass = "http://${cfg.address}:${toString cfg.port}"; 116 }; 117 enableACME = true; 118 forceSSL = true; 119 serverAliases = cfg.nginx.extraDomains; 120 }; 121 }; 122 }; 123}