at 18.09-beta 2.3 kB view raw
1{ config, lib, pkgs, ... }: 2 3with lib; 4 5let 6 7 cfg = config.services.morty; 8 9in 10 11{ 12 13 ###### interface 14 15 options = { 16 17 services.morty = { 18 19 enable = mkEnableOption 20 "Morty proxy server. See https://github.com/asciimoo/morty"; 21 22 ipv6 = mkOption { 23 type = types.bool; 24 default = true; 25 description = "Allow IPv6 HTTP requests?"; 26 defaultText = "Allow IPv6 HTTP requests."; 27 }; 28 29 key = mkOption { 30 type = types.string; 31 default = ""; 32 description = "HMAC url validation key (hexadecimal encoded). 33 Leave blank to disable. Without validation key, anyone can 34 submit proxy requests. Leave blank to disable."; 35 defaultText = "No HMAC url validation. Generate with echo -n somevalue | openssl dgst -sha1 -hmac somekey"; 36 }; 37 38 timeout = mkOption { 39 type = types.int; 40 default = 2; 41 description = "Request timeout in seconds."; 42 defaultText = "A resource now gets 2 seconds to respond."; 43 }; 44 45 package = mkOption { 46 type = types.package; 47 default = pkgs.morty; 48 defaultText = "pkgs.morty"; 49 description = "morty package to use."; 50 }; 51 52 port = mkOption { 53 type = types.int; 54 default = 3000; 55 description = "Listing port"; 56 }; 57 58 listenAddress = mkOption { 59 type = types.string; 60 default = "127.0.0.1"; 61 description = "The address on which the service listens"; 62 defaultText = "127.0.0.1 (localhost)"; 63 }; 64 65 }; 66 67 }; 68 69 ###### Service definition 70 71 config = mkIf config.services.morty.enable { 72 73 users.users.morty = 74 { description = "Morty user"; 75 createHome = true; 76 home = "/var/lib/morty"; 77 }; 78 79 systemd.services.morty = 80 { 81 description = "Morty sanitizing proxy server."; 82 after = [ "network.target" ]; 83 wantedBy = [ "multi-user.target" ]; 84 serviceConfig = { 85 User = "morty"; 86 ExecStart = ''${cfg.package}/bin/morty \ 87 -listen ${cfg.listenAddress}:${toString cfg.port} \ 88 ${optionalString cfg.ipv6 "-ipv6"} \ 89 ${optionalString (cfg.key != "") "-key " + cfg.key} \ 90 ''; 91 }; 92 }; 93 environment.systemPackages = [ cfg.package ]; 94 95 }; 96}