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
|
2022-08-28 19:18:44 +00:00
|
|
|
(lib.mdDoc "Morty proxy server. See https://github.com/asciimoo/morty");
|
2018-05-30 16:13:16 +00:00
|
|
|
|
|
|
|
ipv6 = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc "Allow IPv6 HTTP requests?";
|
2018-05-30 16:13:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
key = mkOption {
|
2019-08-08 20:48:27 +00:00
|
|
|
type = types.str;
|
2018-05-30 16:13:16 +00:00
|
|
|
default = "";
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-11-22 07:23:53 +00:00
|
|
|
HMAC url validation key (hexadecimal encoded).
|
|
|
|
Leave blank to disable. Without validation key, anyone can
|
|
|
|
submit proxy requests. Leave blank to disable.
|
2022-07-28 21:19:15 +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;
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc "Request timeout in seconds.";
|
2018-05-30 16:13:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.morty;
|
2021-10-03 16:06:03 +00:00
|
|
|
defaultText = literalExpression "pkgs.morty";
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc "morty package to use.";
|
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;
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc "Listing port";
|
2018-05-30 16:13:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
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";
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc "The address on which the service listens";
|
2018-05-30 16:13:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
###### 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 ];
|
|
|
|
|
|
|
|
};
|
|
|
|
}
|