at master 4.5 kB view raw
1{ 2 config, 3 lib, 4 pkgs, 5 ... 6}: 7with lib; 8let 9 cfg = config.services.selfoss; 10 11 poolName = "selfoss_pool"; 12 13 dataDir = "/var/lib/selfoss"; 14 15 selfoss-config = 16 let 17 db_type = cfg.database.type; 18 default_port = if (db_type == "mysql") then 3306 else 5342; 19 in 20 pkgs.writeText "selfoss-config.ini" '' 21 [globals] 22 ${lib.optionalString (db_type != "sqlite") '' 23 db_type=${db_type} 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)} 29 ''} 30 ${cfg.extraConfig} 31 ''; 32in 33{ 34 options = { 35 services.selfoss = { 36 enable = mkEnableOption "selfoss"; 37 38 user = mkOption { 39 type = types.str; 40 default = "nginx"; 41 description = '' 42 User account under which both the service and the web-application run. 43 ''; 44 }; 45 46 pool = mkOption { 47 type = types.str; 48 default = "${poolName}"; 49 description = '' 50 Name of existing phpfpm pool that is used to run web-application. 51 If not specified a pool will be created automatically with 52 default values. 53 ''; 54 }; 55 56 database = { 57 type = mkOption { 58 type = types.enum [ 59 "pgsql" 60 "mysql" 61 "sqlite" 62 ]; 63 default = "sqlite"; 64 description = '' 65 Database to store feeds. Supported are sqlite, pgsql and mysql. 66 ''; 67 }; 68 69 host = mkOption { 70 type = types.str; 71 default = "localhost"; 72 description = '' 73 Host of the database (has no effect if type is "sqlite"). 74 ''; 75 }; 76 77 name = mkOption { 78 type = types.str; 79 default = "tt_rss"; 80 description = '' 81 Name of the existing database (has no effect if type is "sqlite"). 82 ''; 83 }; 84 85 user = mkOption { 86 type = types.str; 87 default = "tt_rss"; 88 description = '' 89 The database user. The user must exist and has access to 90 the specified database (has no effect if type is "sqlite"). 91 ''; 92 }; 93 94 password = mkOption { 95 type = types.nullOr types.str; 96 default = null; 97 description = '' 98 The database user's password (has no effect if type is "sqlite"). 99 ''; 100 }; 101 102 port = mkOption { 103 type = types.nullOr types.port; 104 default = null; 105 description = '' 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"). 109 ''; 110 }; 111 }; 112 extraConfig = mkOption { 113 type = types.lines; 114 default = ""; 115 description = '' 116 Extra configuration added to config.ini 117 ''; 118 }; 119 }; 120 }; 121 122 config = mkIf cfg.enable { 123 services.phpfpm.pools = mkIf (cfg.pool == "${poolName}") { 124 ${poolName} = { 125 user = "nginx"; 126 settings = mapAttrs (name: mkDefault) { 127 "listen.owner" = "nginx"; 128 "listen.group" = "nginx"; 129 "listen.mode" = "0600"; 130 "pm" = "dynamic"; 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; 137 }; 138 }; 139 }; 140 141 systemd.services.selfoss-config = { 142 serviceConfig.Type = "oneshot"; 143 script = '' 144 mkdir -m 755 -p ${dataDir} 145 cd ${dataDir} 146 147 # Delete all but the "data" folder 148 ls | grep -v data | while read line; do rm -rf $line; done || true 149 150 # Create the files 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}" 155 ''; 156 wantedBy = [ "multi-user.target" ]; 157 }; 158 159 systemd.services.selfoss-update = { 160 serviceConfig = { 161 ExecStart = "${pkgs.php83}/bin/php ${dataDir}/cliupdate.php"; 162 User = "${cfg.user}"; 163 }; 164 startAt = "hourly"; 165 after = [ "selfoss-config.service" ]; 166 wantedBy = [ "multi-user.target" ]; 167 168 }; 169 170 }; 171}