Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Anish Lakhwara committed Sep 14, 2023
1 parent 1e9487f commit 0cc51b0
Showing 1 changed file with 26 additions and 30 deletions.
56 changes: 26 additions & 30 deletions modules/flarum.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,20 @@ let
cfg = config.services.flarum;
opt = options.services.flarum;

flarumInstallConfig = pkgs.writeText "config.php" ''
<?php return array (
'debug' => true, // enables or disables debug mode, used to troubleshoot issues FIXME(jl): disable debug later?
'offline' => false, // enables or disables site maintenance mode. This makes your site inaccessible to all users (including admins).
'database' =>
array (
'driver' => 'mysql', // the database driver, i.e. MySQL, MariaDB...
'host' => 'localhost', // the host of the connection, localhost in most cases unless using an external service
'database' => 'flarum', // the name of the database in the instance
'username' => 'flarum', // database username
'password' => "", // database password
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => "", // the prefix for the tables, useful if you are sharing the same database with another service
'port' => '3306', // the port of the connection, defaults to 3306 with MySQL
'strict' => false,
),
'url' => 'https://localhost', // the URL installation, you will want to change this if you change domains
'paths' =>
array (
'api' => 'api', // /api goes to the API
'admin' => 'admin', // /admin goes to the admin
),
);
'';
flarumInstallConfig = pkgs.writeText "config.json" (builtins.toJSON {
debug = false;
offline = false;

baseUrl = cfg.baseUrl;
databaseConfiguration = cfg.database;
adminUser = {
username = cfg.adminUser;
password = cfg.initialAdminPassword;
email = cfg.adminEmail;
};
settings = { forum_title = cfg.forumTitle; };
});

in {
options = {
services.flarum = with types; {
Expand Down Expand Up @@ -70,6 +59,12 @@ in {
description = "Username for first web application administrator";
};

adminEmail = mkOption {
type = types.str;
default = "admin@example.com";
description = "Email for first web application administrator";
};

initialAdminPassword = mkOption {
type = types.str;
default = "flarum";
Expand Down Expand Up @@ -148,7 +143,7 @@ in {
"pm.max_spare_servers" = mkDefault 3;
};
phpOptions = ''
error_log = 'stderr'
error_log = syslog
log_errors = on
'';
};
Expand Down Expand Up @@ -204,11 +199,12 @@ in {
cp -f ${cfg.package}/build/{extend.php,site.php,flarum} .
ln -sf ${cfg.package}/build/vendor .
ln -sf ${cfg.package}/build/public/index.php public/
chmod a+x . public
''
+ lib.optionalString
chmod a+x . public
'' + lib.optionalString
(cfg.createDatabaseLocally && cfg.database.driver == "mysql") ''
cp ${flarumInstallConfig} ${cfg.stateDir}/config.php
if [ ! -f config.php ]; then
php flarum install --file=${flarumInstallConfig}
fi
php flarum migrate
# php flarum cache:clear
'';
Expand Down

0 comments on commit 0cc51b0

Please sign in to comment.