]>
Commit | Line | Data |
---|---|---|
33aa7e5c | 1 | { lib, writeText, fetchedGitPrivate, stdenv, runCommand, composerEnv, fetchurl, fetchgit, jq, python, nodejs, libsass, yarn2nixPackage }: |
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 | }; | |
e5073add | 32 | apache = rec { |
6c672f34 IB |
33 | user = "wwwrun"; |
34 | group = "wwwrun"; | |
35 | modules = [ "proxy_fcgi" ]; | |
e5073add IB |
36 | webappName = "aten_${environment}"; |
37 | root = "/run/current-system/webapps/${webappName}"; | |
9d90e7e2 | 38 | vhostConf = '' |
6c672f34 IB |
39 | <FilesMatch "\.php$"> |
40 | SetHandler "proxy:unix:${phpFpm.socket}|fcgi://localhost" | |
41 | </FilesMatch> | |
42 | ||
43 | SetEnv APP_ENV "${environment}" | |
9d90e7e2 IB |
44 | SetEnv APP_SECRET "${config.secret}" |
45 | SetEnv DATABASE_URL "${config.psql_url}" | |
6c672f34 IB |
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 '' | |
34e2fd14 IB |
60 | Use Stats aten.pro |
61 | ||
6c672f34 IB |
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 | ||
7da3ceec | 69 | <Directory ${root}> |
6c672f34 IB |
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} | |
c8e019b6 | 82 | install -m 0750 -o ${apache.user} -g ${apache.group} -d ${varDir}/phpSessions |
6c672f34 IB |
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 | }; | |
625e0bfd IB |
92 | yarnModules = let |
93 | info = fetchedGitPrivate ./aten.json; | |
33aa7e5c IB |
94 | packagejson = runCommand "package.json" { buildInputs = [ jq ]; } '' |
95 | cat ${info.src}/package.json | jq -r '.version = "v1.0.0"|.name="aten"' > $out | |
96 | ''; | |
625e0bfd | 97 | in |
33aa7e5c IB |
98 | yarn2nixPackage.mkYarnModules rec { |
99 | name = "aten-yarn"; | |
100 | pname = name; | |
101 | version = "v1.0.0"; | |
102 | packageJSON = packagejson; | |
625e0bfd IB |
103 | yarnLock = "${info.src}/yarn.lock"; |
104 | pkgConfig = { | |
105 | node-sass = { | |
24a7da33 | 106 | buildInputs = [ libsass python ]; |
625e0bfd IB |
107 | postInstall = let |
108 | nodeHeaders = fetchurl { | |
109 | url = "https://nodejs.org/download/release/v${nodejs.version}/node-v${nodejs.version}-headers.tar.gz"; | |
587b9e34 | 110 | sha256 = "16f20ya3ys6w5w6y6l4536f7jrgk4gz46bf71w1r1xxb26a54m32"; |
625e0bfd IB |
111 | }; |
112 | in | |
113 | '' | |
625e0bfd IB |
114 | node scripts/build.js --tarball=${nodeHeaders} |
115 | ''; | |
116 | }; | |
117 | }; | |
118 | }; | |
119 | webappDir = composerEnv.buildPackage ( | |
120 | import ./php-packages.nix { inherit composerEnv fetchurl fetchgit; } // | |
121 | fetchedGitPrivate ./aten.json // | |
122 | rec { | |
123 | noDev = (environment == "prod"); | |
124 | preInstall = '' | |
125 | export SYMFONY_ENV="${environment}" | |
126 | export APP_ENV="${environment}" | |
127 | export DATABASE_URL="${config.psql_url}" | |
128 | export APP_SECRET="${config.secret}" | |
129 | ''; | |
130 | postInstall = '' | |
625e0bfd IB |
131 | ln -sf ${yarnModules}/node_modules . |
132 | yarn run --offline encore production | |
133 | rm -rf var/{log,cache} | |
3c8d7f87 | 134 | ln -sf ${varDir}/{log,cache} var/ |
625e0bfd | 135 | ''; |
33aa7e5c | 136 | buildInputs = [ yarnModules yarn2nixPackage.yarn ]; |
625e0bfd | 137 | }); |
6c672f34 IB |
138 | webRoot = "${webappDir}/public"; |
139 | }; | |
140 | in | |
141 | aten |