-
Notifications
You must be signed in to change notification settings - Fork 49
/
nginx.nix
41 lines (41 loc) · 948 Bytes
/
nginx.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
{ pkgs, nix2container }:
let
nginxPort = "80";
nginxConf = pkgs.writeText "nginx.conf" ''
user nobody nobody;
daemon off;
error_log /dev/stdout info;
pid /dev/null;
events {}
http {
access_log /dev/stdout;
server {
listen ${nginxPort};
index index.html;
location / {
root ${nginxWebRoot};
}
}
}
'';
nginxWebRoot = pkgs.writeTextDir "index.html" ''
<html><body><h1>Hello from NGINX</h1></body></html>
'';
nginxVar = pkgs.runCommand "nginx-var" {} ''
mkdir -p $out/var/log/nginx
mkdir -p $out/var/cache/nginx
'';
in
nix2container.buildImage {
name = "nginx";
copyToRoot = [
pkgs.dockerTools.fakeNss
nginxVar
];
config = {
Cmd = [ "${pkgs.nginx}/bin/nginx" "-c" nginxConf ];
ExposedPorts = {
"${nginxPort}/tcp" = {};
};
};
}