Repository navigation
Expand file tree
/
Copy pathdemo.nix
More file actions
103 lines (102 loc) · 2.41 KB
/
Copy pathdemo.nix
File metadata and controls
103 lines (102 loc) · 2.41 KB
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
{
config,
lib,
pkgs,
...
}:
let
htmlPackage = pkgs.writeTextFile {
name = "nginx-static-html";
destination = "/index.html";
text = # html
''
<!DOCTYPE html>
<html>
<head><title>Hello</title></head>
<body><h1>Hello World</h1></body>
</html>
'';
};
nginxConfig =
pkgs.writeText "nginxConfig" # nginx
''
daemon off;
pid /tmp/nginx.pid;
error_log /dev/stderr info;
events {}
http {
access_log /dev/stdout;
server {
listen 8080;
location / {
root ${htmlPackage};
index index.html;
}
}
}
'';
generatedServiceCount = 10;
in
{
imports = [
# Module that generates N minimal services for testing
(
{ lib, ... }:
{
config.services = lib.listToAttrs (
lib.genList (i: {
name = toString i;
value = {
type = "internal";
};
}) generatedServiceCount
);
}
)
];
config = {
env-file = {
variables = {
"DINITENV" = "DINITENV123";
};
};
users.enable = true;
# dinix.critical wires nginx to boot. These are wired by hand, to check
# that both reach the same boot service.
services.boot.depends-on = lib.genList toString (builtins.floor (generatedServiceCount / 2));
services.nginx = {
type = "process";
# nginx is the reason this container exists, so dinit exits when it
# stops and the container runtime restarts the lot.
dinix.critical = true;
command = pkgs.writeShellApplication {
name = "nginx-launcher";
text = # bash
''
exec ${lib.getExe pkgs.nginx} -c ${nginxConfig} -e /dev/stderr
'';
};
restart = true;
options = [
"shares-console"
"pass-cs-fd"
];
"@include" =
pkgs.writeText "includeTest" # dinit
''
depends-on: ${toString (generatedServiceCount - 1)}
'';
"@include-opt" = "/doesnt/exist";
"depends-on.d" = pkgs.writeTextFile {
name = "nginxdeps";
destination = "/${toString (generatedServiceCount - 2)}";
text = "";
};
env-file = {
variables = {
"NGINXENV" = "NGINXENV123";
};
};
};
};
}