3
0
Fork 0
forked from mirrors/nixpkgs
nixpkgs/nixos/modules/services/networking/morty.nix
pennae 2e751c0772 treewide: automatically md-convert option descriptions
the conversion procedure is simple:

 - find all things that look like options, ie calls to either `mkOption`
   or `lib.mkOption` that take an attrset. remember the attrset as the
   option
 - for all options, find a `description` attribute who's value is not a
   call to `mdDoc` or `lib.mdDoc`
 - textually convert the entire value of the attribute to MD with a few
   simple regexes (the set from mdize-module.sh)
 - if the change produced a change in the manual output, discard
 - if the change kept the manual unchanged, add some text to the
   description to make sure we've actually found an option. if the
   manual changes this time, keep the converted description

this procedure converts 80% of nixos options to markdown. around 2000
options remain to be inspected, but most of those fail the "does not
change the manual output check": currently the MD conversion process
does not faithfully convert docbook tags like <code> and <package>, so
any option using such tags will not be converted at all.
2022-07-30 15:16:34 +02:00

99 lines
2.3 KiB
Nix

{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.services.morty;
in
{
###### interface
options = {
services.morty = {
enable = mkEnableOption
"Morty proxy server. See https://github.com/asciimoo/morty";
ipv6 = mkOption {
type = types.bool;
default = true;
description = lib.mdDoc "Allow IPv6 HTTP requests?";
};
key = mkOption {
type = types.str;
default = "";
description = lib.mdDoc ''
HMAC url validation key (hexadecimal encoded).
Leave blank to disable. Without validation key, anyone can
submit proxy requests. Leave blank to disable.
Generate with `printf %s somevalue | openssl dgst -sha1 -hmac somekey`
'';
};
timeout = mkOption {
type = types.int;
default = 2;
description = lib.mdDoc "Request timeout in seconds.";
};
package = mkOption {
type = types.package;
default = pkgs.morty;
defaultText = literalExpression "pkgs.morty";
description = lib.mdDoc "morty package to use.";
};
port = mkOption {
type = types.int;
default = 3000;
description = lib.mdDoc "Listing port";
};
listenAddress = mkOption {
type = types.str;
default = "127.0.0.1";
description = lib.mdDoc "The address on which the service listens";
};
};
};
###### Service definition
config = mkIf config.services.morty.enable {
users.users.morty =
{ description = "Morty user";
createHome = true;
home = "/var/lib/morty";
isSystemUser = true;
group = "morty";
};
users.groups.morty = {};
systemd.services.morty =
{
description = "Morty sanitizing proxy server.";
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
serviceConfig = {
User = "morty";
ExecStart = ''${cfg.package}/bin/morty \
-listen ${cfg.listenAddress}:${toString cfg.port} \
${optionalString cfg.ipv6 "-ipv6"} \
${optionalString (cfg.key != "") "-key " + cfg.key} \
'';
};
};
environment.systemPackages = [ cfg.package ];
};
}