-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdefault.nix
44 lines (43 loc) · 1.29 KB
/
default.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
{ pkgs }:
let
scriptDirectory = name: scripts: with pkgs.lib;
let
fileAttrSet =
mapAttrsRecursive
(path: src: {
name = last path;
path = "$out/" + concatStringsSep "/" (init path);
file = pkgs.writeScript (concatStringsSep "-" path) src;
})
scripts;
files = collect (x: x ? file && isDerivation x.file) fileAttrSet;
copier =
concatMapStringsSep "\n"
({ name, path, file }: ''
mkdir -p "${path}" && cp "${file}" "${path}"/"${name}"
'')
files;
in
pkgs.runCommand name
{ preferLocalBuild = true; }
copier;
in { port, scripts, user }:
let
conf = pkgs.writeText "cgi-mighty-conf" ''
Port: ${toString port}
Host: 127.0.0.1
Pid_File: /var/run/mighty-${toString port}.pid
Logging: No
'';
routes = pkgs.writeText "cgi-mighty-routes" ''
[*]
/ => ${scriptDirectory "cgi" scripts}
'';
in {
wantedBy = ["multi-user.target"];
environment = { PORT = builtins.toString port; };
serviceConfig = {
User = user;
ExecStart = "${pkgs.haskellPackages.mighttpd2}/bin/mighty ${conf} ${routes}";
};
}