]>
Commit | Line | Data |
---|---|---|
1 | { lib, writeText, fetchedGitPrivate, stdenv, runCommand, composerEnv, fetchurl, fetchgit, jq, python, nodejs, libsass, yarn2nixPackage }: | |
2 | let | |
3 | aten = { config }: rec { | |
4 | environment = config.environment; | |
5 | varDir = "/var/lib/aten_${environment}"; | |
6 | phpFpm = rec { | |
7 | serviceDeps = [ "postgresql.service" "${environment}-aten-key.service" ]; | |
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 | keys."${environment}-aten" = { | |
34 | destDir = "/run/keys/webapps"; | |
35 | user = apache.user; | |
36 | group = apache.group; | |
37 | permissions = "0400"; | |
38 | text = '' | |
39 | SetEnv APP_ENV "${environment}" | |
40 | SetEnv APP_SECRET "${config.secret}" | |
41 | SetEnv DATABASE_URL "${config.psql_url}" | |
42 | ''; | |
43 | }; | |
44 | apache = rec { | |
45 | user = "wwwrun"; | |
46 | group = "wwwrun"; | |
47 | modules = [ "proxy_fcgi" ]; | |
48 | webappName = "aten_${environment}"; | |
49 | root = "/run/current-system/webapps/${webappName}"; | |
50 | vhostConf = '' | |
51 | <FilesMatch "\.php$"> | |
52 | SetHandler "proxy:unix:${phpFpm.socket}|fcgi://localhost" | |
53 | </FilesMatch> | |
54 | ||
55 | Include /run/keys/webapps/${environment}-aten | |
56 | ||
57 | ${if environment == "dev" then '' | |
58 | <Location /> | |
59 | Use LDAPConnect | |
60 | Require ldap-group cn=dev.aten.pro,cn=httpd,ou=services,dc=immae,dc=eu | |
61 | ErrorDocument 401 "<html><meta http-equiv=\"refresh\" content=\"0;url=https://aten.pro\"></html>" | |
62 | </Location> | |
63 | ||
64 | <Location /backend> | |
65 | Use LDAPConnect | |
66 | Require ldap-group cn=dev.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 | '' else '' | |
70 | Use Stats aten.pro | |
71 | ||
72 | <Location /backend> | |
73 | Use LDAPConnect | |
74 | Require ldap-group cn=aten.pro,cn=httpd,ou=services,dc=immae,dc=eu | |
75 | ErrorDocument 401 "<html><meta http-equiv=\"refresh\" content=\"0;url=https://aten.pro\"></html>" | |
76 | </Location> | |
77 | ''} | |
78 | ||
79 | <Directory ${root}> | |
80 | Options Indexes FollowSymLinks MultiViews Includes | |
81 | AllowOverride All | |
82 | Require all granted | |
83 | DirectoryIndex index.php | |
84 | FallbackResource /index.php | |
85 | </Directory> | |
86 | ''; | |
87 | }; | |
88 | activationScript = { | |
89 | deps = [ "wrappers" ]; | |
90 | text = '' | |
91 | install -m 0755 -o ${apache.user} -g ${apache.group} -d ${varDir} | |
92 | install -m 0750 -o ${apache.user} -g ${apache.group} -d ${varDir}/phpSessions | |
93 | if [ ! -f "${varDir}/currentWebappDir" -o \ | |
94 | "${webappDir}" != "$(cat ${varDir}/currentWebappDir 2>/dev/null)" ]; then | |
95 | pushd ${webappDir} > /dev/null | |
96 | $wrapperDir/sudo -u wwwrun APP_ENV=${environment} ./bin/console --env=${environment} cache:clear --no-warmup | |
97 | popd > /dev/null | |
98 | echo -n "${webappDir}" > ${varDir}/currentWebappDir | |
99 | fi | |
100 | ''; | |
101 | }; | |
102 | yarnModules = let | |
103 | info = fetchedGitPrivate ./aten.json; | |
104 | packagejson = runCommand "package.json" { buildInputs = [ jq ]; } '' | |
105 | cat ${info.src}/package.json | jq -r '.version = "v1.0.0"|.name="aten"' > $out | |
106 | ''; | |
107 | in | |
108 | yarn2nixPackage.mkYarnModules rec { | |
109 | name = "aten-yarn"; | |
110 | pname = name; | |
111 | version = "v1.0.0"; | |
112 | packageJSON = packagejson; | |
113 | yarnLock = "${info.src}/yarn.lock"; | |
114 | pkgConfig = { | |
115 | node-sass = { | |
116 | buildInputs = [ libsass python ]; | |
117 | postInstall = let | |
118 | nodeHeaders = fetchurl { | |
119 | url = "https://nodejs.org/download/release/v${nodejs.version}/node-v${nodejs.version}-headers.tar.gz"; | |
120 | sha256 = "16f20ya3ys6w5w6y6l4536f7jrgk4gz46bf71w1r1xxb26a54m32"; | |
121 | }; | |
122 | in | |
123 | '' | |
124 | node scripts/build.js --tarball=${nodeHeaders} | |
125 | ''; | |
126 | }; | |
127 | }; | |
128 | }; | |
129 | webappDir = composerEnv.buildPackage ( | |
130 | import ./php-packages.nix { inherit composerEnv fetchurl fetchgit; } // | |
131 | fetchedGitPrivate ./aten.json // | |
132 | rec { | |
133 | noDev = (environment == "prod"); | |
134 | preInstall = '' | |
135 | export SYMFONY_ENV="${environment}" | |
136 | export APP_ENV="${environment}" | |
137 | ''; | |
138 | postInstall = '' | |
139 | ln -sf ${yarnModules}/node_modules . | |
140 | yarn run --offline encore production | |
141 | rm -rf var/{log,cache} | |
142 | ln -sf ${varDir}/{log,cache} var/ | |
143 | ''; | |
144 | buildInputs = [ yarnModules yarn2nixPackage.yarn ]; | |
145 | }); | |
146 | webRoot = "${webappDir}/public"; | |
147 | }; | |
148 | in | |
149 | aten |