-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathconfiguration.nix
373 lines (327 loc) · 9.66 KB
/
configuration.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
# Edit this configuration file to define what should be installed on
# the system. Help is available in the configuration.nix(5) man page
# or the NixOS manual available on virtual console 8 (Alt+F8).
{ config, pkgs, ... }:
{
imports =
[ # Include the results of the hardware scan.
./hardware-configuration.nix
];
boot.initrd.kernelModules =
[ # Specify all kernel modules that are necessary for mounting the root
# filesystem.
# "xfs" "ata_piix"
];
# Use the GRUB 2 boot loader.
boot.loader.grub.enable = true;
boot.loader.grub.version = 2;
# Define on which hard drive you want to install Grub.
boot.loader.grub.device = "/dev/sda";
# networking.wireless.enable = true; # Enables Wireless.
networking = {
hostName = "easterhegg14"; # Define your hostname.
#bridges = {
# br0 = {
# interfaces = [ "enp0s3" ];
# };
#};
enableIPv6 = false;
interfaces.enp0s3 = {
ipAddress = "192.168.56.102";
prefixLength = 24;
};
defaultGateway = "192.168.56.1";
nameservers = [ "8.8.8.8" ];
firewall = {
enable = true;
allowedTCPPorts = [ 22 80 443 ];
};
extraHosts = ''
192.168.56.102 webservice0 webservice1 webservice2 webservice3 webservice4 webservice5
'';
};
# Add filesystem entries for each partition that you want to see
# mounted at boot time. This should include at least the root
# filesystem.
# fileSystems."/".device = "/dev/disk/by-label/nixos";
fileSystems."/".label = "system";
# fileSystems."/data" = # where you want to mount the device
# { device = "/dev/sdb"; # the device
# fsType = "ext3"; # the type of the partition
# options = "data=journal";
# };
# List swap partitions activated at boot time.
swapDevices =
[ # { device = "/dev/disk/by-label/swap"; }
];
# List services that you want to enable:
# Enable the OpenSSH daemon.
services.openssh.enable = true;
# SECURITY WARNING SECURITY WARNING SECURITY WARNING
#
# do not use this in production, nixos-containers are not meant for that !!!
#
# SECURITY WARNING SECURITY WARNING SECURITY WARNING
# for debugging use:
# journalctl status httpd.service
# journalctl -b -u httpd
# and do not forget to start the containers manually (even the declarative containers)
#
# once you did nixos-rebuild switch;
# for i in `seq 1 5`; do nixos-confainter start web$i; done
# for i in `seq 1 5`; do mkdir -p /var/lib/containers/web$i/webroot/; done
# for i in `seq 1 5`; do echo "<?php phpinfo(); ?>" > /var/lib/containers/web$i/webroot/index.php; done
# for i in `seq 1 5`; do echo "hello world from web$i" > /var/lib/containers/web$i/webroot/index.html; done
services.httpd = {
enable = true;
enableSSL = false;
adminAddr = "[email protected]";
virtualHosts =
[
# webservice0 vhost
# index.html works, browsing to index.php shows that php is not enabled
{
serverAliases = ["webservice0"];
documentRoot = "/webroot/";
extraConfig = ''
<Directory "/webroot/">
Options -Indexes
AllowOverride None
Order allow,deny
Allow from all
</Directory>
<IfModule mod_dir.c>
DirectoryIndex index.html
</IfModule>
'';
}
# webservice1 vhost
{
hostName = "webservice1";
serverAliases = ["webservice1"];
extraConfig = ''
# prevent a forward proxy!
ProxyRequests off
# User-Agent / browser identification is used from the original client
ProxyVia Off
ProxyPreserveHost On
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass / http://192.168.101.11:80/
ProxyPassReverse / http://192.168.101.11:80/
'';
}
## webservice2 vhost
{
hostName = "webservice2";
serverAliases = ["webservice2"];
extraConfig = ''
# prevent a forward proxy!
ProxyRequests off
# User-Agent / browser identification is used from the original client
ProxyVia Off
ProxyPreserveHost On
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass / http://192.168.102.11:80/
ProxyPassReverse / http://192.168.102.11:80/
'';
}
# webservice3 vhost
{
hostName = "webservice3";
serverAliases = ["webservice3"];
extraConfig = ''
# prevent a forward proxy!
ProxyRequests off
# User-Agent / browser identification is used from the original client
ProxyVia Off
ProxyPreserveHost On
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass / http://192.168.103.11:80/
ProxyPassReverse / http://192.168.103.11:80/
'';
}
# webservice4 vhost
{
hostName = "webservice4";
serverAliases = ["webservice4"];
extraConfig = ''
# prevent a forward proxy!
ProxyRequests off
# User-Agent / browser identification is used from the original client
ProxyVia Off
ProxyPreserveHost On
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass / http://192.168.104.11:80/
ProxyPassReverse / http://192.168.104.11:80/
'';
}
# webservice5 vhost
{
hostName = "webservice5";
serverAliases = ["webservice5"];
extraConfig = ''
# prevent a forward proxy!
ProxyRequests off
# User-Agent / browser identification is used from the original client
ProxyVia Off
ProxyPreserveHost On
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass / http://192.168.105.11:80/
ProxyPassReverse / http://192.168.105.11:80/
'';
}
];
};
containers.web1 = {
privateNetwork = true;
hostAddress = "192.168.101.10";
localAddress = "192.168.101.11";
config = { config, pkgs, ... }: {
networking.firewall = {
enable = true;
allowedTCPPorts = [ 80 443 ];
};
services.httpd = {
enable = true;
enableSSL = false;
adminAddr = "[email protected]";
documentRoot = "/webroot";
# we override the php version for all uses of pkgs.php with this,
# nix-env -qa --xml | grep php
# lists available versions of php
extraModules = [
{ name = "php5"; path = "${pkgs.php}/modules/libphp5.so"; }
];
};
};
};
containers.web2 = {
privateNetwork = true;
hostAddress = "192.168.102.10";
localAddress = "192.168.102.11";
config = { config, pkgs, ... }: {
# two additional programs are installed in the environment
environment.systemPackages = with pkgs; [
wget
nmap
];
networking.firewall = {
enable = true;
allowedTCPPorts = [ 80 443 ];
};
services.httpd = {
enable = true;
enableSSL = false;
adminAddr = "[email protected]";
documentRoot = "/webroot";
extraModules = [
# here we are using php-5.3.28 instead of php-5.4.23
{ name = "php5"; path = "${pkgs.php53}/modules/libphp5.so"; }
];
};
};
};
# container with a mediawiki instance
containers.web3 = {
privateNetwork = true;
hostAddress = "192.168.103.10";
localAddress = "192.168.103.11";
config = { config, pkgs, ... }: {
networking.firewall = {
enable = true;
allowedTCPPorts = [ 80 443 ];
};
services.postgresql = {
enable=true;
package = pkgs.postgresql92;
authentication = pkgs.lib.mkOverride 10 ''
local mediawiki all ident map=mwusers
local all all ident
'';
identMap = ''
mwusers root mediawiki
mwusers wwwrun mediawiki
'';
};
services.httpd = {
enable = true;
enableSSL = false;
adminAddr = "[email protected]";
documentRoot = "/webroot";
virtualHosts =
[
{
serverAliases = ["webservice3"];
extraConfig = ''
RedirectMatch ^/$ /wiki
'';
extraSubservices =
[
{
serviceType = "mediawiki";
siteName = "webservice3";
}
];
}
];
};
};
};
# lighttpd hello world example
containers.web4 = {
privateNetwork = true;
hostAddress = "192.168.104.10";
localAddress = "192.168.104.11";
config = { config, pkgs, ... }: {
networking.firewall = {
enable = true;
allowedTCPPorts = [ 80 443 ];
};
services.lighttpd = {
enable = true;
document-root = "/webroot";
};
};
};
# nginx hello world example
containers.web5 = {
privateNetwork = true;
hostAddress = "192.168.105.10";
localAddress = "192.168.105.11";
config = { config, pkgs, ... }: {
networking.firewall = {
enable = true;
allowedTCPPorts = [ 80 443 ];
};
services.nginx = {
enable = true;
config = ''
error_log /webroot/error.log;
events {}
http {
server {
access_log /webroot/access.log;
listen 80;
root /webroot;
}
}
'';
};
};
};
}