-
Notifications
You must be signed in to change notification settings - Fork 0
/
svc.nix
58 lines (53 loc) · 1.41 KB
/
svc.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
{ pkgs }: rec {
inherit (pkgs.lib) mapAttrsToList pipe;
oneshot = { deps ? { }, up, down ? "", extra ? { } }: service {
type = "oneshot";
inherit deps;
extra = extra // { inherit up; } //
(if down != "" then { inherit down; } else { });
};
longrun = { deps ? { }, run, extra ? { } }: service {
type = "longrun";
inherit deps;
extra = extra // { run = "#!${pkgs.execline}/bin/execlineb -P\n" + run; };
};
service = { type, deps, extra }: ''
echo ${type} > type
${if deps != {} then "mkdir dependencies.d" else ""}
'' + pipe deps [
(builtins.attrNames)
(map (i: "touch dependencies.d/${i}"))
(builtins.concatStringsSep "\n")
] + "\n" + pipe ({ timeout-kill = "3000"; } // extra) [
(mapAttrsToList (name: text: ''
cp ${pkgs.writeText name (text + "\n")} ${name}
''))
(builtins.concatStringsSep "\n")
];
bundle = deps: ''
echo bundle > type
mkdir contents.d
'' + pipe deps [
(builtins.attrNames)
(map (i: "touch contents.d/${i}"))
(builtins.concatStringsSep "\n")
];
mkDB = services: pipe services [
(mapAttrsToList (name: cmd: ''
mkdir ${name}
cd ${name}
${cmd}
cd ..
''))
(builtins.concatStringsSep "\n")
(i: ''
mkdir svc
cd svc
${i}
cd ..
${pkgs.s6-rc}/bin/s6-rc-compile $out svc
cp -r svc $out/src
'')
(pkgs.runCommand "mkDB" { })
];
}