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