-
Notifications
You must be signed in to change notification settings - Fork 0
/
module.nix
78 lines (67 loc) · 1.79 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
self: {
config,
lib,
pkgs,
...
}: let
inherit
(lib)
types
;
inherit
(lib.modules)
mkIf
;
inherit
(lib.options)
mdDoc
mkEnableOption
mkOption
;
cfg = config.services.discord-to-authentik;
in {
options.services = {
discord-to-authentik = {
enable = mkEnableOption "discord-to-authentik";
package = mkOption {
type = types.package;
default = self.packages.${pkgs.system}.default;
description = "The discord-to-authentik package";
};
autoSyncRoles = mkOption {
type = types.bool;
default = true;
description = "Automatically sync roles from users";
};
environmentFile = mkOption {
type = types.path;
example = "/run/secrets/discord-to-authentik/discord-to-authentik-env";
description = mdDoc ''
Environment file as defined in {manpage}`systemd.exec(5)`.
```
# required content
DISCORD_OWNER_ID=<your discord user id>
DISCORD_BOT_TOKEN=<your discord bot token>
AUTHENTIK_HOST=<your authentik host>
AUTHENTIK_TOKEN=<your authentik token>
```
'';
};
};
};
config = mkIf cfg.enable {
systemd.services.discord-to-authentik = {
description = "A Discord bot that synchronizes your discord roles to authentik groups";
after = ["network.target"];
wants = ["network-online.target"];
serviceConfig = {
Type = "simple";
Restart = "always";
ExecStart = lib.getExe cfg.package;
EnvironmentFile = config.services.discord-to-authentik.environmentFile;
Environment = mkIf cfg.autoSyncRoles "DISCORD_AUTO_SYNC_ROLES=true";
};
wantedBy = ["multi-user.target"];
};
};
}