1 { config, lib, pkgs, ... }:
4 cfg = config.services.selfoss;
6 poolName = "selfoss_pool";
8 dataDir = "/var/lib/selfoss";
12 db_type = cfg.database.type;
13 default_port = if (db_type == "mysql") then 3306 else 5342;
15 pkgs.writeText "selfoss-config.ini" ''
17 ${lib.optionalString (db_type != "sqlite") ''
19 db_host=${cfg.database.host}
20 db_database=${cfg.database.name}
21 db_username=${cfg.database.user}
22 db_password=${cfg.database.password}
23 db_port=${toString (if (cfg.database.port != null) then cfg.database.port
33 enable = mkEnableOption "selfoss";
39 User account under which both the service and the web-application run.
45 default = "${poolName}";
47 Name of existing phpfpm pool that is used to run web-application.
48 If not specified a pool will be created automatically with
55 type = types.enum ["pgsql" "mysql" "sqlite"];
58 Database to store feeds. Supported are sqlite, pgsql and mysql.
64 default = "localhost";
66 Host of the database (has no effect if type is "sqlite").
74 Name of the existing database (has no effect if type is "sqlite").
82 The database user. The user must exist and has access to
83 the specified database (has no effect if type is "sqlite").
88 type = types.nullOr types.str;
91 The database user's password (has no effect if type is "sqlite").
96 type = types.nullOr types.int;
99 The database's port. If not set, the default ports will be
100 provided (5432 and 3306 for pgsql and mysql respectively)
101 (has no effect if type is "sqlite").
105 extraConfig = mkOption {
109 Extra configuration added to config.ini
115 config = mkIf cfg.enable {
116 services.phpfpm.pools = mkIf (cfg.pool == "${poolName}") {
119 settings = mapAttrs (name: mkDefault) {
120 "listen.owner" = "nginx";
121 "listen.group" = "nginx";
122 "listen.mode" = "0600";
124 "pm.max_children" = 75;
125 "pm.start_servers" = 10;
126 "pm.min_spare_servers" = 5;
127 "pm.max_spare_servers" = 20;
128 "pm.max_requests" = 500;
129 "catch_workers_output" = 1;
134 systemd.services.selfoss-config = {
135 serviceConfig.Type = "oneshot";
137 mkdir -m 755 -p ${dataDir}
140 # Delete all but the "data" folder
141 ls | grep -v data | while read line; do rm -rf $line; done || true
144 cp -r "${pkgs.selfoss}/"* "${dataDir}"
145 ln -sf "${selfoss-config}" "${dataDir}/config.ini"
146 chown -R "${cfg.user}" "${dataDir}"
147 chmod -R 755 "${dataDir}"
149 wantedBy = [ "multi-user.target" ];
152 systemd.services.selfoss-update = {
154 ExecStart = "${pkgs.php}/bin/php ${dataDir}/cliupdate.php";
155 User = "${cfg.user}";
158 after = [ "selfoss-config.service" ];
159 wantedBy = [ "multi-user.target" ];