aboutsummaryrefslogtreecommitdiff
path: root/nixops/modules/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 /nixops/modules/websites/piedsjaloux
parent4aac110f17f0528d90510eec00c9a8df60bcf04f (diff)
downloadNix-f8026b6e4c869aa108f6361c8ccd50890657994d.tar.gz
Nix-f8026b6e4c869aa108f6361c8ccd50890657994d.tar.zst
Nix-f8026b6e4c869aa108f6361c8ccd50890657994d.zip
Move personal websites to modules
Diffstat (limited to 'nixops/modules/websites/piedsjaloux')
-rw-r--r--nixops/modules/websites/piedsjaloux/default.nix66
-rw-r--r--nixops/modules/websites/piedsjaloux/piedsjaloux.nix146
2 files changed, 0 insertions, 212 deletions
diff --git a/nixops/modules/websites/piedsjaloux/default.nix b/nixops/modules/websites/piedsjaloux/default.nix
deleted file mode 100644
index a5ee24f..0000000
--- a/nixops/modules/websites/piedsjaloux/default.nix
+++ /dev/null
@@ -1,66 +0,0 @@
1{ lib, pkgs, config, myconfig, ... }:
2let
3 piedsjaloux_dev = pkgs.callPackage ./piedsjaloux.nix {
4 inherit (pkgs.webapps) piedsjaloux;
5 config = myconfig.env.websites.piedsjaloux.integration;
6 };
7 piedsjaloux_prod = pkgs.callPackage ./piedsjaloux.nix {
8 inherit (pkgs.webapps) piedsjaloux;
9 config = myconfig.env.websites.piedsjaloux.production;
10 };
11
12 cfg = config.services.myWebsites.PiedsJaloux;
13in {
14 options.services.myWebsites.PiedsJaloux = {
15 production = {
16 enable = lib.mkEnableOption "enable PiedsJaloux's website in production";
17 };
18 integration = {
19 enable = lib.mkEnableOption "enable PiedsJaloux's website in integration";
20 };
21 };
22
23 config = lib.mkMerge [
24 (lib.mkIf cfg.production.enable {
25 secrets.keys = piedsjaloux_prod.keys;
26 services.webstats.sites = [ { name = "piedsjaloux.fr"; } ];
27
28 services.myPhpfpm.preStart.piedsjaloux_prod = piedsjaloux_prod.phpFpm.preStart;
29 services.myPhpfpm.serviceDependencies.piedsjaloux_prod = piedsjaloux_prod.phpFpm.serviceDeps;
30 services.myPhpfpm.poolConfigs.piedsjaloux_prod = piedsjaloux_prod.phpFpm.pool;
31 system.activationScripts.piedsjaloux_prod = piedsjaloux_prod.activationScript;
32 system.extraSystemBuilderCmds = ''
33 mkdir -p $out/webapps
34 ln -s ${piedsjaloux_prod.app.webRoot} $out/webapps/${piedsjaloux_prod.apache.webappName}
35 '';
36 services.websites.production.modules = piedsjaloux_prod.apache.modules;
37 services.websites.production.vhostConfs.piedsjaloux = {
38 certName = "piedsjaloux";
39 certMainHost = "piedsjaloux.fr";
40 hosts = [ "piedsjaloux.fr" "www.piedsjaloux.fr" ];
41 root = piedsjaloux_prod.apache.root;
42 extraConfig = [ piedsjaloux_prod.apache.vhostConf ];
43 };
44 })
45 (lib.mkIf cfg.integration.enable {
46 secrets.keys = piedsjaloux_dev.keys;
47 services.myPhpfpm.preStart.piedsjaloux_dev = piedsjaloux_dev.phpFpm.preStart;
48 services.myPhpfpm.serviceDependencies.piedsjaloux_dev = piedsjaloux_dev.phpFpm.serviceDeps;
49 services.myPhpfpm.poolConfigs.piedsjaloux_dev = piedsjaloux_dev.phpFpm.pool;
50 system.activationScripts.piedsjaloux_dev = piedsjaloux_dev.activationScript;
51 system.extraSystemBuilderCmds = ''
52 mkdir -p $out/webapps
53 ln -s ${piedsjaloux_dev.app.webRoot} $out/webapps/${piedsjaloux_dev.apache.webappName}
54 '';
55 services.websites.integration.modules = piedsjaloux_dev.apache.modules;
56 services.websites.integration.vhostConfs.piedsjaloux = {
57 certName = "eldiron";
58 addToCerts = true;
59 hosts = [ "piedsjaloux.immae.eu" ];
60 root = piedsjaloux_dev.apache.root;
61 extraConfig = [ piedsjaloux_dev.apache.vhostConf ];
62 };
63 })
64 ];
65}
66
diff --git a/nixops/modules/websites/piedsjaloux/piedsjaloux.nix b/nixops/modules/websites/piedsjaloux/piedsjaloux.nix
deleted file mode 100644
index 97f8946..0000000
--- a/nixops/modules/websites/piedsjaloux/piedsjaloux.nix
+++ /dev/null
@@ -1,146 +0,0 @@
1{ 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 = apache.user;
8 group = apache.group;
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 wwwrun ./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 = ${apache.user}
47 group = ${apache.group}
48 listen.owner = ${apache.user}
49 listen.group = ${apache.group}
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 user = "wwwrun";
71 group = "wwwrun";
72 modules = [ "proxy_fcgi" ];
73 webappName = "piedsjaloux_${app.environment}";
74 root = "/run/current-system/webapps/${webappName}";
75 vhostConf = ''
76 <FilesMatch "\.php$">
77 SetHandler "proxy:unix:${phpFpm.socket}|fcgi://localhost"
78 </FilesMatch>
79
80 ${if app.environment == "dev" then ''
81 <Location />
82 Use LDAPConnect
83 Require ldap-group cn=piedsjaloux.immae.eu,cn=httpd,ou=services,dc=immae,dc=eu
84 ErrorDocument 401 "<html><meta http-equiv=\"refresh\" content=\"0;url=https://piedsjaloux.fr\"></html>"
85 </Location>
86
87 <Directory ${root}>
88 Options Indexes FollowSymLinks MultiViews Includes
89 AllowOverride None
90 Require all granted
91
92 DirectoryIndex app_dev.php
93
94 <IfModule mod_negotiation.c>
95 Options -MultiViews
96 </IfModule>
97
98 <IfModule mod_rewrite.c>
99 RewriteEngine On
100
101 RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
102 RewriteRule ^(.*) - [E=BASE:%1]
103
104 # Maintenance script
105 RewriteCond %{DOCUMENT_ROOT}/maintenance.php -f
106 RewriteCond %{SCRIPT_FILENAME} !maintenance.php
107 RewriteRule ^.*$ %{ENV:BASE}/maintenance.php [R=503,L]
108 ErrorDocument 503 /maintenance.php
109
110 # Sets the HTTP_AUTHORIZATION header removed by Apache
111 RewriteCond %{HTTP:Authorization} .
112 RewriteRule ^ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
113
114 RewriteCond %{ENV:REDIRECT_STATUS} ^$
115 RewriteRule ^app_dev\.php(?:/(.*)|$) %{ENV:BASE}/$1 [R=301,L]
116
117 # If the requested filename exists, simply serve it.
118 # We only want to let Apache serve files and not directories.
119 RewriteCond %{REQUEST_FILENAME} -f
120 RewriteRule ^ - [L]
121
122 # Rewrite all other queries to the front controller.
123 RewriteRule ^ %{ENV:BASE}/app_dev.php [L]
124 </IfModule>
125
126 </Directory>
127 '' else ''
128 Use Stats piedsjaloux.fr
129
130 <Directory ${root}>
131 Options Indexes FollowSymLinks MultiViews Includes
132 AllowOverride All
133 Require all granted
134 </Directory>
135 ''}
136 '';
137 };
138 activationScript = {
139 deps = [ "wrappers" ];
140 text = ''
141 install -m 0755 -o ${apache.user} -g ${apache.group} -d ${app.varDir} \
142 ${app.varDir}/tmp
143 install -m 0750 -o ${apache.user} -g ${apache.group} -d ${app.varDir}/phpSessions
144 '';
145 };
146}