Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Mob moss work on packaging flarum #23

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
13fd40b
mob start [ci-skip] [ci skip] [skip ci]
albertchae Jul 18, 2023
154c914
mob next [ci-skip] [ci skip] [skip ci]
albertchae Jul 18, 2023
fc5b003
mob next [ci-skip] [ci skip] [skip ci]
jasonodoom Jul 18, 2023
7790c80
mob next [ci-skip] [ci skip] [skip ci]
DMills27 Jul 18, 2023
6a9089f
mob next [ci-skip] [ci skip] [skip ci]
jleightcap Jul 18, 2023
94f8a5e
mob next [ci-skip] [ci skip] [skip ci]
jleightcap Jul 18, 2023
2f38aa2
mob start [ci-skip] [ci skip] [skip ci]
jleightcap Jul 20, 2023
5cca401
mob next [ci-skip] [ci skip] [skip ci]
jleightcap Jul 20, 2023
7649658
mob next [ci-skip] [ci skip] [skip ci]
Chickensoupwithrice Jul 20, 2023
8645907
mob next [ci-skip] [ci skip] [skip ci]
DMills27 Jul 20, 2023
efcd4b2
mob next [ci-skip] [ci skip] [skip ci]
jasonodoom Jul 20, 2023
3faa9a6
mob next [ci-skip] [ci skip] [skip ci]
albertchae Jul 20, 2023
084ed40
mob next [ci-skip] [ci skip] [skip ci]
jleightcap Jul 20, 2023
743fcc3
mob next [ci-skip] [ci skip] [skip ci]
jleightcap Jul 20, 2023
29f6b9c
mob next [ci-skip] [ci skip] [skip ci]
albertchae Jul 20, 2023
b31dc42
undo README changes when learning mob.sh
albertchae Jul 21, 2023
3c5be6f
Squashed commit of the following:
jleightcap Jul 24, 2023
8e9ddc4
Merge branch 'moss-flarum' of github.com:ngi-nix/ngipkgs into moss-fl…
jleightcap Jul 24, 2023
65fa58e
flarum: jack
jleightcap Jul 24, 2023
fb7aac9
Copied structure from pixelfed https://github.com/NixOS/nixpkgs/tree/…
albertchae Jul 24, 2023
24e6d04
flarum: lockfile sync
jleightcap Jul 25, 2023
3e36923
Pull from albertchae fork
albertchae Jul 25, 2023
dc7176e
Use albertchae/flarum fork which has composer.lock committed
albertchae Jul 25, 2023
f4fdd6a
flarum: init module
jleightcap Jul 27, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion all-packages.nix
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{ newScope, ... }:
let
self = rec {
libgnunetchat = callPackage ./pkgs/libgnunetchat { };
flarum = callPackage ./pkgs/flarum { };
gnunet-messenger-cli = callPackage ./pkgs/gnunet-messenger-cli { };
liberaforms = callPackage ./pkgs/liberaforms { };
liberaforms-env = callPackage ./pkgs/liberaforms/env.nix { };
libgnunetchat = callPackage ./pkgs/libgnunetchat { };
};

callPackage = newScope self;
Expand Down
1 change: 1 addition & 0 deletions modules/all-modules.nix
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
liberaforms = import ./liberaforms.nix;
flarum = import ./flarum.nix;
}
193 changes: 193 additions & 0 deletions modules/flarum.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
{ config, lib, pkgs, utils, ... }:

let
inherit (lib) concatStrings literalExample mapAttrs mkDefault mkEnableOption mkIf mkOption types;
inherit (pkgs) writeText;

cfg = config.services.flarum;

flarumInstallConfig =
writeText "config.yml" (builtins.toJSON {
debug = false;
baseUrl = cfg.baseUrl;
databaseConfiguration = cfg.database;
adminUser = {
username = cfg.adminUser;
password = cfg.initialAdminPassword;
};
settings = {
forum_title = cfg.forumTitle;
};
});
in {
options = {
services.flarum = {
enable = mkEnableOption "Flarum discussion platform";

forumTitle = mkOption {
type = types.str;
default = "A Flarum Forum on NixOS";
description = "Title of the forum.";
};

domain = mkOption {
type = types.str;
default = "localhost";
example = "forum.example.com";
description = "Domain to serve on.";
};

baseUrl = mkOption {
type = types.str;
default = "https://${cfg.domain}";
example = "https://forum.example.com";
description = "Change `domain` instead.";
};

adminUser = mkOption {
type = types.str;
default = "flarum";
description = "Username for first web application administrator";
};

initialAdminPassword = mkOption {
type = types.str;
default = "flarum";
description = "Initial password for the adminUser";
};

user = mkOption {
type = types.str;
default = "flarum";
description = "System user to run Flarum";
};

group = mkOption {
type = types.str;
default = "flarum";
description = "System group to run Flarum";
};

stateDir = mkOption {
type = types.path;
default = "/var/lib/flarum";
description = "Home directory for writable storage";
};

database = mkOption rec {
type = with types; attrsOf (oneOf [str bool int]);
description = "MySQL database parameters";
default = {
# the database driver; i.e. MySQL; MariaDB...
driver = "mysql";
# the host of the connection; localhost in most cases unless using an external service
host = "localhost";
# the name of the database in the instance
database = "flarum";
# database username
username = "flarum";
# database password
password = "";
# the prefix for the tables; useful if you are sharing the same database with another service
prefix = "";
# the port of the connection; defaults to 3306 with MySQL
port = 3306;
strict = false;
};
};

createDatabaseLocally = mkOption {
type = types.bool;
default = true;
description = "Create the database and database user locally, and run installation.";
};
};
};

config = mkIf cfg.enable {
users.users.${cfg.user} = {
isSystemUser = true;
home = cfg.stateDir;
createHome = true;
group = cfg.group;
};
users.groups.${cfg.group} = {};

services.phpfpm.pools.flarum = {
user = cfg.user;
settings = {
"listen.owner" = config.services.nginx.user;
"listen.group" = config.services.nginx.group;
"listen.mode" = "0600";
"pm" = mkDefault "dynamic";
"pm.max_children" = mkDefault 10;
"pm.max_requests" = mkDefault 500;
"pm.start_servers" = mkDefault 2;
"pm.min_spare_servers" = mkDefault 1;
"pm.max_spare_servers" = mkDefault 3;
};
};

services.nginx = {
enable = true;
virtualHosts."${cfg.domain}" = {
root = "${cfg.stateDir}/public";
locations."~ \.php$".extraConfig =
''
fastcgi_pass unix:${config.services.phpfpm.pools.flarum.socket};
fastcgi_index site.php;
'';
extraConfig =
''
index index.php;
include ${pkgs.flarum.src}/.nginx.conf;
'';
};
};

services.mysql = mkIf cfg.enable {
enable = true;
ensureDatabases = [ cfg.database.database ];
ensureUsers = [ {
name = cfg.database.username;
ensurePermissions = {
"${cfg.database.database}.*" = "ALL PRIVILEGES";
};
} ];
};

assertions = [ {
assertion = !cfg.createDatabaseLocally || cfg.database.driver == "mysql";
message = "Flarum can only be automatically installed in MySQL/MariaDB.";
} ];

systemd.services.flarum-install = {
description = "Flarum installation";
after = [ "mysql.service" ];
requires = [ "mysql.service" ];
before = [ "nginx.service" "phpfm-flarum.service" ];
wantedBy = [ "phpfpm-flarum.service" ];
serviceConfig = {
Type = "oneshot";
User = cfg.user;
Group = cfg.group;
};
path = [ config.services.phpfpm.phpPackage ];
script = ''
mkdir -p ${cfg.stateDir}/{extensions,public/assets/avatars}
mkdir -p ${cfg.stateDir}/storage/{formatter,sessions,views}
cd ${cfg.stateDir}
cp -f ${pkgs.flarum.src}/{extend.php,site.php,flarum} .
ln -sf ${pkgs.flarum.dependencies}/vendor .
ln -sf ${pkgs.flarum.src}/public/index.php public/
chmod a+x . public
'' + lib.optionalString (cfg.createDatabaseLocally && cfg.database.driver == "mysql") ''
if [ ! -f config.php ]; then
php flarum install --file=${flarumInstallConfig}
fi
php flarum migrate
php flarum cache:clear
'';
};
};
}
Loading