nixos/stargazer: fix route ordering

gaykitty d4f3dd4f 3c5e8175

Changed files
+58 -27
nixos
modules
services
web-servers
tests
web-servers
+53 -23
nixos/modules/services/web-servers/stargazer.nix
···
let
cfg = config.services.stargazer;
-
routesFormat = pkgs.formats.ini { };
-
globalFile = pkgs.writeText "global.ini" ''
-
listen = ${concatStringsSep " " cfg.listen}
-
connection-logging = ${boolToString cfg.connectionLogging}
-
log-ip = ${boolToString cfg.ipLog}
-
log-ip-partial = ${boolToString cfg.ipLogPartial}
request-timeout = ${toString cfg.requestTimeout}
response-timeout = ${toString cfg.responseTimeout}
···
${optionalString (cfg.certLifetime != "") "cert-lifetime = ${cfg.certLifetime}"}
'';
-
routesFile = routesFormat.generate "router.ini" cfg.routes;
-
configFile = pkgs.runCommand "config.ini" { } ''
-
cat ${globalFile} ${routesFile} > $out
-
'';
in
{
options.services.stargazer = {
···
};
routes = lib.mkOption {
-
type = routesFormat.type;
-
default = { };
description = lib.mdDoc ''
Routes that Stargazer should server.
-
[Refer to upstream docs](https://git.sr.ht/~zethra/stargazer/tree/main/item/doc/stargazer.ini.5.txt)
'';
-
example = literalExpression ''
-
{
-
"example.com" = {
-
root = "/srv/gemini/example.com";
-
};
-
"example.com:/man" = {
root = "/cgi-bin";
cgi = true;
-
};
-
"other.org~(.*)" = {
redirect = "gemini://example.com";
rewrite = "\1";
-
};
-
}
'';
};
···
let
cfg = config.services.stargazer;
+
globalSection = ''
+
listen = ${lib.concatStringsSep " " cfg.listen}
+
connection-logging = ${lib.boolToString cfg.connectionLogging}
+
log-ip = ${lib.boolToString cfg.ipLog}
+
log-ip-partial = ${lib.boolToString cfg.ipLogPartial}
request-timeout = ${toString cfg.requestTimeout}
response-timeout = ${toString cfg.responseTimeout}
···
${optionalString (cfg.certLifetime != "") "cert-lifetime = ${cfg.certLifetime}"}
'';
+
genINI = lib.generators.toINI { };
+
configFile = pkgs.writeText "config.ini" (lib.strings.concatStrings (
+
[ globalSection ] ++ (lib.lists.forEach cfg.routes (section:
+
let
+
name = section.route;
+
params = builtins.removeAttrs section [ "route" ];
+
in
+
genINI
+
{
+
"${name}" = params;
+
} + "\n"
+
))
+
));
in
{
options.services.stargazer = {
···
};
routes = lib.mkOption {
+
type = lib.types.listOf
+
(lib.types.submodule {
+
freeformType = with lib.types; attrsOf (nullOr
+
(oneOf [
+
bool
+
int
+
float
+
str
+
]) // {
+
description = "INI atom (null, bool, int, float or string)";
+
});
+
options.route = lib.mkOption {
+
type = lib.types.str;
+
description = lib.mdDoc "Route section name";
+
};
+
});
+
default = [ ];
description = lib.mdDoc ''
Routes that Stargazer should server.
+
Expressed as a list of attribute sets. Each set must have a key `route`
+
that becomes the section name for that route in the stargazer ini cofig.
+
The remaining keys and vaules become the parameters for that route.
+
+
[Refer to upstream docs for other params](https://git.sr.ht/~zethra/stargazer/tree/main/item/doc/stargazer.ini.5.txt)
'';
+
example = lib.literalExpression ''
+
[
+
{
+
route = "example.com";
+
root = "/srv/gemini/example.com"
+
}
+
{
+
route = "example.com:/man";
root = "/cgi-bin";
cgi = true;
+
}
+
{
+
route = "other.org~(.*)";
redirect = "gemini://example.com";
rewrite = "\1";
+
}
+
]
'';
};
+5 -4
nixos/tests/web-servers/stargazer.nix
···
geminiserver = { pkgs, ... }: {
services.stargazer = {
enable = true;
-
routes = {
-
"localhost" = {
root = toString (pkgs.writeTextDir "index.gmi" ''
# Hello NixOS!
'');
-
};
-
};
};
};
};
···
geminiserver = { pkgs, ... }: {
services.stargazer = {
enable = true;
+
routes = [
+
{
+
route = "localhost";
root = toString (pkgs.writeTextDir "index.gmi" ''
# Hello NixOS!
'');
+
}
+
];
};
};
};