]>
Commit | Line | Data |
---|---|---|
1 | { lib, checkEnv, writeText, fetchedGitPrivate, stdenv, php, git, cacert, phpPackages, yarn }: | |
2 | let | |
3 | aten = { environment ? "dev" }: rec { | |
4 | varPrefix = "ATEN"; | |
5 | varDir = "/var/lib/aten_${environment}"; | |
6 | envName= lib.strings.toUpper environment; | |
7 | phpFpm = rec { | |
8 | socket = "/var/run/phpfpm/aten-${environment}.sock"; | |
9 | pool = '' | |
10 | listen = ${socket} | |
11 | user = ${apache.user} | |
12 | group = ${apache.group} | |
13 | listen.owner = ${apache.user} | |
14 | listen.group = ${apache.group} | |
15 | php_admin_value[upload_max_filesize] = 20M | |
16 | php_admin_value[post_max_size] = 20M | |
17 | ;php_admin_flag[log_errors] = on | |
18 | php_admin_value[open_basedir] = "${webappDir}:${varDir}:/tmp" | |
19 | ${if environment == "dev" then '' | |
20 | pm = ondemand | |
21 | pm.max_children = 5 | |
22 | pm.process_idle_timeout = 60 | |
23 | env[SYMFONY_DEBUG_MODE] = "yes" | |
24 | '' else '' | |
25 | pm = dynamic | |
26 | pm.max_children = 20 | |
27 | pm.start_servers = 2 | |
28 | pm.min_spare_servers = 1 | |
29 | pm.max_spare_servers = 3 | |
30 | ''}''; | |
31 | }; | |
32 | apache = { | |
33 | user = "wwwrun"; | |
34 | group = "wwwrun"; | |
35 | modules = [ "proxy_fcgi" ]; | |
36 | vhostConf = | |
37 | assert checkEnv "NIXOPS_${varPrefix}_${envName}_SECRET"; | |
38 | assert checkEnv "NIXOPS_${varPrefix}_${envName}_PSQL_URL"; | |
39 | '' | |
40 | Use Stats aten.pro | |
41 | ||
42 | <FilesMatch "\.php$"> | |
43 | SetHandler "proxy:unix:${phpFpm.socket}|fcgi://localhost" | |
44 | </FilesMatch> | |
45 | ||
46 | SetEnv APP_ENV "${environment}" | |
47 | SetEnv APP_SECRET "${builtins.getEnv "NIXOPS_${varPrefix}_${envName}_SECRET"} | |
48 | SetEnv DATABASE_URL "${builtins.getEnv "NIXOPS_${varPrefix}_${envName}_PSQL_URL"} | |
49 | ||
50 | ${if environment == "dev" then '' | |
51 | <Location /> | |
52 | Use LDAPConnect | |
53 | Require ldap-group cn=dev.aten.pro,cn=httpd,ou=services,dc=immae,dc=eu | |
54 | ErrorDocument 401 "<html><meta http-equiv=\"refresh\" content=\"0;url=https://aten.pro\"></html>" | |
55 | </Location> | |
56 | ||
57 | <Location /backend> | |
58 | Use LDAPConnect | |
59 | Require ldap-group cn=dev.aten.pro,cn=httpd,ou=services,dc=immae,dc=eu | |
60 | ErrorDocument 401 "<html><meta http-equiv=\"refresh\" content=\"0;url=https://aten.pro\"></html>" | |
61 | </Location> | |
62 | '' else '' | |
63 | <Location /backend> | |
64 | Use LDAPConnect | |
65 | Require ldap-group cn=aten.pro,cn=httpd,ou=services,dc=immae,dc=eu | |
66 | ErrorDocument 401 "<html><meta http-equiv=\"refresh\" content=\"0;url=https://aten.pro\"></html>" | |
67 | </Location> | |
68 | ''} | |
69 | ||
70 | <Directory ${webRoot}> | |
71 | Options Indexes FollowSymLinks MultiViews Includes | |
72 | AllowOverride All | |
73 | Require all granted | |
74 | DirectoryIndex index.php | |
75 | FallbackResource /index.php | |
76 | </Directory> | |
77 | ''; | |
78 | }; | |
79 | activationScript = { | |
80 | deps = [ "wrappers" ]; | |
81 | text = '' | |
82 | install -m 0755 -o ${apache.user} -g ${apache.group} -d ${varDir} | |
83 | if [ ! -f "${varDir}/currentWebappDir" -o \ | |
84 | "${webappDir}" != "$(cat ${varDir}/currentWebappDir 2>/dev/null)" ]; then | |
85 | pushd ${webappDir} > /dev/null | |
86 | $wrapperDir/sudo -u wwwrun APP_ENV=${environment} ./bin/console --env=${environment} cache:clear --no-warmup | |
87 | popd > /dev/null | |
88 | echo -n "${webappDir}" > ${varDir}/currentWebappDir | |
89 | fi | |
90 | ''; | |
91 | }; | |
92 | webappDir = stdenv.mkDerivation (fetchedGitPrivate ./aten.json // rec { | |
93 | # FIXME: can we do better than symlink? | |
94 | # FIXME: initial sync | |
95 | # FIXME: backup | |
96 | # FIXME: usage statistics | |
97 | buildPhase = '' | |
98 | export GIT_SSL_CAINFO=${cacert}/etc/ssl/certs/ca-bundle.crt | |
99 | export SSL_CERT_FILE=${cacert}/etc/ssl/certs/ca-bundle.crt | |
100 | export APP_ENV="${environment}" | |
101 | export DATABASE_URL="${builtins.getEnv "NIXOPS_${varPrefix}_${envName}_PSQL_URL"}" | |
102 | export APP_SECRET="${builtins.getEnv "NIXOPS_${varPrefix}_${envName}_SECRET"}" | |
103 | ||
104 | ${if environment == "dev" then '' | |
105 | composer install | |
106 | '' else '' | |
107 | SYMFONY_ENV=prod composer install --no-dev | |
108 | ''} | |
109 | yarn install | |
110 | yarn run encore production | |
111 | rm -rf var | |
112 | ln -sf ../../../../../${varDir} var | |
113 | ''; | |
114 | installPhase = '' | |
115 | cp -a . $out | |
116 | ''; | |
117 | buildInputs = [ | |
118 | php git cacert phpPackages.composer yarn | |
119 | ]; | |
120 | }); | |
121 | webRoot = "${webappDir}/public"; | |
122 | }; | |
123 | in | |
124 | aten |