-
Notifications
You must be signed in to change notification settings - Fork 224
Expand file tree
/
Copy pathnixos-module.nix
More file actions
144 lines (125 loc) · 4.18 KB
/
Copy pathnixos-module.nix
File metadata and controls
144 lines (125 loc) · 4.18 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
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
{ config, lib, pkgs, ... }:
let
cfg = config.services.hackage-server;
pkg = cfg.package;
in
{
options.services.hackage-server = {
enable = lib.mkEnableOption "hackage-server, a Haskell package repository";
package = lib.mkPackageOption pkgs "hackage-server" { };
baseUri = lib.mkOption {
type = lib.types.str;
example = "https://hackage.example.org";
description = "The server's public base URI.";
};
userContentUri = lib.mkOption {
type = lib.types.str;
example = "https://hackage-content.example.org";
description = ''
The server's public user content base URI, used for untrusted
content to defeat XSS-style attacks.
'';
};
requiredBaseHostHeader = lib.mkOption {
type = lib.types.str;
example = "hackage-origin.example.org";
description = ''
Required Host header value for incoming requests. This may be
an internal hostname if the server is behind a reverse proxy.
'';
};
stateDir = lib.mkOption {
type = lib.types.path;
default = "/var/lib/hackage-server";
description = "Directory for the server's persistent state.";
};
datafilesDir = lib.mkOption {
type = lib.types.path;
# The Cabal data-files are installed under an ABI-specific path
# like share/ghc-X.Y.Z/<abi-hash>/hackage-server-0.6/
# We use a derivation to resolve the glob at build time.
default = pkgs.runCommand "hackage-server-datafiles" {} ''
templatesDir=$(find ${pkg.data or pkg}/share -name templates -type d | head -1)
if [ -z "$templatesDir" ]; then
echo "Could not find hackage-server data files in ${pkg.data or pkg}" >&2
exit 1
fi
datadir=$(dirname "$templatesDir")
ln -s "$datadir" $out
'';
defaultText = lib.literalMD "the data files of {option}`package`";
description = ''
Directory containing HTML templates, static files, and TUF keys.
'';
};
port = lib.mkOption {
type = lib.types.port;
default = 8080;
description = "TCP port to listen on.";
};
ip = lib.mkOption {
type = lib.types.str;
default = "127.0.0.1";
description = "IPv4 address to bind.";
};
user = lib.mkOption {
type = lib.types.str;
default = "hackage";
description = "User account under which hackage-server runs.";
};
group = lib.mkOption {
type = lib.types.str;
default = "hackage";
description = "Group under which hackage-server runs.";
};
};
config = lib.mkIf cfg.enable {
users.users.${cfg.user} = {
isSystemUser = true;
group = cfg.group;
home = cfg.stateDir;
description = "Hackage Server service user";
};
users.groups.${cfg.group} = { };
systemd.tmpfiles.rules = [
"d ${cfg.stateDir} 0750 ${cfg.user} ${cfg.group} -"
"d ${cfg.stateDir}/state 0750 ${cfg.user} ${cfg.group} -"
"d ${cfg.stateDir}/state/tmp 0750 ${cfg.user} ${cfg.group} -"
];
systemd.services.hackage-server = {
description = "Hackage Server";
after = [ "network-online.target" ];
wants = [ "network-online.target" ];
wantedBy = [ "multi-user.target" ];
preStart = ''
if [ ! -d "${cfg.stateDir}/state/db" ]; then
${lib.getExe pkg} init \
--state-dir="${cfg.stateDir}/state" \
--static-dir="${cfg.datafilesDir}"
fi
'';
serviceConfig = {
Type = "simple";
User = cfg.user;
Group = cfg.group;
Restart = "on-failure";
RestartSec = 3;
TimeoutStopSec = 120;
LimitNOFILE = 1073741824;
WorkingDirectory = cfg.stateDir;
ExecStart = lib.concatStringsSep " " [
(lib.getExe pkg)
"run"
"--ip=${cfg.ip}"
"--port=${toString cfg.port}"
"--base-uri=${cfg.baseUri}"
"--user-content-uri=${cfg.userContentUri}"
"--required-base-host-header=${cfg.requiredBaseHostHeader}"
"--state-dir=${cfg.stateDir}/state"
"--static-dir=${cfg.datafilesDir}"
"--tmp-dir=${cfg.stateDir}/state/tmp"
];
};
};
};
}