at 16.09-beta 2.0 kB view raw
1{ config, lib, pkgs, ... }: 2 3with lib; 4 5let 6 cfg = config.services.fcgiwrap; 7in { 8 9 options = { 10 services.fcgiwrap = { 11 enable = mkOption { 12 type = types.bool; 13 default = false; 14 description = "Whether to enable fcgiwrap, a server for running CGI applications over FastCGI."; 15 }; 16 17 preforkProcesses = mkOption { 18 type = types.int; 19 default = 1; 20 description = "Number of processes to prefork."; 21 }; 22 23 socketType = mkOption { 24 type = types.addCheck types.str (t: t == "unix" || t == "tcp" || t == "tcp6"); 25 default = "unix"; 26 description = "Socket type: 'unix', 'tcp' or 'tcp6'."; 27 }; 28 29 socketAddress = mkOption { 30 type = types.str; 31 default = "/run/fcgiwrap.sock"; 32 example = "1.2.3.4:5678"; 33 description = "Socket address. In case of a UNIX socket, this should be its filesystem path."; 34 }; 35 36 user = mkOption { 37 type = types.nullOr types.str; 38 default = null; 39 description = "User permissions for the socket."; 40 }; 41 42 group = mkOption { 43 type = types.nullOr types.str; 44 default = null; 45 description = "Group permissions for the socket."; 46 }; 47 }; 48 }; 49 50 config = mkIf cfg.enable { 51 systemd.services.fcgiwrap = { 52 after = [ "nss-user-lookup.target" ]; 53 wantedBy = optional (cfg.socketType != "unix") "multi-user.target"; 54 55 serviceConfig = { 56 ExecStart = "${pkgs.fcgiwrap}/sbin/fcgiwrap -c ${builtins.toString cfg.preforkProcesses} ${ 57 if (cfg.socketType != "unix") then "-s ${cfg.socketType}:${cfg.socketAddress}" else "" 58 }"; 59 } // (if cfg.user != null && cfg.group != null then { 60 User = cfg.user; 61 Group = cfg.group; 62 } else { } ); 63 }; 64 65 systemd.sockets = if (cfg.socketType == "unix") then { 66 fcgiwrap = { 67 wantedBy = [ "sockets.target" ]; 68 socketConfig.ListenStream = cfg.socketAddress; 69 }; 70 } else { }; 71 }; 72}