9 cfg = config.services.selfoss;
11 poolName = "selfoss_pool";
13 dataDir = "/var/lib/selfoss";
17 db_type = cfg.database.type;
18 default_port = if (db_type == "mysql") then 3306 else 5342;
20 pkgs.writeText "selfoss-config.ini" ''
22 ${lib.optionalString (db_type != "sqlite") ''
24 db_host=${cfg.database.host}
25 db_database=${cfg.database.name}
26 db_username=${cfg.database.user}
27 db_password=${cfg.database.password}
28 db_port=${toString (if (cfg.database.port != null) then cfg.database.port else default_port)}
36 enable = mkEnableOption "selfoss";
42 User account under which both the service and the web-application run.
48 default = "${poolName}";
50 Name of existing phpfpm pool that is used to run web-application.
51 If not specified a pool will be created automatically with
65 Database to store feeds. Supported are sqlite, pgsql and mysql.
71 default = "localhost";
73 Host of the database (has no effect if type is "sqlite").
81 Name of the existing database (has no effect if type is "sqlite").
89 The database user. The user must exist and has access to
90 the specified database (has no effect if type is "sqlite").
95 type = types.nullOr types.str;
98 The database user's password (has no effect if type is "sqlite").
103 type = types.nullOr types.int;
106 The database's port. If not set, the default ports will be
107 provided (5432 and 3306 for pgsql and mysql respectively)
108 (has no effect if type is "sqlite").
112 extraConfig = mkOption {
116 Extra configuration added to config.ini
122 config = mkIf cfg.enable {
123 services.phpfpm.pools = mkIf (cfg.pool == "${poolName}") {
126 settings = mapAttrs (name: mkDefault) {
127 "listen.owner" = "nginx";
128 "listen.group" = "nginx";
129 "listen.mode" = "0600";
131 "pm.max_children" = 75;
132 "pm.start_servers" = 10;
133 "pm.min_spare_servers" = 5;
134 "pm.max_spare_servers" = 20;
135 "pm.max_requests" = 500;
136 "catch_workers_output" = 1;
141 systemd.services.selfoss-config = {
142 serviceConfig.Type = "oneshot";
144 mkdir -m 755 -p ${dataDir}
147 # Delete all but the "data" folder
148 ls | grep -v data | while read line; do rm -rf $line; done || true
151 cp -r "${pkgs.selfoss}/"* "${dataDir}"
152 ln -sf "${selfoss-config}" "${dataDir}/config.ini"
153 chown -R "${cfg.user}" "${dataDir}"
154 chmod -R 755 "${dataDir}"
156 wantedBy = [ "multi-user.target" ];
159 systemd.services.selfoss-update = {
161 ExecStart = "${pkgs.php}/bin/php ${dataDir}/cliupdate.php";
162 User = "${cfg.user}";
165 after = [ "selfoss-config.service" ];
166 wantedBy = [ "multi-user.target" ];