8 cfg = config.services.simplesamlphp;
10 format = pkgs.formats.php { finalVariable = "config"; };
14 pkgs.runCommand "simplesamlphp-config" { } ''
16 cp ${format.generate "config.php" opts.settings} $out/config.php
17 cp ${format.generate "authsources.php" opts.authSources} $out/authsources.php
22 maintainers = with lib.maintainers; [ nhnn ];
25 options.services.simplesamlphp =
28 type = types.attrsOf (
33 package = mkPackageOption pkgs "simplesamlphp" { };
34 configureNginx = mkOption {
37 description = "Configure nginx as a reverse proxy for SimpleSAMLphp.";
39 phpfpmPool = mkOption {
41 description = "The PHP-FPM pool that serves SimpleSAMLphp instance.";
43 localDomain = mkOption {
45 description = "The domain serving your SimpleSAMLphp instance. This option modifies only /saml route.";
48 type = types.submodule {
49 freeformType = format.type;
51 baseurlpath = mkOption {
53 example = "https://filesender.example.com/saml/";
54 description = "URL where SimpleSAMLphp can be reached.";
60 Configuration options used by SimpleSAMLphp.
61 See [](https://simplesamlphp.org/docs/stable/simplesamlphp-install)
62 for available options.
66 authSources = mkOption {
70 Auth sources options used by SimpleSAMLphp.
78 Path to the SimpleSAMLphp library directory.
81 configDir = mkOption {
85 Path to the SimpleSAMLphp config directory.
90 libDir = "${config.package}/share/php/simplesamlphp/";
91 configDir = "${generateConfig config}";
97 description = "Instances of SimpleSAMLphp. This module is designed to work with already existing PHP-FPM pool and NGINX virtualHost.";
101 services.phpfpm.pools = lib.mapAttrs' (
103 lib.nameValuePair opts.phpfpmPool { phpEnv.SIMPLESAMLPHP_CONFIG_DIR = "${generateConfig opts}"; }
106 services.nginx.virtualHosts = lib.mapAttrs' (
108 lib.nameValuePair opts.localDomain (
109 lib.mkIf opts.configureNginx {
110 locations."^~ /saml/" = {
111 alias = "${opts.package}/share/php/simplesamlphp/www/";
113 location ~ ^(?<prefix>/saml)(?<phpfile>.+?\.php)(?<pathinfo>/.*)?$ {
114 include ${pkgs.nginx}/conf/fastcgi.conf;
115 fastcgi_split_path_info ^(.+\.php)(/.+)$;
116 fastcgi_pass unix:${config.services.phpfpm.pools.${phpfpmName}.socket};
117 fastcgi_intercept_errors on;
118 fastcgi_param SCRIPT_FILENAME $document_root$phpfile;
119 fastcgi_param SCRIPT_NAME /saml$phpfile;
120 fastcgi_param PATH_INFO $pathinfo if_not_empty;