]>
Commit | Line | Data |
---|---|---|
1 | { lib, writeText, fetchedGitPrivate, stdenv, composerEnv, fetchurl, fetchgit, python, nodejs, libsass, yarn2nix }: | |
2 | let | |
3 | aten = { config }: rec { | |
4 | environment = config.environment; | |
5 | varDir = "/var/lib/aten_${environment}"; | |
6 | phpFpm = rec { | |
7 | socket = "/var/run/phpfpm/aten-${environment}.sock"; | |
8 | pool = '' | |
9 | listen = ${socket} | |
10 | user = ${apache.user} | |
11 | group = ${apache.group} | |
12 | listen.owner = ${apache.user} | |
13 | listen.group = ${apache.group} | |
14 | php_admin_value[upload_max_filesize] = 20M | |
15 | php_admin_value[post_max_size] = 20M | |
16 | ;php_admin_flag[log_errors] = on | |
17 | php_admin_value[open_basedir] = "${webappDir}:${varDir}:/tmp" | |
18 | php_admin_value[session.save_path] = "${varDir}/phpSessions" | |
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 = rec { | |
33 | user = "wwwrun"; | |
34 | group = "wwwrun"; | |
35 | modules = [ "proxy_fcgi" ]; | |
36 | webappName = "aten_${environment}"; | |
37 | root = "/run/current-system/webapps/${webappName}"; | |
38 | vhostConf = '' | |
39 | <FilesMatch "\.php$"> | |
40 | SetHandler "proxy:unix:${phpFpm.socket}|fcgi://localhost" | |
41 | </FilesMatch> | |
42 | ||
43 | SetEnv APP_ENV "${environment}" | |
44 | SetEnv APP_SECRET "${config.secret}" | |
45 | SetEnv DATABASE_URL "${config.psql_url}" | |
46 | ||
47 | ${if environment == "dev" then '' | |
48 | <Location /> | |
49 | Use LDAPConnect | |
50 | Require ldap-group cn=dev.aten.pro,cn=httpd,ou=services,dc=immae,dc=eu | |
51 | ErrorDocument 401 "<html><meta http-equiv=\"refresh\" content=\"0;url=https://aten.pro\"></html>" | |
52 | </Location> | |
53 | ||
54 | <Location /backend> | |
55 | Use LDAPConnect | |
56 | Require ldap-group cn=dev.aten.pro,cn=httpd,ou=services,dc=immae,dc=eu | |
57 | ErrorDocument 401 "<html><meta http-equiv=\"refresh\" content=\"0;url=https://aten.pro\"></html>" | |
58 | </Location> | |
59 | '' else '' | |
60 | Use Stats aten.pro | |
61 | ||
62 | <Location /backend> | |
63 | Use LDAPConnect | |
64 | Require ldap-group cn=aten.pro,cn=httpd,ou=services,dc=immae,dc=eu | |
65 | ErrorDocument 401 "<html><meta http-equiv=\"refresh\" content=\"0;url=https://aten.pro\"></html>" | |
66 | </Location> | |
67 | ''} | |
68 | ||
69 | <Directory ${root}> | |
70 | Options Indexes FollowSymLinks MultiViews Includes | |
71 | AllowOverride All | |
72 | Require all granted | |
73 | DirectoryIndex index.php | |
74 | FallbackResource /index.php | |
75 | </Directory> | |
76 | ''; | |
77 | }; | |
78 | activationScript = { | |
79 | deps = [ "wrappers" ]; | |
80 | text = '' | |
81 | install -m 0755 -o ${apache.user} -g ${apache.group} -d ${varDir} | |
82 | install -m 0750 -o ${apache.user} -g ${apache.group} -d ${varDir}/phpSessions | |
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 | yarnModules = let | |
93 | info = fetchedGitPrivate ./aten.json; | |
94 | in | |
95 | yarn2nix.mkYarnModules { | |
96 | name = "aten-yarn-modules"; | |
97 | packageJSON = "${info.src}/package.json"; | |
98 | yarnLock = "${info.src}/yarn.lock"; | |
99 | pkgConfig = { | |
100 | node-sass = { | |
101 | buildInputs = [ libsass python ]; | |
102 | postInstall = let | |
103 | nodeHeaders = fetchurl { | |
104 | url = "https://nodejs.org/download/release/v${nodejs.version}/node-v${nodejs.version}-headers.tar.gz"; | |
105 | sha256 = "12zzsf8my43b8qnlacp871ih5vqafl2vlpqp51xp6h3gckn2frwy"; | |
106 | }; | |
107 | in | |
108 | '' | |
109 | node scripts/build.js --tarball=${nodeHeaders} | |
110 | ''; | |
111 | }; | |
112 | }; | |
113 | }; | |
114 | webappDir = composerEnv.buildPackage ( | |
115 | import ./php-packages.nix { inherit composerEnv fetchurl fetchgit; } // | |
116 | fetchedGitPrivate ./aten.json // | |
117 | rec { | |
118 | noDev = (environment == "prod"); | |
119 | preInstall = '' | |
120 | export SYMFONY_ENV="${environment}" | |
121 | export APP_ENV="${environment}" | |
122 | export DATABASE_URL="${config.psql_url}" | |
123 | export APP_SECRET="${config.secret}" | |
124 | ''; | |
125 | postInstall = '' | |
126 | cd $out | |
127 | ln -sf ${yarnModules}/node_modules . | |
128 | yarn run --offline encore production | |
129 | rm -rf var/{log,cache} | |
130 | ln -sf ../../../../../../../${varDir}/{log,cache} var/ | |
131 | ''; | |
132 | buildInputs = [ yarnModules yarn2nix yarn2nix.yarn ]; | |
133 | }); | |
134 | webRoot = "${webappDir}/public"; | |
135 | }; | |
136 | in | |
137 | aten |