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