aboutsummaryrefslogtreecommitdiff
path: root/modules/private/websites/piedsjaloux
diff options
context:
space:
mode:
authorIsmaël Bouya <ismael.bouya@normalesup.org>2019-05-18 10:49:00 +0200
committerIsmaël Bouya <ismael.bouya@normalesup.org>2019-05-18 10:49:00 +0200
commitf8026b6e4c869aa108f6361c8ccd50890657994d (patch)
tree57cb311e520933bd2ab6ccbae05f2913799eb49e /modules/private/websites/piedsjaloux
parent4aac110f17f0528d90510eec00c9a8df60bcf04f (diff)
downloadNix-f8026b6e4c869aa108f6361c8ccd50890657994d.tar.gz
Nix-f8026b6e4c869aa108f6361c8ccd50890657994d.tar.zst
Nix-f8026b6e4c869aa108f6361c8ccd50890657994d.zip
Move personal websites to modules
Diffstat (limited to 'modules/private/websites/piedsjaloux')
-rw-r--r--modules/private/websites/piedsjaloux/builder.nix144
-rw-r--r--modules/private/websites/piedsjaloux/integration.nix34
-rw-r--r--modules/private/websites/piedsjaloux/production.nix36
3 files changed, 214 insertions, 0 deletions
diff --git a/modules/private/websites/piedsjaloux/builder.nix b/modules/private/websites/piedsjaloux/builder.nix
new file mode 100644
index 0000000..9fcc8fb
--- /dev/null
+++ b/modules/private/websites/piedsjaloux/builder.nix
@@ -0,0 +1,144 @@
1{ apacheUser, apacheGroup, piedsjaloux, config, pkgs, lib, texlive, imagemagick }:
2rec {
3 app = piedsjaloux.override { inherit (config) environment; };
4 varDir = "/var/lib/piedsjaloux_${app.environment}";
5 keys = [{
6 dest = "webapps/${app.environment}-piedsjaloux";
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 pdflatex: "${texlive.combine { inherit (texlive) attachfile preprint scheme-small; }}/bin/pdflatex"
25 leapt_im:
26 binary_path: ${imagemagick}/bin
27 '';
28 }];
29 phpFpm = rec {
30 preStart = ''
31 if [ ! -f "${app.varDir}/currentWebappDir" -o \
32 ! -f "${app.varDir}/currentKey" -o \
33 "${app}" != "$(cat ${app.varDir}/currentWebappDir 2>/dev/null)" ] \
34 || ! sha512sum -c --status ${app.varDir}/currentKey; then
35 pushd ${app} > /dev/null
36 /run/wrappers/bin/sudo -u ${apacheUser} ./bin/console --env=${app.environment} cache:clear --no-warmup
37 popd > /dev/null
38 echo -n "${app}" > ${app.varDir}/currentWebappDir
39 sha512sum /var/secrets/webapps/${app.environment}-piedsjaloux > ${app.varDir}/currentKey
40 fi
41 '';
42 serviceDeps = [ "mysql.service" ];
43 socket = "/var/run/phpfpm/piedsjaloux-${app.environment}.sock";
44 pool = ''
45 listen = ${socket}
46 user = ${apacheUser}
47 group = ${apacheGroup}
48 listen.owner = ${apacheUser}
49 listen.group = ${apacheGroup}
50 php_admin_value[upload_max_filesize] = 20M
51 php_admin_value[post_max_size] = 20M
52 ;php_admin_flag[log_errors] = on
53 php_admin_value[open_basedir] = "/var/secrets/webapps/${app.environment}-piedsjaloux:${app}:${app.varDir}:/tmp"
54 php_admin_value[session.save_path] = "${app.varDir}/phpSessions"
55 env[PATH] = ${lib.makeBinPath [ pkgs.apg pkgs.unzip ]}
56 ${if app.environment == "dev" then ''
57 pm = ondemand
58 pm.max_children = 5
59 pm.process_idle_timeout = 60
60 env[SYMFONY_DEBUG_MODE] = "yes"
61 '' else ''
62 pm = dynamic
63 pm.max_children = 20
64 pm.start_servers = 2
65 pm.min_spare_servers = 1
66 pm.max_spare_servers = 3
67 ''}'';
68 };
69 apache = rec {
70 modules = [ "proxy_fcgi" ];
71 webappName = "piedsjaloux_${app.environment}";
72 root = "/run/current-system/webapps/${webappName}";
73 vhostConf = ''
74 <FilesMatch "\.php$">
75 SetHandler "proxy:unix:${phpFpm.socket}|fcgi://localhost"
76 </FilesMatch>
77
78 ${if app.environment == "dev" then ''
79 <Location />
80 Use LDAPConnect
81 Require ldap-group cn=piedsjaloux.immae.eu,cn=httpd,ou=services,dc=immae,dc=eu
82 ErrorDocument 401 "<html><meta http-equiv=\"refresh\" content=\"0;url=https://piedsjaloux.fr\"></html>"
83 </Location>
84
85 <Directory ${root}>
86 Options Indexes FollowSymLinks MultiViews Includes
87 AllowOverride None
88 Require all granted
89
90 DirectoryIndex app_dev.php
91
92 <IfModule mod_negotiation.c>
93 Options -MultiViews
94 </IfModule>
95
96 <IfModule mod_rewrite.c>
97 RewriteEngine On
98
99 RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
100 RewriteRule ^(.*) - [E=BASE:%1]
101
102 # Maintenance script
103 RewriteCond %{DOCUMENT_ROOT}/maintenance.php -f
104 RewriteCond %{SCRIPT_FILENAME} !maintenance.php
105 RewriteRule ^.*$ %{ENV:BASE}/maintenance.php [R=503,L]
106 ErrorDocument 503 /maintenance.php
107
108 # Sets the HTTP_AUTHORIZATION header removed by Apache
109 RewriteCond %{HTTP:Authorization} .
110 RewriteRule ^ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
111
112 RewriteCond %{ENV:REDIRECT_STATUS} ^$
113 RewriteRule ^app_dev\.php(?:/(.*)|$) %{ENV:BASE}/$1 [R=301,L]
114
115 # If the requested filename exists, simply serve it.
116 # We only want to let Apache serve files and not directories.
117 RewriteCond %{REQUEST_FILENAME} -f
118 RewriteRule ^ - [L]
119
120 # Rewrite all other queries to the front controller.
121 RewriteRule ^ %{ENV:BASE}/app_dev.php [L]
122 </IfModule>
123
124 </Directory>
125 '' else ''
126 Use Stats piedsjaloux.fr
127
128 <Directory ${root}>
129 Options Indexes FollowSymLinks MultiViews Includes
130 AllowOverride All
131 Require all granted
132 </Directory>
133 ''}
134 '';
135 };
136 activationScript = {
137 deps = [ "wrappers" ];
138 text = ''
139 install -m 0755 -o ${apacheUser} -g ${apacheGroup} -d ${app.varDir} \
140 ${app.varDir}/tmp
141 install -m 0750 -o ${apacheUser} -g ${apacheGroup} -d ${app.varDir}/phpSessions
142 '';
143 };
144}
diff --git a/modules/private/websites/piedsjaloux/integration.nix b/modules/private/websites/piedsjaloux/integration.nix
new file mode 100644
index 0000000..6249e85
--- /dev/null
+++ b/modules/private/websites/piedsjaloux/integration.nix
@@ -0,0 +1,34 @@
1{ lib, pkgs, config, myconfig, ... }:
2let
3 piedsjaloux = pkgs.callPackage ./builder.nix {
4 inherit (pkgs.webapps) piedsjaloux;
5 config = myconfig.env.websites.piedsjaloux.integration;
6 apacheUser = config.services.httpd.Inte.user;
7 apacheGroup = config.services.httpd.Inte.group;
8 };
9
10 cfg = config.myServices.websites.piedsjaloux.integration;
11in {
12 options.myServices.websites.piedsjaloux.integration.enable = lib.mkEnableOption "enable PiedsJaloux's website in integration";
13
14 config = lib.mkIf cfg.enable {
15 secrets.keys = piedsjaloux.keys;
16 services.myPhpfpm.preStart.piedsjaloux_dev = piedsjaloux.phpFpm.preStart;
17 services.myPhpfpm.serviceDependencies.piedsjaloux_dev = piedsjaloux.phpFpm.serviceDeps;
18 services.myPhpfpm.poolConfigs.piedsjaloux_dev = piedsjaloux.phpFpm.pool;
19 system.activationScripts.piedsjaloux_dev = piedsjaloux.activationScript;
20 system.extraSystemBuilderCmds = ''
21 mkdir -p $out/webapps
22 ln -s ${piedsjaloux.app.webRoot} $out/webapps/${piedsjaloux.apache.webappName}
23 '';
24 services.websites.integration.modules = piedsjaloux.apache.modules;
25 services.websites.integration.vhostConfs.piedsjaloux = {
26 certName = "eldiron";
27 addToCerts = true;
28 hosts = [ "piedsjaloux.immae.eu" ];
29 root = piedsjaloux.apache.root;
30 extraConfig = [ piedsjaloux.apache.vhostConf ];
31 };
32 };
33}
34
diff --git a/modules/private/websites/piedsjaloux/production.nix b/modules/private/websites/piedsjaloux/production.nix
new file mode 100644
index 0000000..afa1667
--- /dev/null
+++ b/modules/private/websites/piedsjaloux/production.nix
@@ -0,0 +1,36 @@
1{ lib, pkgs, config, myconfig, ... }:
2let
3 piedsjaloux = pkgs.callPackage ./builder.nix {
4 inherit (pkgs.webapps) piedsjaloux;
5 config = myconfig.env.websites.piedsjaloux.production;
6 apacheUser = config.services.httpd.Prod.user;
7 apacheGroup = config.services.httpd.Prod.group;
8 };
9
10 cfg = config.myServices.websites.piedsjaloux.production;
11in {
12 options.myServices.websites.piedsjaloux.production.enable = lib.mkEnableOption "enable PiedsJaloux's website in production";
13
14 config = lib.mkIf cfg.enable {
15 secrets.keys = piedsjaloux.keys;
16 services.webstats.sites = [ { name = "piedsjaloux.fr"; } ];
17
18 services.myPhpfpm.preStart.piedsjaloux_prod = piedsjaloux.phpFpm.preStart;
19 services.myPhpfpm.serviceDependencies.piedsjaloux_prod = piedsjaloux.phpFpm.serviceDeps;
20 services.myPhpfpm.poolConfigs.piedsjaloux_prod = piedsjaloux.phpFpm.pool;
21 system.activationScripts.piedsjaloux_prod = piedsjaloux.activationScript;
22 system.extraSystemBuilderCmds = ''
23 mkdir -p $out/webapps
24 ln -s ${piedsjaloux.app.webRoot} $out/webapps/${piedsjaloux.apache.webappName}
25 '';
26 services.websites.production.modules = piedsjaloux.apache.modules;
27 services.websites.production.vhostConfs.piedsjaloux = {
28 certName = "piedsjaloux";
29 certMainHost = "piedsjaloux.fr";
30 hosts = [ "piedsjaloux.fr" "www.piedsjaloux.fr" ];
31 root = piedsjaloux.apache.root;
32 extraConfig = [ piedsjaloux.apache.vhostConf ];
33 };
34 };
35}
36