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