lol

nixos/stargazer: fix route ordering

authored by

gaykitty and committed by
Anderson Torres
d4f3dd4f 3c5e8175

+58 -27
+53 -23
nixos/modules/services/web-servers/stargazer.nix
··· 4 4 5 5 let 6 6 cfg = config.services.stargazer; 7 - routesFormat = pkgs.formats.ini { }; 8 - globalFile = pkgs.writeText "global.ini" '' 9 - listen = ${concatStringsSep " " cfg.listen} 10 - connection-logging = ${boolToString cfg.connectionLogging} 11 - log-ip = ${boolToString cfg.ipLog} 12 - log-ip-partial = ${boolToString cfg.ipLogPartial} 7 + globalSection = '' 8 + listen = ${lib.concatStringsSep " " cfg.listen} 9 + connection-logging = ${lib.boolToString cfg.connectionLogging} 10 + log-ip = ${lib.boolToString cfg.ipLog} 11 + log-ip-partial = ${lib.boolToString cfg.ipLogPartial} 13 12 request-timeout = ${toString cfg.requestTimeout} 14 13 response-timeout = ${toString cfg.responseTimeout} 15 14 ··· 21 20 ${optionalString (cfg.certLifetime != "") "cert-lifetime = ${cfg.certLifetime}"} 22 21 23 22 ''; 24 - routesFile = routesFormat.generate "router.ini" cfg.routes; 25 - configFile = pkgs.runCommand "config.ini" { } '' 26 - cat ${globalFile} ${routesFile} > $out 27 - ''; 23 + genINI = lib.generators.toINI { }; 24 + configFile = pkgs.writeText "config.ini" (lib.strings.concatStrings ( 25 + [ globalSection ] ++ (lib.lists.forEach cfg.routes (section: 26 + let 27 + name = section.route; 28 + params = builtins.removeAttrs section [ "route" ]; 29 + in 30 + genINI 31 + { 32 + "${name}" = params; 33 + } + "\n" 34 + )) 35 + )); 28 36 in 29 37 { 30 38 options.services.stargazer = { ··· 124 132 }; 125 133 126 134 routes = lib.mkOption { 127 - type = routesFormat.type; 128 - default = { }; 135 + type = lib.types.listOf 136 + (lib.types.submodule { 137 + freeformType = with lib.types; attrsOf (nullOr 138 + (oneOf [ 139 + bool 140 + int 141 + float 142 + str 143 + ]) // { 144 + description = "INI atom (null, bool, int, float or string)"; 145 + }); 146 + options.route = lib.mkOption { 147 + type = lib.types.str; 148 + description = lib.mdDoc "Route section name"; 149 + }; 150 + }); 151 + default = [ ]; 129 152 description = lib.mdDoc '' 130 153 Routes that Stargazer should server. 131 154 132 - [Refer to upstream docs](https://git.sr.ht/~zethra/stargazer/tree/main/item/doc/stargazer.ini.5.txt) 155 + Expressed as a list of attribute sets. Each set must have a key `route` 156 + that becomes the section name for that route in the stargazer ini cofig. 157 + The remaining keys and vaules become the parameters for that route. 158 + 159 + [Refer to upstream docs for other params](https://git.sr.ht/~zethra/stargazer/tree/main/item/doc/stargazer.ini.5.txt) 133 160 ''; 134 - example = literalExpression '' 135 - { 136 - "example.com" = { 137 - root = "/srv/gemini/example.com"; 138 - }; 139 - "example.com:/man" = { 161 + example = lib.literalExpression '' 162 + [ 163 + { 164 + route = "example.com"; 165 + root = "/srv/gemini/example.com" 166 + } 167 + { 168 + route = "example.com:/man"; 140 169 root = "/cgi-bin"; 141 170 cgi = true; 142 - }; 143 - "other.org~(.*)" = { 171 + } 172 + { 173 + route = "other.org~(.*)"; 144 174 redirect = "gemini://example.com"; 145 175 rewrite = "\1"; 146 - }; 147 - } 176 + } 177 + ] 148 178 ''; 149 179 }; 150 180
+5 -4
nixos/tests/web-servers/stargazer.nix
··· 7 7 geminiserver = { pkgs, ... }: { 8 8 services.stargazer = { 9 9 enable = true; 10 - routes = { 11 - "localhost" = { 10 + routes = [ 11 + { 12 + route = "localhost"; 12 13 root = toString (pkgs.writeTextDir "index.gmi" '' 13 14 # Hello NixOS! 14 15 ''); 15 - }; 16 - }; 16 + } 17 + ]; 17 18 }; 18 19 }; 19 20 };