2016-09-09 12:09:57 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
with lib;
|
|
|
|
let
|
|
|
|
cfg = config.services.selfoss;
|
|
|
|
|
2019-06-29 01:47:43 +00:00
|
|
|
poolName = "selfoss_pool";
|
|
|
|
|
2016-09-09 12:09:57 +00:00
|
|
|
dataDir = "/var/lib/selfoss";
|
|
|
|
|
|
|
|
selfoss-config =
|
|
|
|
let
|
|
|
|
db_type = cfg.database.type;
|
|
|
|
default_port = if (db_type == "mysql") then 3306 else 5342;
|
|
|
|
in
|
|
|
|
pkgs.writeText "selfoss-config.ini" ''
|
|
|
|
[globals]
|
|
|
|
${lib.optionalString (db_type != "sqlite") ''
|
|
|
|
db_type=${db_type}
|
|
|
|
db_host=${cfg.database.host}
|
|
|
|
db_database=${cfg.database.name}
|
|
|
|
db_username=${cfg.database.user}
|
|
|
|
db_password=${cfg.database.password}
|
2018-11-15 19:22:20 +00:00
|
|
|
db_port=${toString (if (cfg.database.port != null) then cfg.database.port
|
|
|
|
else default_port)}
|
2016-09-09 12:09:57 +00:00
|
|
|
''
|
|
|
|
}
|
|
|
|
${cfg.extraConfig}
|
|
|
|
'';
|
|
|
|
in
|
|
|
|
{
|
|
|
|
options = {
|
|
|
|
services.selfoss = {
|
2022-08-28 19:18:44 +00:00
|
|
|
enable = mkEnableOption (lib.mdDoc "selfoss");
|
2016-09-09 12:09:57 +00:00
|
|
|
|
|
|
|
user = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "nginx";
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc ''
|
2016-09-09 12:09:57 +00:00
|
|
|
User account under which both the service and the web-application run.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
pool = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "${poolName}";
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc ''
|
2016-09-09 12:09:57 +00:00
|
|
|
Name of existing phpfpm pool that is used to run web-application.
|
|
|
|
If not specified a pool will be created automatically with
|
|
|
|
default values.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
database = {
|
|
|
|
type = mkOption {
|
|
|
|
type = types.enum ["pgsql" "mysql" "sqlite"];
|
|
|
|
default = "sqlite";
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc ''
|
2016-09-09 12:09:57 +00:00
|
|
|
Database to store feeds. Supported are sqlite, pgsql and mysql.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
host = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "localhost";
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc ''
|
2016-09-09 12:09:57 +00:00
|
|
|
Host of the database (has no effect if type is "sqlite").
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
name = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "tt_rss";
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc ''
|
2016-09-09 12:09:57 +00:00
|
|
|
Name of the existing database (has no effect if type is "sqlite").
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
user = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "tt_rss";
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc ''
|
2016-09-09 12:09:57 +00:00
|
|
|
The database user. The user must exist and has access to
|
|
|
|
the specified database (has no effect if type is "sqlite").
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
password = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc ''
|
2016-09-09 12:09:57 +00:00
|
|
|
The database user's password (has no effect if type is "sqlite").
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
port = mkOption {
|
|
|
|
type = types.nullOr types.int;
|
|
|
|
default = null;
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc ''
|
2016-09-09 12:09:57 +00:00
|
|
|
The database's port. If not set, the default ports will be
|
|
|
|
provided (5432 and 3306 for pgsql and mysql respectively)
|
|
|
|
(has no effect if type is "sqlite").
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
extraConfig = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
default = "";
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc ''
|
2016-09-09 12:09:57 +00:00
|
|
|
Extra configuration added to config.ini
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2019-07-03 16:11:38 +00:00
|
|
|
services.phpfpm.pools = mkIf (cfg.pool == "${poolName}") {
|
2019-09-08 23:38:31 +00:00
|
|
|
${poolName} = {
|
2019-08-08 02:36:49 +00:00
|
|
|
user = "nginx";
|
|
|
|
settings = mapAttrs (name: mkDefault) {
|
|
|
|
"listen.owner" = "nginx";
|
|
|
|
"listen.group" = "nginx";
|
|
|
|
"listen.mode" = "0600";
|
|
|
|
"pm" = "dynamic";
|
|
|
|
"pm.max_children" = 75;
|
|
|
|
"pm.start_servers" = 10;
|
|
|
|
"pm.min_spare_servers" = 5;
|
|
|
|
"pm.max_spare_servers" = 20;
|
|
|
|
"pm.max_requests" = 500;
|
|
|
|
"catch_workers_output" = 1;
|
|
|
|
};
|
2019-07-03 16:11:38 +00:00
|
|
|
};
|
2016-09-09 12:09:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
systemd.services.selfoss-config = {
|
|
|
|
serviceConfig.Type = "oneshot";
|
|
|
|
script = ''
|
|
|
|
mkdir -m 755 -p ${dataDir}
|
|
|
|
cd ${dataDir}
|
|
|
|
|
|
|
|
# Delete all but the "data" folder
|
|
|
|
ls | grep -v data | while read line; do rm -rf $line; done || true
|
|
|
|
|
|
|
|
# Create the files
|
|
|
|
cp -r "${pkgs.selfoss}/"* "${dataDir}"
|
|
|
|
ln -sf "${selfoss-config}" "${dataDir}/config.ini"
|
2019-06-29 01:47:43 +00:00
|
|
|
chown -R "${cfg.user}" "${dataDir}"
|
2016-09-09 12:09:57 +00:00
|
|
|
chmod -R 755 "${dataDir}"
|
|
|
|
'';
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
};
|
|
|
|
|
|
|
|
systemd.services.selfoss-update = {
|
|
|
|
serviceConfig = {
|
|
|
|
ExecStart = "${pkgs.php}/bin/php ${dataDir}/cliupdate.php";
|
|
|
|
User = "${cfg.user}";
|
|
|
|
};
|
|
|
|
startAt = "hourly";
|
|
|
|
after = [ "selfoss-config.service" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
}
|