diff options
Diffstat (limited to 'virtual/packages/aten.nix')
-rw-r--r-- | virtual/packages/aten.nix | 122 |
1 files changed, 122 insertions, 0 deletions
diff --git a/virtual/packages/aten.nix b/virtual/packages/aten.nix new file mode 100644 index 0000000..016676f --- /dev/null +++ b/virtual/packages/aten.nix | |||
@@ -0,0 +1,122 @@ | |||
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 | <FilesMatch "\.php$"> | ||
41 | SetHandler "proxy:unix:${phpFpm.socket}|fcgi://localhost" | ||
42 | </FilesMatch> | ||
43 | |||
44 | SetEnv APP_ENV "${environment}" | ||
45 | SetEnv APP_SECRET "${builtins.getEnv "NIXOPS_${varPrefix}_${envName}_SECRET"} | ||
46 | SetEnv DATABASE_URL "${builtins.getEnv "NIXOPS_${varPrefix}_${envName}_PSQL_URL"} | ||
47 | |||
48 | ${if environment == "dev" then '' | ||
49 | <Location /> | ||
50 | Use LDAPConnect | ||
51 | Require ldap-group cn=dev.aten.pro,cn=httpd,ou=services,dc=immae,dc=eu | ||
52 | ErrorDocument 401 "<html><meta http-equiv=\"refresh\" content=\"0;url=https://aten.pro\"></html>" | ||
53 | </Location> | ||
54 | |||
55 | <Location /backend> | ||
56 | Use LDAPConnect | ||
57 | Require ldap-group cn=dev.aten.pro,cn=httpd,ou=services,dc=immae,dc=eu | ||
58 | ErrorDocument 401 "<html><meta http-equiv=\"refresh\" content=\"0;url=https://aten.pro\"></html>" | ||
59 | </Location> | ||
60 | '' else '' | ||
61 | <Location /backend> | ||
62 | Use LDAPConnect | ||
63 | Require ldap-group cn=aten.pro,cn=httpd,ou=services,dc=immae,dc=eu | ||
64 | ErrorDocument 401 "<html><meta http-equiv=\"refresh\" content=\"0;url=https://aten.pro\"></html>" | ||
65 | </Location> | ||
66 | ''} | ||
67 | |||
68 | <Directory ${webRoot}> | ||
69 | Options Indexes FollowSymLinks MultiViews Includes | ||
70 | AllowOverride All | ||
71 | Require all granted | ||
72 | DirectoryIndex index.php | ||
73 | FallbackResource /index.php | ||
74 | </Directory> | ||
75 | ''; | ||
76 | }; | ||
77 | activationScript = { | ||
78 | deps = [ "wrappers" ]; | ||
79 | text = '' | ||
80 | install -m 0755 -o ${apache.user} -g ${apache.group} -d ${varDir} | ||
81 | if [ ! -f "${varDir}/currentWebappDir" -o \ | ||
82 | "${webappDir}" != "$(cat ${varDir}/currentWebappDir 2>/dev/null)" ]; then | ||
83 | pushd ${webappDir} > /dev/null | ||
84 | $wrapperDir/sudo -u wwwrun APP_ENV=${environment} ./bin/console --env=${environment} cache:clear --no-warmup | ||
85 | popd > /dev/null | ||
86 | echo -n "${webappDir}" > ${varDir}/currentWebappDir | ||
87 | fi | ||
88 | ''; | ||
89 | }; | ||
90 | webappDir = stdenv.mkDerivation (fetchedGitPrivate ./aten.json // rec { | ||
91 | # FIXME: can we do better than symlink? | ||
92 | # FIXME: initial sync | ||
93 | # FIXME: backup | ||
94 | # FIXME: usage statistics | ||
95 | buildPhase = '' | ||
96 | export GIT_SSL_CAINFO=${cacert}/etc/ssl/certs/ca-bundle.crt | ||
97 | export SSL_CERT_FILE=${cacert}/etc/ssl/certs/ca-bundle.crt | ||
98 | export APP_ENV="${environment}" | ||
99 | export DATABASE_URL="${builtins.getEnv "NIXOPS_${varPrefix}_${envName}_PSQL_URL"}" | ||
100 | export APP_SECRET="${builtins.getEnv "NIXOPS_${varPrefix}_${envName}_SECRET"}" | ||
101 | |||
102 | ${if environment == "dev" then '' | ||
103 | composer install | ||
104 | '' else '' | ||
105 | SYMFONY_ENV=prod composer install --no-dev | ||
106 | ''} | ||
107 | yarn install | ||
108 | yarn run encore production | ||
109 | rm -rf var | ||
110 | ln -sf ../../../../../${varDir} var | ||
111 | ''; | ||
112 | installPhase = '' | ||
113 | cp -a . $out | ||
114 | ''; | ||
115 | buildInputs = [ | ||
116 | php git cacert phpPackages.composer yarn | ||
117 | ]; | ||
118 | }); | ||
119 | webRoot = "${webappDir}/public"; | ||
120 | }; | ||
121 | in | ||
122 | aten | ||