tangled
alpha
login
or
join now
pyrox.dev
/
nixpkgs
lol
0
fork
atom
overview
issues
pulls
pipelines
frab module: init
Franz Pletz
9 years ago
fbf762e0
2450c867
+225
2 changed files
expand all
collapse all
unified
split
nixos
modules
module-list.nix
services
web-apps
frab.nix
+1
nixos/modules/module-list.nix
···
521
521
./services/web-apps/atlassian/confluence.nix
522
522
./services/web-apps/atlassian/crowd.nix
523
523
./services/web-apps/atlassian/jira.nix
524
524
+
./services/web-apps/frab.nix
524
525
./services/web-apps/mattermost.nix
525
526
./services/web-apps/nixbot.nix
526
527
./services/web-apps/pump.io.nix
+224
nixos/modules/services/web-apps/frab.nix
···
1
1
+
{ config, lib, pkgs, ... }:
2
2
+
3
3
+
with lib;
4
4
+
5
5
+
let
6
6
+
cfg = config.services.frab;
7
7
+
8
8
+
package = pkgs.frab;
9
9
+
ruby = package.ruby;
10
10
+
11
11
+
databaseConfig = builtins.toJSON { production = cfg.database; };
12
12
+
13
13
+
frabEnv = {
14
14
+
RAILS_ENV = "production";
15
15
+
RACK_ENV = "production";
16
16
+
SECRET_KEY_BASE = cfg.secretKeyBase;
17
17
+
FRAB_HOST = cfg.host;
18
18
+
FRAB_PROTOCOL = cfg.protocol;
19
19
+
FROM_EMAIL = cfg.fromEmail;
20
20
+
RAILS_SERVE_STATIC_FILES = "1";
21
21
+
} // cfg.extraEnvironment;
22
22
+
23
23
+
frab-rake = pkgs.stdenv.mkDerivation rec {
24
24
+
name = "frab-rake";
25
25
+
buildInputs = [ package.env pkgs.makeWrapper ];
26
26
+
phases = "installPhase fixupPhase";
27
27
+
installPhase = ''
28
28
+
mkdir -p $out/bin
29
29
+
makeWrapper ${package.env}/bin/bundle $out/bin/frab-bundle \
30
30
+
${concatStrings (mapAttrsToList (name: value: "--set ${name} '${value}' ") frabEnv)} \
31
31
+
--set PATH '${lib.makeBinPath (with pkgs; [ nodejs file imagemagick ])}:$PATH' \
32
32
+
--set RAKEOPT '-f ${package}/share/frab/Rakefile' \
33
33
+
--run 'cd ${package}/share/frab'
34
34
+
makeWrapper $out/bin/frab-bundle $out/bin/frab-rake \
35
35
+
--add-flags "exec rake"
36
36
+
'';
37
37
+
};
38
38
+
39
39
+
in
40
40
+
41
41
+
{
42
42
+
options = {
43
43
+
services.frab = {
44
44
+
enable = mkOption {
45
45
+
type = types.bool;
46
46
+
default = false;
47
47
+
description = ''
48
48
+
Enable the frab service.
49
49
+
'';
50
50
+
};
51
51
+
52
52
+
host = mkOption {
53
53
+
type = types.str;
54
54
+
example = "frab.example.com";
55
55
+
description = ''
56
56
+
Hostname under which this frab instance can be reached.
57
57
+
'';
58
58
+
};
59
59
+
60
60
+
protocol = mkOption {
61
61
+
type = types.str;
62
62
+
default = "https";
63
63
+
example = "http";
64
64
+
description = ''
65
65
+
Either http or https, depending on how your Frab instance
66
66
+
will be exposed to the public.
67
67
+
'';
68
68
+
};
69
69
+
70
70
+
fromEmail = mkOption {
71
71
+
type = types.str;
72
72
+
default = "frab@localhost";
73
73
+
description = ''
74
74
+
Email address used by frab.
75
75
+
'';
76
76
+
};
77
77
+
78
78
+
listenAddress = mkOption {
79
79
+
type = types.str;
80
80
+
default = "localhost";
81
81
+
description = ''
82
82
+
Address or hostname frab should listen on.
83
83
+
'';
84
84
+
};
85
85
+
86
86
+
listenPort = mkOption {
87
87
+
type = types.int;
88
88
+
default = 3000;
89
89
+
description = ''
90
90
+
Port frab should listen on.
91
91
+
'';
92
92
+
};
93
93
+
94
94
+
statePath = mkOption {
95
95
+
type = types.str;
96
96
+
default = "/var/lib/frab";
97
97
+
description = ''
98
98
+
Directory where frab keeps its state.
99
99
+
'';
100
100
+
};
101
101
+
102
102
+
user = mkOption {
103
103
+
type = types.str;
104
104
+
default = "frab";
105
105
+
description = ''
106
106
+
User to run frab.
107
107
+
'';
108
108
+
};
109
109
+
110
110
+
group = mkOption {
111
111
+
type = types.str;
112
112
+
default = "frab";
113
113
+
description = ''
114
114
+
Group to run frab.
115
115
+
'';
116
116
+
};
117
117
+
118
118
+
secretKeyBase = mkOption {
119
119
+
type = types.str;
120
120
+
description = ''
121
121
+
Your secret key is used for verifying the integrity of signed cookies.
122
122
+
If you change this key, all old signed cookies will become invalid!
123
123
+
124
124
+
Make sure the secret is at least 30 characters and all random,
125
125
+
no regular words or you'll be exposed to dictionary attacks.
126
126
+
'';
127
127
+
};
128
128
+
129
129
+
database = mkOption {
130
130
+
type = types.attrs;
131
131
+
default = {
132
132
+
adapter = "sqlite3";
133
133
+
database = "/var/lib/frab/db.sqlite3";
134
134
+
pool = 5;
135
135
+
timeout = 5000;
136
136
+
};
137
137
+
example = {
138
138
+
adapter = "postgresql";
139
139
+
database = "frab";
140
140
+
host = "localhost";
141
141
+
username = "frabuser";
142
142
+
password = "supersecret";
143
143
+
encoding = "utf8";
144
144
+
pool = 5;
145
145
+
};
146
146
+
description = ''
147
147
+
Rails database configuration for Frab as Nix attribute set.
148
148
+
'';
149
149
+
};
150
150
+
151
151
+
extraEnvironment = mkOption {
152
152
+
type = types.attrs;
153
153
+
default = {};
154
154
+
example = {
155
155
+
FRAB_CURRENCY_UNIT = "€";
156
156
+
FRAB_CURRENCY_FORMAT = "%n%u";
157
157
+
EXCEPTION_EMAIL = "frab-owner@example.com";
158
158
+
SMTP_ADDRESS = "localhost";
159
159
+
SMTP_PORT = "587";
160
160
+
SMTP_DOMAIN = "localdomain";
161
161
+
SMTP_USER_NAME = "root";
162
162
+
SMTP_PASSWORD = "toor";
163
163
+
SMTP_AUTHENTICATION = "1";
164
164
+
SMTP_NOTLS = "1";
165
165
+
};
166
166
+
description = ''
167
167
+
Additional environment variables to set for frab for further
168
168
+
configuration. See the frab documentation for more information.
169
169
+
'';
170
170
+
};
171
171
+
};
172
172
+
};
173
173
+
174
174
+
config = mkIf cfg.enable {
175
175
+
environment.systemPackages = [ frab-rake ];
176
176
+
177
177
+
users.extraUsers = [
178
178
+
{ name = cfg.user;
179
179
+
group = cfg.group;
180
180
+
home = "${cfg.statePath}";
181
181
+
}
182
182
+
];
183
183
+
184
184
+
users.extraGroups = [ { name = cfg.group; } ];
185
185
+
186
186
+
systemd.services.frab = {
187
187
+
after = [ "network.target" "gitlab.service" ];
188
188
+
wantedBy = [ "multi-user.target" ];
189
189
+
environment = frabEnv;
190
190
+
191
191
+
preStart = ''
192
192
+
mkdir -p ${cfg.statePath}/system/attachments
193
193
+
chown ${cfg.user}:${cfg.group} -R ${cfg.statePath}
194
194
+
195
195
+
mkdir /run/frab -p
196
196
+
ln -sf ${pkgs.writeText "frab-database.yml" databaseConfig} /run/frab/database.yml
197
197
+
ln -sf ${cfg.statePath}/system /run/frab/system
198
198
+
199
199
+
if ! test -e "${cfg.statePath}/db-setup-done"; then
200
200
+
${frab-rake}/bin/frab-rake db:setup
201
201
+
touch ${cfg.statePath}/db-setup-done
202
202
+
else
203
203
+
${frab-rake}/bin/frab-rake db:migrate
204
204
+
fi
205
205
+
'';
206
206
+
207
207
+
serviceConfig = {
208
208
+
PermissionsStartOnly = true;
209
209
+
PrivateTmp = true;
210
210
+
PrivateDevices = true;
211
211
+
Type = "simple";
212
212
+
User = cfg.user;
213
213
+
Group = cfg.group;
214
214
+
TimeoutSec = "300s";
215
215
+
Restart = "on-failure";
216
216
+
RestartSec = "10s";
217
217
+
WorkingDirectory = "${package}/share/frab";
218
218
+
ExecStart = "${frab-rake}/bin/frab-bundle exec rails server " +
219
219
+
"--binding=${cfg.listenAddress} --port=${toString cfg.listenPort}";
220
220
+
};
221
221
+
};
222
222
+
223
223
+
};
224
224
+
}