aboutsummaryrefslogtreecommitdiff
path: root/modules/private/websites/aten
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/aten
parent4aac110f17f0528d90510eec00c9a8df60bcf04f (diff)
downloadNix-f8026b6e4c869aa108f6361c8ccd50890657994d.tar.gz
Nix-f8026b6e4c869aa108f6361c8ccd50890657994d.tar.zst
Nix-f8026b6e4c869aa108f6361c8ccd50890657994d.zip
Move personal websites to modules
Diffstat (limited to 'modules/private/websites/aten')
-rw-r--r--modules/private/websites/aten/builder.nix102
-rw-r--r--modules/private/websites/aten/integration.nix34
-rw-r--r--modules/private/websites/aten/production.nix36
3 files changed, 172 insertions, 0 deletions
diff --git a/modules/private/websites/aten/builder.nix b/modules/private/websites/aten/builder.nix
new file mode 100644
index 0000000..9a2e1a7
--- /dev/null
+++ b/modules/private/websites/aten/builder.nix
@@ -0,0 +1,102 @@
1{ apacheUser, apacheGroup, aten, lib, config }: rec {
2 app = aten.override { inherit (config) environment; };
3 phpFpm = rec {
4 preStart = ''
5 if [ ! -f "${app.varDir}/currentWebappDir" -o \
6 ! -f "${app.varDir}/currentKey" -o \
7 "${app}" != "$(cat ${app.varDir}/currentWebappDir 2>/dev/null)" ] \
8 || ! sha512sum -c --status ${app.varDir}/currentKey; then
9 pushd ${app} > /dev/null
10 /run/wrappers/bin/sudo -u ${apacheUser} APP_ENV=${app.environment} ./bin/console --env=${app.environment} cache:clear --no-warmup
11 popd > /dev/null
12 echo -n "${app}" > ${app.varDir}/currentWebappDir
13 sha512sum /var/secrets/webapps/${app.environment}-aten > ${app.varDir}/currentKey
14 fi
15 '';
16 serviceDeps = [ "postgresql.service" ];
17 socket = "/var/run/phpfpm/aten-${app.environment}.sock";
18 pool = ''
19 listen = ${socket}
20 user = ${apacheUser}
21 group = ${apacheGroup}
22 listen.owner = ${apacheUser}
23 listen.group = ${apacheGroup}
24 php_admin_value[upload_max_filesize] = 20M
25 php_admin_value[post_max_size] = 20M
26 ;php_admin_flag[log_errors] = on
27 php_admin_value[open_basedir] = "${app}:${app.varDir}:/tmp"
28 php_admin_value[session.save_path] = "${app.varDir}/phpSessions"
29 ${if app.environment == "dev" then ''
30 pm = ondemand
31 pm.max_children = 5
32 pm.process_idle_timeout = 60
33 env[SYMFONY_DEBUG_MODE] = "yes"
34 '' else ''
35 pm = dynamic
36 pm.max_children = 20
37 pm.start_servers = 2
38 pm.min_spare_servers = 1
39 pm.max_spare_servers = 3
40 ''}'';
41 };
42 keys = [{
43 dest = "webapps/${app.environment}-aten";
44 user = apacheUser;
45 group = apacheGroup;
46 permissions = "0400";
47 text = ''
48 SetEnv APP_ENV "${app.environment}"
49 SetEnv APP_SECRET "${config.secret}"
50 SetEnv DATABASE_URL "${config.psql_url}"
51 '';
52 }];
53 apache = rec {
54 modules = [ "proxy_fcgi" ];
55 webappName = "aten_${app.environment}";
56 root = "/run/current-system/webapps/${webappName}";
57 vhostConf = ''
58 <FilesMatch "\.php$">
59 SetHandler "proxy:unix:${phpFpm.socket}|fcgi://localhost"
60 </FilesMatch>
61
62 Include /var/secrets/webapps/${app.environment}-aten
63
64 ${if app.environment == "dev" then ''
65 <Location />
66 Use LDAPConnect
67 Require ldap-group cn=dev.aten.pro,cn=httpd,ou=services,dc=immae,dc=eu
68 ErrorDocument 401 "<html><meta http-equiv=\"refresh\" content=\"0;url=https://aten.pro\"></html>"
69 </Location>
70
71 <Location /backend>
72 Use LDAPConnect
73 Require ldap-group cn=dev.aten.pro,cn=httpd,ou=services,dc=immae,dc=eu
74 ErrorDocument 401 "<html><meta http-equiv=\"refresh\" content=\"0;url=https://aten.pro\"></html>"
75 </Location>
76 '' else ''
77 Use Stats aten.pro
78
79 <Location /backend>
80 Use LDAPConnect
81 Require ldap-group cn=aten.pro,cn=httpd,ou=services,dc=immae,dc=eu
82 ErrorDocument 401 "<html><meta http-equiv=\"refresh\" content=\"0;url=https://aten.pro\"></html>"
83 </Location>
84 ''}
85
86 <Directory ${root}>
87 Options Indexes FollowSymLinks MultiViews Includes
88 AllowOverride All
89 Require all granted
90 DirectoryIndex index.php
91 FallbackResource /index.php
92 </Directory>
93 '';
94 };
95 activationScript = {
96 deps = [ "wrappers" ];
97 text = ''
98 install -m 0755 -o ${apacheUser} -g ${apacheGroup} -d ${app.varDir}
99 install -m 0750 -o ${apacheUser} -g ${apacheGroup} -d ${app.varDir}/phpSessions
100 '';
101 };
102}
diff --git a/modules/private/websites/aten/integration.nix b/modules/private/websites/aten/integration.nix
new file mode 100644
index 0000000..790c5a9
--- /dev/null
+++ b/modules/private/websites/aten/integration.nix
@@ -0,0 +1,34 @@
1{ lib, pkgs, config, myconfig, ... }:
2let
3 aten = pkgs.callPackage ./builder.nix {
4 inherit (pkgs.webapps) aten;
5 config = myconfig.env.websites.aten.integration;
6 apacheUser = config.services.httpd.Inte.user;
7 apacheGroup = config.services.httpd.Inte.group;
8 };
9
10 cfg = config.myServices.websites.aten.integration;
11in {
12 options.myServices.websites.aten.integration.enable = lib.mkEnableOption "enable Aten's website in integration";
13
14 config = lib.mkIf cfg.enable {
15 secrets.keys = aten.keys;
16 services.myPhpfpm.preStart.aten_dev = aten.phpFpm.preStart;
17 services.myPhpfpm.serviceDependencies.aten_dev = aten.phpFpm.serviceDeps;
18 services.myPhpfpm.poolConfigs.aten_dev = aten.phpFpm.pool;
19 system.activationScripts.aten_dev = aten.activationScript;
20 system.extraSystemBuilderCmds = ''
21 mkdir -p $out/webapps
22 ln -s ${aten.app.webRoot} $out/webapps/${aten.apache.webappName}
23 '';
24 services.websites.integration.modules = aten.apache.modules;
25 services.websites.integration.vhostConfs.aten = {
26 certName = "eldiron";
27 addToCerts = true;
28 hosts = [ "dev.aten.pro" ];
29 root = aten.apache.root;
30 extraConfig = [ aten.apache.vhostConf ];
31 };
32 };
33}
34
diff --git a/modules/private/websites/aten/production.nix b/modules/private/websites/aten/production.nix
new file mode 100644
index 0000000..697f1b8
--- /dev/null
+++ b/modules/private/websites/aten/production.nix
@@ -0,0 +1,36 @@
1{ lib, pkgs, config, myconfig, ... }:
2let
3 aten = pkgs.callPackage ./builder.nix {
4 inherit (pkgs.webapps) aten;
5 config = myconfig.env.websites.aten.production;
6 apacheUser = config.services.httpd.Prod.user;
7 apacheGroup = config.services.httpd.Prod.group;
8 };
9
10 cfg = config.myServices.websites.aten.production;
11in {
12 options.myServices.websites.aten.production.enable = lib.mkEnableOption "enable Aten's website in production";
13
14 config = lib.mkIf cfg.enable {
15 secrets.keys = aten.keys;
16 services.webstats.sites = [ { name = "aten.pro"; } ];
17
18 services.myPhpfpm.preStart.aten_prod = aten.phpFpm.preStart;
19 services.myPhpfpm.serviceDependencies.aten_prod = aten.phpFpm.serviceDeps;
20 services.myPhpfpm.poolConfigs.aten_prod = aten.phpFpm.pool;
21 system.activationScripts.aten_prod = aten.activationScript;
22 system.extraSystemBuilderCmds = ''
23 mkdir -p $out/webapps
24 ln -s ${aten.app.webRoot} $out/webapps/${aten.apache.webappName}
25 '';
26 services.websites.production.modules = aten.apache.modules;
27 services.websites.production.vhostConfs.aten = {
28 certName = "aten";
29 certMainHost = "aten.pro";
30 hosts = [ "aten.pro" "www.aten.pro" ];
31 root = aten.apache.root;
32 extraConfig = [ aten.apache.vhostConf ];
33 };
34 };
35}
36