···
1
+
{ config, lib, pkgs, ... }:
6
+
cfg = config.services.frab;
11
+
databaseConfig = builtins.toJSON { production = cfg.database; };
14
+
RAILS_ENV = "production";
15
+
RACK_ENV = "production";
16
+
SECRET_KEY_BASE = cfg.secretKeyBase;
17
+
FRAB_HOST = cfg.host;
18
+
FRAB_PROTOCOL = cfg.protocol;
19
+
FROM_EMAIL = cfg.fromEmail;
20
+
RAILS_SERVE_STATIC_FILES = "1";
21
+
} // cfg.extraEnvironment;
23
+
frab-rake = pkgs.stdenv.mkDerivation rec {
25
+
buildInputs = [ package.env pkgs.makeWrapper ];
26
+
phases = "installPhase fixupPhase";
29
+
makeWrapper ${package.env}/bin/bundle $out/bin/frab-bundle \
30
+
${concatStrings (mapAttrsToList (name: value: "--set ${name} '${value}' ") frabEnv)} \
31
+
--set PATH '${lib.makeBinPath (with pkgs; [ nodejs file imagemagick ])}:$PATH' \
32
+
--set RAKEOPT '-f ${package}/share/frab/Rakefile' \
33
+
--run 'cd ${package}/share/frab'
34
+
makeWrapper $out/bin/frab-bundle $out/bin/frab-rake \
35
+
--add-flags "exec rake"
48
+
Enable the frab service.
54
+
example = "frab.example.com";
56
+
Hostname under which this frab instance can be reached.
60
+
protocol = mkOption {
65
+
Either http or https, depending on how your Frab instance
66
+
will be exposed to the public.
70
+
fromEmail = mkOption {
72
+
default = "frab@localhost";
74
+
Email address used by frab.
78
+
listenAddress = mkOption {
80
+
default = "localhost";
82
+
Address or hostname frab should listen on.
86
+
listenPort = mkOption {
90
+
Port frab should listen on.
94
+
statePath = mkOption {
96
+
default = "/var/lib/frab";
98
+
Directory where frab keeps its state.
118
+
secretKeyBase = mkOption {
121
+
Your secret key is used for verifying the integrity of signed cookies.
122
+
If you change this key, all old signed cookies will become invalid!
124
+
Make sure the secret is at least 30 characters and all random,
125
+
no regular words or you'll be exposed to dictionary attacks.
129
+
database = mkOption {
130
+
type = types.attrs;
132
+
adapter = "sqlite3";
133
+
database = "/var/lib/frab/db.sqlite3";
138
+
adapter = "postgresql";
140
+
host = "localhost";
141
+
username = "frabuser";
142
+
password = "supersecret";
147
+
Rails database configuration for Frab as Nix attribute set.
151
+
extraEnvironment = mkOption {
152
+
type = types.attrs;
155
+
FRAB_CURRENCY_UNIT = "€";
156
+
FRAB_CURRENCY_FORMAT = "%n%u";
157
+
EXCEPTION_EMAIL = "frab-owner@example.com";
158
+
SMTP_ADDRESS = "localhost";
160
+
SMTP_DOMAIN = "localdomain";
161
+
SMTP_USER_NAME = "root";
162
+
SMTP_PASSWORD = "toor";
163
+
SMTP_AUTHENTICATION = "1";
167
+
Additional environment variables to set for frab for further
168
+
configuration. See the frab documentation for more information.
174
+
config = mkIf cfg.enable {
175
+
environment.systemPackages = [ frab-rake ];
177
+
users.extraUsers = [
180
+
home = "${cfg.statePath}";
184
+
users.extraGroups = [ { name = cfg.group; } ];
186
+
systemd.services.frab = {
187
+
after = [ "network.target" "gitlab.service" ];
188
+
wantedBy = [ "multi-user.target" ];
189
+
environment = frabEnv;
192
+
mkdir -p ${cfg.statePath}/system/attachments
193
+
chown ${cfg.user}:${cfg.group} -R ${cfg.statePath}
196
+
ln -sf ${pkgs.writeText "frab-database.yml" databaseConfig} /run/frab/database.yml
197
+
ln -sf ${cfg.statePath}/system /run/frab/system
199
+
if ! test -e "${cfg.statePath}/db-setup-done"; then
200
+
${frab-rake}/bin/frab-rake db:setup
201
+
touch ${cfg.statePath}/db-setup-done
203
+
${frab-rake}/bin/frab-rake db:migrate
208
+
PermissionsStartOnly = true;
210
+
PrivateDevices = true;
214
+
TimeoutSec = "300s";
215
+
Restart = "on-failure";
216
+
RestartSec = "10s";
217
+
WorkingDirectory = "${package}/share/frab";
218
+
ExecStart = "${frab-rake}/bin/frab-bundle exec rails server " +
219
+
"--binding=${cfg.listenAddress} --port=${toString cfg.listenPort}";