-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathservice.nix
145 lines (114 loc) · 3.4 KB
/
service.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
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.services.nixpkgs-monitor;
env_db = optionalAttrs (cfg.database != null) { DB = cfg.database; };
npmon = import ./default.nix { inherit pkgs; };
in
{
###### interface
options = {
services.nixpkgs-monitor = rec {
enable = mkOption {
default = false;
description = ''
Whether to run Nixpkgs-monitor services.
'';
};
baseDir = mkOption {
default = "/var/lib/nixpkgs-monitor";
description = ''
The directory holding configuration, logs and temporary files.
'';
};
user = mkOption {
default = "nixpkgsmon";
description = ''
The user the Nixpkgs-monitor services should run as.
'';
};
host = mkOption {
default = "localhost";
description = ''
The IP address to listen at.
'';
};
port = mkOption {
default = 4567;
description = ''
The IP address to listen at.
'';
};
baseUrl = mkOption {
default = null;
description = ''
Base URL at which the monitor should run.
'';
};
database = mkOption {
default = null;
example = "postgres://db_user:db_password@host/db_name";
description = ''
Use the specified database instead of the default(sqlite) one.
'';
};
builderCount = mkOption {
default = 1;
description = ''
The number of builds to run in parallel
'';
};
};
};
###### implementation
config = mkIf cfg.enable {
users.extraUsers = singleton {
name = cfg.user;
description = "Nixpkgs-monitor";
home = cfg.baseDir;
createHome = true;
useDefaultShell = true;
};
systemd.services."nixpkgs-monitor-site" = {
wantedBy = [ "multi-user.target" ];
environment =
env_db //
optionalAttrs (cfg.baseUrl != null) { BASE_URL = cfg.baseUrl; };
serviceConfig = {
ExecStart = "${npmon}/bin/nixpkgs-monitor-site -p ${toString cfg.port} -o ${cfg.host}";
User = cfg.user;
Restart = "always";
WorkingDirectory = cfg.baseDir;
};
};
systemd.services."nixpkgs-monitor-updater" = {
path = [ pkgs.xz ];
environment = {
NIX_REMOTE = "daemon";
NIX_CONF_DIR = "/etc/nix";
OPENSSL_X509_CERT_FILE = "/etc/ssl/certs/ca-certificates.crt";
GIT_SSL_CAINFO = "/etc/ssl/certs/ca-certificates.crt";
CURL_CA_BUNDLE = "/etc/ssl/certs/ca-certificates.crt";
SSL_CERT_FILE = "/etc/ssl/certs/ca-certificates.crt";
NIX_PATH = "/nix/var/nix/profiles/per-user/root/channels/nixos"; # to be able to prefetch mirror:// urls
} // env_db;
script = ''
${npmon}/bin/nixpkgs-monitor --all
${pkgs.curl}/bin/curl ${cfg.host}:${toString cfg.port}/refresh
${npmon}/bin/nixpkgs-monitor --build --builder-count ${toString cfg.builderCount}
'';
serviceConfig = {
User = cfg.user;
WorkingDirectory = cfg.baseDir;
};
};
systemd.services."nixpkgs-monitor-updater-drop-negative-cache" = {
environment = env_db;
serviceConfig = {
ExecStart = "${npmon}/bin/nixpkgs-monitor --redownload --rebuild";
User = cfg.user;
WorkingDirectory = cfg.baseDir;
};
};
};
}