2018-05-30 16:13:16 +00:00
|
|
|
{ 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 = "Allow IPv6 HTTP requests?";
|
|
|
|
};
|
|
|
|
|
|
|
|
key = mkOption {
|
2019-08-08 20:48:27 +00:00
|
|
|
type = types.str;
|
2018-05-30 16:13:16 +00:00
|
|
|
default = "";
|
2020-11-22 07:23:53 +00:00
|
|
|
description = ''
|
|
|
|
HMAC url validation key (hexadecimal encoded).
|
|
|
|
Leave blank to disable. Without validation key, anyone can
|
|
|
|
submit proxy requests. Leave blank to disable.
|
2021-10-03 16:06:03 +00:00
|
|
|
Generate with `printf %s somevalue | openssl dgst -sha1 -hmac somekey`
|
2020-11-22 07:23:53 +00:00
|
|
|
'';
|
2018-05-30 16:13:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
timeout = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = 2;
|
|
|
|
description = "Request timeout in seconds.";
|
|
|
|
};
|
|
|
|
|
2023-11-27 00:19:27 +00:00
|
|
|
package = mkPackageOption pkgs "morty" { };
|
2018-05-30 16:13:16 +00:00
|
|
|
|
|
|
|
port = mkOption {
|
2022-11-30 16:15:00 +00:00
|
|
|
type = types.port;
|
2018-05-30 16:13:16 +00:00
|
|
|
default = 3000;
|
|
|
|
description = "Listing port";
|
|
|
|
};
|
|
|
|
|
|
|
|
listenAddress = mkOption {
|
2019-08-08 20:48:27 +00:00
|
|
|
type = types.str;
|
2018-05-30 16:13:16 +00:00
|
|
|
default = "127.0.0.1";
|
|
|
|
description = "The address on which the service listens";
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
###### Service definition
|
|
|
|
|
|
|
|
config = mkIf config.services.morty.enable {
|
|
|
|
|
2018-06-29 23:58:35 +00:00
|
|
|
users.users.morty =
|
2018-05-30 16:13:16 +00:00
|
|
|
{ description = "Morty user";
|
|
|
|
createHome = true;
|
|
|
|
home = "/var/lib/morty";
|
2019-10-12 20:25:28 +00:00
|
|
|
isSystemUser = true;
|
2021-08-08 12:00:00 +00:00
|
|
|
group = "morty";
|
2018-05-30 16:13:16 +00:00
|
|
|
};
|
2021-08-08 12:00:00 +00:00
|
|
|
users.groups.morty = {};
|
2018-05-30 16:13:16 +00:00
|
|
|
|
|
|
|
systemd.services.morty =
|
|
|
|
{
|
|
|
|
description = "Morty sanitizing proxy server.";
|
|
|
|
after = [ "network.target" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
serviceConfig = {
|
|
|
|
User = "morty";
|
|
|
|
ExecStart = ''${cfg.package}/bin/morty \
|
2020-11-22 07:23:53 +00:00
|
|
|
-listen ${cfg.listenAddress}:${toString cfg.port} \
|
|
|
|
${optionalString cfg.ipv6 "-ipv6"} \
|
|
|
|
${optionalString (cfg.key != "") "-key " + cfg.key} \
|
|
|
|
'';
|
2018-05-30 16:13:16 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
environment.systemPackages = [ cfg.package ];
|
|
|
|
|
|
|
|
};
|
|
|
|
}
|