nixpkgs/nixos/modules/services/networking/morty.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

99 lines
2.3 KiB
Nix
Raw Normal View History

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
(lib.mdDoc "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;
2018-05-30 16:13:16 +00:00
default = "";
2020-11-22 07:23:53 +00:00
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`
2020-11-22 07:23:53 +00:00
'';
2018-05-30 16:13:16 +00:00
};
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";
2018-05-30 16:13:16 +00:00
description = lib.mdDoc "morty package to use.";
};
port = mkOption {
type = types.port;
2018-05-30 16:13:16 +00:00
default = 3000;
description = lib.mdDoc "Listing port";
};
listenAddress = mkOption {
type = types.str;
2018-05-30 16:13:16 +00:00
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 =
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;
group = "morty";
2018-05-30 16:13:16 +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 ];
};
}