-
Notifications
You must be signed in to change notification settings - Fork 0
/
local-images.nix
69 lines (59 loc) · 1.64 KB
/
local-images.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
{ mkDerivation, nginx, gnused }:
let
port = "8000";
serverConfigTemplate = ''
worker_processes 1;
error_log @@NGINX_DIR@@/error.log;
pid @@NGINX_DIR@@/nginx.pid;
daemon off;
events {
worker_connections 1024;
}
http {
default_type application/octet-stream;
access_log /dev/null;
error_log /dev/null;
sendfile on;
keepalive_timeout 65;
client_body_temp_path @@NGINX_DIR@@;
proxy_temp_path @@NGINX_DIR@@;
fastcgi_temp_path @@NGINX_DIR@@;
uwsgi_temp_path @@NGINX_DIR@@;
scgi_temp_path @@NGINX_DIR@@;
proxy_store off;
server {
listen ${port};
listen [::]:${port};
server_name localhost;
location / {
root @@DATA_DIR@@;
}
}
}
'';
defaultDataDir="/opt/sandbox/public";
in
mkDerivation {
pname = "vmplayer-nginx-server";
version = "1.0";
dontUnpack = true;
installPhase = ''
mkdir -p $out/{bin,share}
echo "${serverConfigTemplate}" > $out/share/nginx.conf.template
cat >> $out/bin/run-nginx <<- EOM
DATA_DIR=\$1
if [ -z "\$DATA_DIR" ]; then
DATA_DIR=${defaultDataDir}
fi
TEMP_DIR=\$(mktemp -d)
trap '{ rm -rf -- "\$TEMP_DIR"; }' EXIT
CONFIG=\$TEMP_DIR/nginx.conf
cp $out/share/nginx.conf.template \$CONFIG
${gnused}/bin/sed -i "s,@@NGINX_DIR@@,\$TEMP_DIR," "\$CONFIG"
${gnused}/bin/sed -i "s,@@DATA_DIR@@,\$DATA_DIR," "\$CONFIG"
${nginx}/bin/nginx -c \$CONFIG
EOM
chmod +x $out/bin/run-nginx
ln -s $out/bin/run-nginx $out/bin/vmplayer-nginx-server
'';
}