]>
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 | 6 | phpFpm = rec { |
a0c845b4 | 7 | serviceDeps = [ "postgresql.service" "${environment}-aten-key.service" ]; |
6c672f34 IB |
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" | |
c8e019b6 | 19 | php_admin_value[session.save_path] = "${varDir}/phpSessions" |
6c672f34 IB |
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 | }; | |
a754e9db IB |
33 | keys."${environment}-aten" = { |
34 | destDir = "/run/keys/webapps"; | |
35 | user = apache.user; | |
36 | group = apache.group; | |
85f5ed68 | 37 | permissions = "0400"; |
a754e9db IB |
38 | text = '' |
39 | SetEnv APP_ENV "${environment}" | |
40 | SetEnv APP_SECRET "${config.secret}" | |
41 | SetEnv DATABASE_URL "${config.psql_url}" | |
42 | ''; | |
43 | }; | |
e5073add | 44 | apache = rec { |
6c672f34 IB |
45 | user = "wwwrun"; |
46 | group = "wwwrun"; | |
47 | modules = [ "proxy_fcgi" ]; | |
e5073add IB |
48 | webappName = "aten_${environment}"; |
49 | root = "/run/current-system/webapps/${webappName}"; | |
9d90e7e2 | 50 | vhostConf = '' |
6c672f34 IB |
51 | <FilesMatch "\.php$"> |
52 | SetHandler "proxy:unix:${phpFpm.socket}|fcgi://localhost" | |
53 | </FilesMatch> | |
54 | ||
a754e9db | 55 | Include /run/keys/webapps/${environment}-aten |
6c672f34 IB |
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 '' | |
34e2fd14 IB |
70 | Use Stats aten.pro |
71 | ||
6c672f34 IB |
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 | ||
7da3ceec | 79 | <Directory ${root}> |
6c672f34 IB |
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} | |
c8e019b6 | 92 | install -m 0750 -o ${apache.user} -g ${apache.group} -d ${varDir}/phpSessions |
6c672f34 IB |
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 | }; | |
625e0bfd IB |
102 | yarnModules = let |
103 | info = fetchedGitPrivate ./aten.json; | |
33aa7e5c IB |
104 | packagejson = runCommand "package.json" { buildInputs = [ jq ]; } '' |
105 | cat ${info.src}/package.json | jq -r '.version = "v1.0.0"|.name="aten"' > $out | |
106 | ''; | |
625e0bfd | 107 | in |
33aa7e5c IB |
108 | yarn2nixPackage.mkYarnModules rec { |
109 | name = "aten-yarn"; | |
110 | pname = name; | |
111 | version = "v1.0.0"; | |
112 | packageJSON = packagejson; | |
625e0bfd IB |
113 | yarnLock = "${info.src}/yarn.lock"; |
114 | pkgConfig = { | |
115 | node-sass = { | |
24a7da33 | 116 | buildInputs = [ libsass python ]; |
625e0bfd IB |
117 | postInstall = let |
118 | nodeHeaders = fetchurl { | |
119 | url = "https://nodejs.org/download/release/v${nodejs.version}/node-v${nodejs.version}-headers.tar.gz"; | |
587b9e34 | 120 | sha256 = "16f20ya3ys6w5w6y6l4536f7jrgk4gz46bf71w1r1xxb26a54m32"; |
625e0bfd IB |
121 | }; |
122 | in | |
123 | '' | |
625e0bfd IB |
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}" | |
625e0bfd IB |
137 | ''; |
138 | postInstall = '' | |
625e0bfd IB |
139 | ln -sf ${yarnModules}/node_modules . |
140 | yarn run --offline encore production | |
141 | rm -rf var/{log,cache} | |
3c8d7f87 | 142 | ln -sf ${varDir}/{log,cache} var/ |
625e0bfd | 143 | ''; |
33aa7e5c | 144 | buildInputs = [ yarnModules yarn2nixPackage.yarn ]; |
625e0bfd | 145 | }); |
6c672f34 IB |
146 | webRoot = "${webappDir}/public"; |
147 | }; | |
148 | in | |
149 | aten |