diff options
author | Ismaël Bouya <ismael.bouya@normalesup.org> | 2019-05-18 10:49:00 +0200 |
---|---|---|
committer | Ismaël Bouya <ismael.bouya@normalesup.org> | 2019-05-18 10:49:00 +0200 |
commit | f8026b6e4c869aa108f6361c8ccd50890657994d (patch) | |
tree | 57cb311e520933bd2ab6ccbae05f2913799eb49e /modules/private/websites/connexionswing | |
parent | 4aac110f17f0528d90510eec00c9a8df60bcf04f (diff) | |
download | Nix-f8026b6e4c869aa108f6361c8ccd50890657994d.tar.gz Nix-f8026b6e4c869aa108f6361c8ccd50890657994d.tar.zst Nix-f8026b6e4c869aa108f6361c8ccd50890657994d.zip |
Move personal websites to modules
Diffstat (limited to 'modules/private/websites/connexionswing')
-rw-r--r-- | modules/private/websites/connexionswing/builder.nix | 164 | ||||
-rw-r--r-- | modules/private/websites/connexionswing/integration.nix | 35 | ||||
-rw-r--r-- | modules/private/websites/connexionswing/production.nix | 37 |
3 files changed, 236 insertions, 0 deletions
diff --git a/modules/private/websites/connexionswing/builder.nix b/modules/private/websites/connexionswing/builder.nix new file mode 100644 index 0000000..1224420 --- /dev/null +++ b/modules/private/websites/connexionswing/builder.nix | |||
@@ -0,0 +1,164 @@ | |||
1 | { apacheUser, apacheGroup, connexionswing, pkgs, phpPackages, config }: | ||
2 | rec { | ||
3 | app = connexionswing.override { inherit (config) environment; }; | ||
4 | keys = [{ | ||
5 | dest = "webapps/${app.environment}-connexionswing"; | ||
6 | user = apacheUser; | ||
7 | group = apacheGroup; | ||
8 | permissions = "0400"; | ||
9 | text = '' | ||
10 | # This file is auto-generated during the composer install | ||
11 | parameters: | ||
12 | database_host: ${config.mysql.host} | ||
13 | database_port: ${config.mysql.port} | ||
14 | database_name: ${config.mysql.name} | ||
15 | database_user: ${config.mysql.user} | ||
16 | database_password: ${config.mysql.password} | ||
17 | database_server_version: ${pkgs.mariadb.mysqlVersion} | ||
18 | mailer_transport: sendmail | ||
19 | mailer_host: null | ||
20 | mailer_user: null | ||
21 | mailer_password: null | ||
22 | subscription_email: ${config.email} | ||
23 | allow_robots: true | ||
24 | secret: ${config.secret} | ||
25 | ${if app.environment == "prod" then '' | ||
26 | services: | ||
27 | swiftmailer.mailer.default.transport: | ||
28 | class: Swift_SendmailTransport | ||
29 | arguments: ['/run/wrappers/bin/sendmail -bs'] | ||
30 | '' else ""} | ||
31 | ''; | ||
32 | }]; | ||
33 | phpFpm = rec { | ||
34 | preStart = '' | ||
35 | if [ ! -f "${app.varDir}/currentWebappDir" -o \ | ||
36 | ! -f "${app.varDir}/currentKey" -o \ | ||
37 | "${app}" != "$(cat ${app.varDir}/currentWebappDir 2>/dev/null)" ] \ | ||
38 | || ! sha512sum -c --status ${app.varDir}/currentKey; then | ||
39 | pushd ${app} > /dev/null | ||
40 | /run/wrappers/bin/sudo -u ${apacheUser} ./bin/console --env=${app.environment} cache:clear --no-warmup | ||
41 | popd > /dev/null | ||
42 | echo -n "${app}" > ${app.varDir}/currentWebappDir | ||
43 | sha512sum /var/secrets/webapps/${app.environment}-connexionswing > ${app.varDir}/currentKey | ||
44 | fi | ||
45 | ''; | ||
46 | serviceDeps = [ "mysql.service" ]; | ||
47 | socket = "/var/run/phpfpm/connexionswing-${app.environment}.sock"; | ||
48 | phpConfig = '' | ||
49 | extension=${phpPackages.imagick}/lib/php/extensions/imagick.so | ||
50 | ''; | ||
51 | pool = '' | ||
52 | listen = ${socket} | ||
53 | user = ${apacheUser} | ||
54 | group = ${apacheGroup} | ||
55 | listen.owner = ${apacheUser} | ||
56 | listen.group = ${apacheGroup} | ||
57 | php_admin_value[upload_max_filesize] = 20M | ||
58 | php_admin_value[post_max_size] = 20M | ||
59 | ;php_admin_flag[log_errors] = on | ||
60 | php_admin_value[open_basedir] = "/run/wrappers/bin/sendmail:/var/secrets/webapps/${app.environment}-connexionswing:${app}:${app.varDir}:/tmp" | ||
61 | php_admin_value[session.save_path] = "${app.varDir}/phpSessions" | ||
62 | ${if app.environment == "dev" then '' | ||
63 | pm = ondemand | ||
64 | pm.max_children = 5 | ||
65 | pm.process_idle_timeout = 60 | ||
66 | env[SYMFONY_DEBUG_MODE] = "yes" | ||
67 | '' else '' | ||
68 | pm = dynamic | ||
69 | pm.max_children = 20 | ||
70 | pm.start_servers = 2 | ||
71 | pm.min_spare_servers = 1 | ||
72 | pm.max_spare_servers = 3 | ||
73 | ''}''; | ||
74 | }; | ||
75 | apache = rec { | ||
76 | modules = [ "proxy_fcgi" ]; | ||
77 | webappName = "connexionswing_${app.environment}"; | ||
78 | root = "/run/current-system/webapps/${webappName}"; | ||
79 | vhostConf = '' | ||
80 | <FilesMatch "\.php$"> | ||
81 | SetHandler "proxy:unix:${phpFpm.socket}|fcgi://localhost" | ||
82 | </FilesMatch> | ||
83 | |||
84 | <Directory ${app.varDir}/medias> | ||
85 | Options FollowSymLinks | ||
86 | AllowOverride None | ||
87 | Require all granted | ||
88 | </Directory> | ||
89 | |||
90 | <Directory ${app.varDir}/uploads> | ||
91 | Options FollowSymLinks | ||
92 | AllowOverride None | ||
93 | Require all granted | ||
94 | </Directory> | ||
95 | |||
96 | ${if app.environment == "dev" then '' | ||
97 | <Location /> | ||
98 | Use LDAPConnect | ||
99 | Require ldap-group cn=connexionswing.immae.eu,cn=httpd,ou=services,dc=immae,dc=eu | ||
100 | ErrorDocument 401 "<html><meta http-equiv=\"refresh\" content=\"0;url=https://connexionswing.com\"></html>" | ||
101 | </Location> | ||
102 | |||
103 | <Directory ${root}> | ||
104 | Options Indexes FollowSymLinks MultiViews Includes | ||
105 | AllowOverride None | ||
106 | Require all granted | ||
107 | |||
108 | DirectoryIndex app_dev.php | ||
109 | |||
110 | <IfModule mod_negotiation.c> | ||
111 | Options -MultiViews | ||
112 | </IfModule> | ||
113 | |||
114 | <IfModule mod_rewrite.c> | ||
115 | RewriteEngine On | ||
116 | |||
117 | RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$ | ||
118 | RewriteRule ^(.*) - [E=BASE:%1] | ||
119 | |||
120 | # Maintenance script | ||
121 | RewriteCond %{DOCUMENT_ROOT}/maintenance.php -f | ||
122 | RewriteCond %{SCRIPT_FILENAME} !maintenance.php | ||
123 | RewriteRule ^.*$ %{ENV:BASE}/maintenance.php [R=503,L] | ||
124 | ErrorDocument 503 /maintenance.php | ||
125 | |||
126 | # Sets the HTTP_AUTHORIZATION header removed by Apache | ||
127 | RewriteCond %{HTTP:Authorization} . | ||
128 | RewriteRule ^ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] | ||
129 | |||
130 | RewriteCond %{ENV:REDIRECT_STATUS} ^$ | ||
131 | RewriteRule ^app_dev\.php(?:/(.*)|$) %{ENV:BASE}/$1 [R=301,L] | ||
132 | |||
133 | # If the requested filename exists, simply serve it. | ||
134 | # We only want to let Apache serve files and not directories. | ||
135 | RewriteCond %{REQUEST_FILENAME} -f | ||
136 | RewriteRule ^ - [L] | ||
137 | |||
138 | # Rewrite all other queries to the front controller. | ||
139 | RewriteRule ^ %{ENV:BASE}/app_dev.php [L] | ||
140 | </IfModule> | ||
141 | |||
142 | </Directory> | ||
143 | '' else '' | ||
144 | Use Stats connexionswing.com | ||
145 | |||
146 | <Directory ${root}> | ||
147 | Options Indexes FollowSymLinks MultiViews Includes | ||
148 | AllowOverride All | ||
149 | Require all granted | ||
150 | </Directory> | ||
151 | ''} | ||
152 | ''; | ||
153 | }; | ||
154 | activationScript = { | ||
155 | deps = [ "wrappers" ]; | ||
156 | text = '' | ||
157 | install -m 0755 -o ${apacheUser} -g ${apacheGroup} -d ${app.varDir} \ | ||
158 | ${app.varDir}/medias \ | ||
159 | ${app.varDir}/uploads \ | ||
160 | ${app.varDir}/var | ||
161 | install -m 0750 -o ${apacheUser} -g ${apacheGroup} -d ${app.varDir}/phpSessions | ||
162 | ''; | ||
163 | }; | ||
164 | } | ||
diff --git a/modules/private/websites/connexionswing/integration.nix b/modules/private/websites/connexionswing/integration.nix new file mode 100644 index 0000000..c3425bd --- /dev/null +++ b/modules/private/websites/connexionswing/integration.nix | |||
@@ -0,0 +1,35 @@ | |||
1 | { lib, pkgs, config, myconfig, ... }: | ||
2 | let | ||
3 | connexionswing = pkgs.callPackage ./builder.nix { | ||
4 | inherit (pkgs.webapps) connexionswing; | ||
5 | config = myconfig.env.websites.connexionswing.integration; | ||
6 | apacheUser = config.services.httpd.Inte.user; | ||
7 | apacheGroup = config.services.httpd.Inte.group; | ||
8 | }; | ||
9 | |||
10 | cfg = config.myServices.websites.connexionswing.integration; | ||
11 | in { | ||
12 | options.myServices.websites.connexionswing.integration.enable = lib.mkEnableOption "enable Connexionswing's website in integration"; | ||
13 | |||
14 | config = lib.mkIf cfg.enable { | ||
15 | secrets.keys = connexionswing.keys; | ||
16 | services.myPhpfpm.preStart.connexionswing_dev = connexionswing.phpFpm.preStart; | ||
17 | services.myPhpfpm.serviceDependencies.connexionswing_dev = connexionswing.phpFpm.serviceDeps; | ||
18 | services.myPhpfpm.poolConfigs.connexionswing_dev = connexionswing.phpFpm.pool; | ||
19 | services.myPhpfpm.poolPhpConfigs.connexionswing_dev = connexionswing.phpFpm.phpConfig; | ||
20 | system.activationScripts.connexionswing_dev = connexionswing.activationScript; | ||
21 | system.extraSystemBuilderCmds = '' | ||
22 | mkdir -p $out/webapps | ||
23 | ln -s ${connexionswing.app.webRoot} $out/webapps/${connexionswing.apache.webappName} | ||
24 | ''; | ||
25 | services.websites.integration.modules = connexionswing.apache.modules; | ||
26 | services.websites.integration.vhostConfs.connexionswing = { | ||
27 | certName = "eldiron"; | ||
28 | addToCerts = true; | ||
29 | hosts = ["connexionswing.immae.eu" "sandetludo.immae.eu" ]; | ||
30 | root = connexionswing.apache.root; | ||
31 | extraConfig = [ connexionswing.apache.vhostConf ]; | ||
32 | }; | ||
33 | }; | ||
34 | } | ||
35 | |||
diff --git a/modules/private/websites/connexionswing/production.nix b/modules/private/websites/connexionswing/production.nix new file mode 100644 index 0000000..8f28f46 --- /dev/null +++ b/modules/private/websites/connexionswing/production.nix | |||
@@ -0,0 +1,37 @@ | |||
1 | { lib, pkgs, config, myconfig, ... }: | ||
2 | let | ||
3 | connexionswing = pkgs.callPackage ./builder.nix { | ||
4 | inherit (pkgs.webapps) connexionswing; | ||
5 | config = myconfig.env.websites.connexionswing.production; | ||
6 | apacheUser = config.services.httpd.Prod.user; | ||
7 | apacheGroup = config.services.httpd.Prod.group; | ||
8 | }; | ||
9 | |||
10 | cfg = config.myServices.websites.connexionswing.production; | ||
11 | in { | ||
12 | options.myServices.websites.connexionswing.production.enable = lib.mkEnableOption "enable Connexionswing's website in production"; | ||
13 | |||
14 | config = lib.mkIf cfg.enable { | ||
15 | secrets.keys = connexionswing.keys; | ||
16 | services.webstats.sites = [ { name = "connexionswing.com"; } ]; | ||
17 | |||
18 | services.myPhpfpm.preStart.connexionswing_prod = connexionswing.phpFpm.preStart; | ||
19 | services.myPhpfpm.serviceDependencies.connexionswing_prod = connexionswing.phpFpm.serviceDeps; | ||
20 | services.myPhpfpm.poolConfigs.connexionswing_prod = connexionswing.phpFpm.pool; | ||
21 | services.myPhpfpm.poolPhpConfigs.connexionswing_prod = connexionswing.phpFpm.phpConfig; | ||
22 | system.activationScripts.connexionswing_prod = connexionswing.activationScript; | ||
23 | system.extraSystemBuilderCmds = '' | ||
24 | mkdir -p $out/webapps | ||
25 | ln -s ${connexionswing.app.webRoot} $out/webapps/${connexionswing.apache.webappName} | ||
26 | ''; | ||
27 | services.websites.production.modules = connexionswing.apache.modules; | ||
28 | services.websites.production.vhostConfs.connexionswing = { | ||
29 | certName = "connexionswing"; | ||
30 | certMainHost = "connexionswing.com"; | ||
31 | hosts = ["connexionswing.com" "sandetludo.com" "www.connexionswing.com" "www.sandetludo.com" ]; | ||
32 | root = connexionswing.apache.root; | ||
33 | extraConfig = [ connexionswing.apache.vhostConf ]; | ||
34 | }; | ||
35 | }; | ||
36 | } | ||
37 | |||