-
Notifications
You must be signed in to change notification settings - Fork 0
/
module.nix
63 lines (56 loc) · 1.6 KB
/
module.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
{self}: {
lib,
pkgs,
config,
...
}: let
inherit (lib) mkEnableOption mkOption types mkIf;
cfg = config.services.phone_db;
system = pkgs.stdenv.system;
phone_db_pkg = self.packages.${system}.default;
wrapper = pkgs.writeShellScriptBin "phone_db" ''
export PATH="$PATH:${pkgs.gawk}/bin"
export RELEASE_TMP="${cfg.data_dir}/tmp"
export HTTP_URL="${cfg.http_url}"
export PORT="${toString (cfg.port)}"
. "${cfg.secrets}"
mkdir -p "${cfg.data_dir}"
mkdir -p "${cfg.data_dir}/tmp"
exec "${phone_db_pkg}/bin/phone_db" "$@"
'';
in {
options.services.phone_db = {
enable = mkEnableOption "phone_db service";
secrets = mkOption {type = types.path;};
http_url = mkOption {type = types.str;};
port = mkOption {
type = types.int;
default = 4000;
};
data_dir = mkOption {
type = types.str;
default = "/var/lib/phone_db";
};
};
config = mkIf cfg.enable {
users.users.phone_db = {
isSystemUser = true;
description = "PhoneDB user";
group = "phone_db";
createHome = true;
home = "${cfg.data_dir}";
};
users.groups.phone_db = {};
systemd.services.phone_db = {
wantedBy = ["multi-user.target"];
after = ["network.target" "postgresql.service" "openldap.service"];
serviceConfig = {
User = "phone_db";
ExecStartPre = ''${wrapper}/bin/phone_db eval "PhoneDb.Release.migrate"'';
ExecStart = "${wrapper}/bin/phone_db start";
ExecStop = "${wrapper}/bin/phone_db stop";
ExecReload = "${wrapper}/bin/phone_db reload";
};
};
};
}