diff options
Diffstat (limited to 'modules/private/websites/ludivinecassal')
-rw-r--r-- | modules/private/websites/ludivinecassal/builder.nix | 155 | ||||
-rw-r--r-- | modules/private/websites/ludivinecassal/integration.nix | 32 | ||||
-rw-r--r-- | modules/private/websites/ludivinecassal/production.nix | 33 |
3 files changed, 220 insertions, 0 deletions
diff --git a/modules/private/websites/ludivinecassal/builder.nix b/modules/private/websites/ludivinecassal/builder.nix new file mode 100644 index 00000000..3167bce7 --- /dev/null +++ b/modules/private/websites/ludivinecassal/builder.nix | |||
@@ -0,0 +1,155 @@ | |||
1 | { apacheUser, apacheGroup, config, ludivinecassal, pkgs, ruby, sass, imagemagick }: | ||
2 | rec { | ||
3 | app = ludivinecassal.override { inherit (config) environment; }; | ||
4 | varDir = "/var/lib/ludivinecassal_${app.environment}"; | ||
5 | keys = [{ | ||
6 | dest = "webapps/${app.environment}-ludivinecassal"; | ||
7 | user = apacheUser; | ||
8 | group = apacheGroup; | ||
9 | permissions = "0400"; | ||
10 | text = '' | ||
11 | # This file is auto-generated during the composer install | ||
12 | parameters: | ||
13 | database_host: ${config.mysql.host} | ||
14 | database_port: ${config.mysql.port} | ||
15 | database_name: ${config.mysql.name} | ||
16 | database_user: ${config.mysql.user} | ||
17 | database_password: ${config.mysql.password} | ||
18 | database_server_version: ${pkgs.mariadb.mysqlVersion} | ||
19 | mailer_transport: smtp | ||
20 | mailer_host: 127.0.0.1 | ||
21 | mailer_user: null | ||
22 | mailer_password: null | ||
23 | secret: ${config.secret} | ||
24 | ldap_host: ldap.immae.eu | ||
25 | ldap_port: 636 | ||
26 | ldap_version: 3 | ||
27 | ldap_ssl: true | ||
28 | ldap_tls: false | ||
29 | ldap_user_bind: 'uid={username},ou=users,dc=immae,dc=eu' | ||
30 | ldap_base_dn: 'dc=immae,dc=eu' | ||
31 | ldap_search_dn: '${config.ldap.dn}' | ||
32 | ldap_search_password: '${config.ldap.password}' | ||
33 | ldap_search_filter: '${config.ldap.search}' | ||
34 | leapt_im: | ||
35 | binary_path: ${imagemagick}/bin | ||
36 | assetic: | ||
37 | sass: ${sass}/bin/sass | ||
38 | ruby: ${ruby}/bin/ruby | ||
39 | ''; | ||
40 | }]; | ||
41 | phpFpm = rec { | ||
42 | preStart = '' | ||
43 | if [ ! -f "${app.varDir}/currentWebappDir" -o \ | ||
44 | ! -f "${app.varDir}/currentKey" -o \ | ||
45 | "${app}" != "$(cat ${app.varDir}/currentWebappDir 2>/dev/null)" ] \ | ||
46 | || ! sha512sum -c --status ${app.varDir}/currentKey; then | ||
47 | pushd ${app} > /dev/null | ||
48 | /run/wrappers/bin/sudo -u ${apacheUser} ./bin/console --env=${app.environment} cache:clear --no-warmup | ||
49 | popd > /dev/null | ||
50 | echo -n "${app}" > ${app.varDir}/currentWebappDir | ||
51 | sha512sum /var/secrets/webapps/${app.environment}-ludivinecassal > ${app.varDir}/currentKey | ||
52 | fi | ||
53 | ''; | ||
54 | serviceDeps = [ "mysql.service" ]; | ||
55 | socket = "/var/run/phpfpm/ludivinecassal-${app.environment}.sock"; | ||
56 | pool = '' | ||
57 | listen = ${socket} | ||
58 | user = ${apacheUser} | ||
59 | group = ${apacheGroup} | ||
60 | listen.owner = ${apacheUser} | ||
61 | listen.group = ${apacheGroup} | ||
62 | php_admin_value[upload_max_filesize] = 20M | ||
63 | php_admin_value[post_max_size] = 20M | ||
64 | ;php_admin_flag[log_errors] = on | ||
65 | php_admin_value[open_basedir] = "/var/secrets/webapps/${app.environment}-ludivinecassal:${app}:${app.varDir}:/tmp" | ||
66 | php_admin_value[session.save_path] = "${app.varDir}/phpSessions" | ||
67 | ${if app.environment == "dev" then '' | ||
68 | pm = ondemand | ||
69 | pm.max_children = 5 | ||
70 | pm.process_idle_timeout = 60 | ||
71 | env[SYMFONY_DEBUG_MODE] = "yes" | ||
72 | '' else '' | ||
73 | pm = dynamic | ||
74 | pm.max_children = 20 | ||
75 | pm.start_servers = 2 | ||
76 | pm.min_spare_servers = 1 | ||
77 | pm.max_spare_servers = 3 | ||
78 | ''}''; | ||
79 | }; | ||
80 | apache = rec { | ||
81 | modules = [ "proxy_fcgi" ]; | ||
82 | webappName = "ludivine_${app.environment}"; | ||
83 | root = "/run/current-system/webapps/${webappName}"; | ||
84 | vhostConf = '' | ||
85 | <FilesMatch "\.php$"> | ||
86 | SetHandler "proxy:unix:${phpFpm.socket}|fcgi://localhost" | ||
87 | </FilesMatch> | ||
88 | |||
89 | ${if app.environment == "dev" then '' | ||
90 | <Location /> | ||
91 | Use LDAPConnect | ||
92 | Require ldap-group cn=ludivine.immae.eu,cn=httpd,ou=services,dc=immae,dc=eu | ||
93 | ErrorDocument 401 "<html><meta http-equiv=\"refresh\" content=\"0;url=https://ludivinecassal.com\"></html>" | ||
94 | </Location> | ||
95 | |||
96 | <Directory ${root}> | ||
97 | Options Indexes FollowSymLinks MultiViews Includes | ||
98 | AllowOverride None | ||
99 | Require all granted | ||
100 | |||
101 | DirectoryIndex app_dev.php | ||
102 | |||
103 | <IfModule mod_negotiation.c> | ||
104 | Options -MultiViews | ||
105 | </IfModule> | ||
106 | |||
107 | <IfModule mod_rewrite.c> | ||
108 | RewriteEngine On | ||
109 | |||
110 | RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$ | ||
111 | RewriteRule ^(.*) - [E=BASE:%1] | ||
112 | |||
113 | # Maintenance script | ||
114 | RewriteCond %{DOCUMENT_ROOT}/maintenance.php -f | ||
115 | RewriteCond %{SCRIPT_FILENAME} !maintenance.php | ||
116 | RewriteRule ^.*$ %{ENV:BASE}/maintenance.php [R=503,L] | ||
117 | ErrorDocument 503 /maintenance.php | ||
118 | |||
119 | # Sets the HTTP_AUTHORIZATION header removed by Apache | ||
120 | RewriteCond %{HTTP:Authorization} . | ||
121 | RewriteRule ^ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] | ||
122 | |||
123 | RewriteCond %{ENV:REDIRECT_STATUS} ^$ | ||
124 | RewriteRule ^app_dev\.php(?:/(.*)|$) %{ENV:BASE}/$1 [R=301,L] | ||
125 | |||
126 | # If the requested filename exists, simply serve it. | ||
127 | # We only want to let Apache serve files and not directories. | ||
128 | RewriteCond %{REQUEST_FILENAME} -f | ||
129 | RewriteRule ^ - [L] | ||
130 | |||
131 | # Rewrite all other queries to the front controller. | ||
132 | RewriteRule ^ %{ENV:BASE}/app_dev.php [L] | ||
133 | </IfModule> | ||
134 | |||
135 | </Directory> | ||
136 | '' else '' | ||
137 | Use Stats ludivinecassal.com | ||
138 | |||
139 | <Directory ${root}> | ||
140 | Options Indexes FollowSymLinks MultiViews Includes | ||
141 | AllowOverride All | ||
142 | Require all granted | ||
143 | </Directory> | ||
144 | ''} | ||
145 | ''; | ||
146 | }; | ||
147 | activationScript = { | ||
148 | deps = [ "wrappers" ]; | ||
149 | text = '' | ||
150 | install -m 0755 -o ${apacheUser} -g ${apacheGroup} -d ${app.varDir} | ||
151 | install -m 0755 -o ${apacheUser} -g ${apacheGroup} -d ${app.varDir}/tmp | ||
152 | install -m 0750 -o ${apacheUser} -g ${apacheGroup} -d ${app.varDir}/phpSessions | ||
153 | ''; | ||
154 | }; | ||
155 | } | ||
diff --git a/modules/private/websites/ludivinecassal/integration.nix b/modules/private/websites/ludivinecassal/integration.nix new file mode 100644 index 00000000..ed0dc9fe --- /dev/null +++ b/modules/private/websites/ludivinecassal/integration.nix | |||
@@ -0,0 +1,32 @@ | |||
1 | { lib, pkgs, config, myconfig, ... }: | ||
2 | let | ||
3 | ludivinecassal = pkgs.callPackage ./builder.nix { | ||
4 | inherit (pkgs.webapps) ludivinecassal; | ||
5 | config = myconfig.env.websites.ludivinecassal.integration; | ||
6 | apacheUser = config.services.httpd.Inte.user; | ||
7 | apacheGroup = config.services.httpd.Inte.group; | ||
8 | }; | ||
9 | |||
10 | cfg = config.myServices.websites.ludivinecassal.integration; | ||
11 | in { | ||
12 | options.myServices.websites.ludivinecassal.integration.enable = lib.mkEnableOption "enable Ludivine's website in integration"; | ||
13 | |||
14 | config = lib.mkIf cfg.enable { | ||
15 | secrets.keys = ludivinecassal.keys; | ||
16 | |||
17 | systemd.services.phpfpm-ludivinecassal_dev.after = lib.mkAfter ludivinecassal.phpFpm.serviceDeps; | ||
18 | systemd.services.phpfpm-ludivinecassal_dev.wants = ludivinecassal.phpFpm.serviceDeps; | ||
19 | systemd.services.phpfpm-ludivinecassal_dev.preStart = lib.mkAfter ludivinecassal.phpFpm.preStart; | ||
20 | services.phpfpm.poolConfigs.ludivinecassal_dev = ludivinecassal.phpFpm.pool; | ||
21 | system.activationScripts.ludivinecassal_dev = ludivinecassal.activationScript; | ||
22 | myServices.websites.webappDirs."${ludivinecassal.apache.webappName}" = ludivinecassal.app.webRoot; | ||
23 | services.websites.integration.modules = ludivinecassal.apache.modules; | ||
24 | services.websites.integration.vhostConfs.ludivine = { | ||
25 | certName = "eldiron"; | ||
26 | addToCerts = true; | ||
27 | hosts = [ "ludivine.immae.eu" ]; | ||
28 | root = ludivinecassal.apache.root; | ||
29 | extraConfig = [ ludivinecassal.apache.vhostConf ]; | ||
30 | }; | ||
31 | }; | ||
32 | } | ||
diff --git a/modules/private/websites/ludivinecassal/production.nix b/modules/private/websites/ludivinecassal/production.nix new file mode 100644 index 00000000..3df5613f --- /dev/null +++ b/modules/private/websites/ludivinecassal/production.nix | |||
@@ -0,0 +1,33 @@ | |||
1 | { lib, pkgs, config, myconfig, ... }: | ||
2 | let | ||
3 | ludivinecassal = pkgs.callPackage ./builder.nix { | ||
4 | inherit (pkgs.webapps) ludivinecassal; | ||
5 | config = myconfig.env.websites.ludivinecassal.production; | ||
6 | apacheUser = config.services.httpd.Prod.user; | ||
7 | apacheGroup = config.services.httpd.Prod.group; | ||
8 | }; | ||
9 | |||
10 | cfg = config.myServices.websites.ludivinecassal.production; | ||
11 | in { | ||
12 | options.myServices.websites.ludivinecassal.production.enable = lib.mkEnableOption "enable Ludivine's website in production"; | ||
13 | |||
14 | config = lib.mkIf cfg.enable { | ||
15 | secrets.keys = ludivinecassal.keys; | ||
16 | services.webstats.sites = [ { name = "ludivinecassal.com"; } ]; | ||
17 | |||
18 | systemd.services.phpfpm-ludivinecassal_prod.after = lib.mkAfter ludivinecassal.phpFpm.serviceDeps; | ||
19 | systemd.services.phpfpm-ludivinecassal_prod.wants = ludivinecassal.phpFpm.serviceDeps; | ||
20 | systemd.services.phpfpm-ludivinecassal_prod.preStart = lib.mkAfter ludivinecassal.phpFpm.preStart; | ||
21 | services.phpfpm.poolConfigs.ludivinecassal_prod = ludivinecassal.phpFpm.pool; | ||
22 | system.activationScripts.ludivinecassal_prod = ludivinecassal.activationScript; | ||
23 | myServices.websites.webappDirs."${ludivinecassal.apache.webappName}" = ludivinecassal.app.webRoot; | ||
24 | services.websites.production.modules = ludivinecassal.apache.modules; | ||
25 | services.websites.production.vhostConfs.ludivine = { | ||
26 | certName = "ludivinecassal"; | ||
27 | certMainHost = "ludivinecassal.com"; | ||
28 | hosts = ["ludivinecassal.com" "www.ludivinecassal.com" ]; | ||
29 | root = ludivinecassal.apache.root; | ||
30 | extraConfig = [ ludivinecassal.apache.vhostConf ]; | ||
31 | }; | ||
32 | }; | ||
33 | } | ||