-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflake.nix
More file actions
175 lines (165 loc) · 5.59 KB
/
Copy pathflake.nix
File metadata and controls
175 lines (165 loc) · 5.59 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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
{
description = "Application packaged using poetry2nix";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
poetry2nix = {
url = "github:nix-community/poetry2nix";
inputs.nixpkgs.follows = "nixpkgs";
inputs.flake-utils.follows = "flake-utils";
inputs.systems.follows = "flake-utils/systems";
};
};
outputs = {
self,
nixpkgs,
flake-utils,
poetry2nix,
}:
flake-utils.lib.eachDefaultSystem (system: let
pkgs = nixpkgs.legacyPackages.${system};
inherit (poetry2nix.lib.mkPoetry2Nix {inherit pkgs;}) mkPoetryApplication mkPoetryEnv defaultPoetryOverrides overrides;
in {
formatter = pkgs.alejandra;
packages = {
slackfeeder = mkPoetryApplication {
projectDir = self;
overrides = overrides.withDefaults (self: super: {
slacker = super.slacker.overridePythonAttrs (old: {
buildInputs = (old.buildInputs or []) ++ [super.setuptools];
});
aiohttp-basicauth = super.aiohttp-basicauth.overridePythonAttrs (old: {
buildInputs = (old.buildInputs or []) ++ [super.setuptools];
});
});
};
default = self.packages.${system}.slackfeeder;
};
devShells.default = pkgs.mkShell {
inputsFrom = [self.packages.${system}.slackfeeder];
packages = [pkgs.poetry];
};
})
// {
nixosModules.default = {
config,
lib,
pkgs,
...
}:
with lib; {
options.services.slackfeeder = {
enable = mkEnableOption "Enable SlackFeeder service";
package = mkOption {
default = self.packages.${pkgs.system}.slackfeeder;
type = types.package;
};
Slack = {
token = mkOption {
default = null;
type = types.nullOr types.str;
description = "Slack OAuth access token";
};
token_file = mkOption {
default = null;
type = types.nullOr types.str;
description = "Slack OAuth access token";
};
};
Feed = {
title = mkOption {
default = "SlackFeeder";
type = types.str;
};
id = mkOption {
default = "";
type = types.str;
};
link = {
href = mkOption {
default = "";
type = types.str;
};
rel = mkOption {
default = "self";
type = types.str;
};
};
description = mkOption {
default = "Feed generated from Slack messages.";
type = types.str;
};
};
Auth = {
enable = mkOption {
default = false;
type = types.bool;
description = "Enable basic auth";
};
htpasswd = mkOption {
default = null;
type = types.nullOr types.str;
description = "Bcrypt password hash";
};
htpasswd_file = mkOption {
default = null;
type = types.nullOr types.str;
description = "Bcrypt password hash";
};
};
Network = {
host = mkOption {
default = "localhost";
type = types.str;
};
port = mkOption {
default = 8080;
type = types.int;
};
};
};
config = mkIf config.services.slackfeeder.enable {
environment.etc."slackfeeder.toml".text = with config.services.slackfeeder; ''
[Slack]
${optionalString (Slack.token != null) ''token = "${Slack.token}"''}
${optionalString (Slack.token_file != null) ''token_file = "${Slack.token_file}"''}
[Feed]
title = "${Feed.title}"
id = "${Feed.id}"
link.href = "${Feed.link.href}"
link.rel = "${Feed.link.rel}"
description = "${Feed.description}"
${optionalString Auth.enable ''
[Auth]
enable = ${toString Auth.enable}
${optionalString (Auth.htpasswd != null) ''htpasswd = "${Auth.htpasswd}"''}
${optionalString (Auth.htpasswd_file != null) ''htpasswd_file = "${Auth.htpasswd_file}"''}
''}
[Network]
host = "${Network.host}"
port = ${toString Network.port}
'';
systemd.services.slackfeeder = {
description = "Feed generated from Slack messages.";
after = ["network-online.target"];
wantedBy = ["multi-user.target"];
path = [config.services.slackfeeder.package];
script = "slackfeeder";
serviceConfig = {
ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
User = "slackfeeder";
Group = "slackfeeder";
};
};
users.users.slackfeeder = {
createHome = false;
isSystemUser = true;
group = "slackfeeder";
};
users.groups.slackfeeder = {
members = ["slackfeeder"];
};
};
};
};
}