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