forked from NixOS/nixpkgs
-
Notifications
You must be signed in to change notification settings - Fork 1
/
wazuh-agent.nix
62 lines (54 loc) · 1.6 KB
/
wazuh-agent.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
{ config, lib, pkgs, ... }:
with lib;
let
wazuhUser = "wazuh";
wazuhGroup = wazuhUser;
stateDir = "/var/ossec";
cfg = config.services.wazuh;
pkg = pkgs.wazuh;
in {
options = {
services.wazuh = {
agent = {
enable = mkEnableOption "Wazuh agent";
# TODO: mkOption -> XML for ossec.conf
};
};
};
config = mkIf ( cfg.agent.enable ) {
environment.systemPackages = [ pkg ];
users.users.${ wazuhUser } = {
uid = config.ids.uids.wazuh;
group = wazuhGroup;
description = "Wazuh daemon user";
home = stateDir;
};
users.groups.${ wazuhGroup } = {
gid = config.ids.gids.wazuh;
};
systemd.services.wazuh-agent = mkIf cfg.agent.enable {
description = "Wazuh agent";
wants = [ "network-online.target" ];
after = [ "network.target" "network-online.target" ];
wantedBy = [ "multi-user.target" ];
preStart = ''
mkdir -m 0750 -p ${stateDir}
cp -rf ${pkg}/* ${stateDir}
find ${stateDir} -type f -exec chmod 644 {} \;
find ${stateDir} -type d -exec chmod 750 {} \;
chmod u+x ${stateDir}/bin/*
chmod u+x ${stateDir}/active-response/bin/*
chown -R ${wazuhUser}:${wazuhGroup} ${stateDir}
'';
serviceConfig = {
Type = "forking";
WorkingDirectory = stateDir;
ExecStart = "env ${stateDir}/bin/wazuh-control start";
ExecStop = "env ${stateDir}/bin/wazuh-control stop";
ExecReload = "env ${stateDir}/bin/wazuh-control reload";
KillMode = "process";
RemainAfterExit = "yes";
};
};
};
}