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