lol

Merge pull request #18047 from Nadrieril/ttrss

tt-rss service: Use nginx virtualhosts; improve config options

authored by

Joachim F and committed by
GitHub
fbcb9385 c571a7f2

+69 -77
+69 -77
nixos/modules/services/web-apps/tt-rss.nix
··· 18 19 poolName = "tt-rss"; 20 phpfpmSocketName = "/var/run/phpfpm/${poolName}.sock"; 21 - virtualHostName = "tt-rss"; 22 23 tt-rss-config = pkgs.writeText "config.php" '' 24 <?php ··· 34 define('MYSQL_CHARSET', 'UTF8'); 35 36 define('DB_TYPE', '${cfg.database.type}'); 37 - define('DB_HOST', '${cfg.database.host}'); 38 define('DB_USER', '${cfg.database.user}'); 39 define('DB_NAME', '${cfg.database.name}'); 40 - define('DB_PASS', '${escape ["'" "\\"] cfg.database.password}'); 41 define('DB_PORT', '${toString dbPort}'); 42 43 define('AUTH_AUTO_CREATE', ${boolToString cfg.auth.autoCreate}); ··· 91 92 enable = mkEnableOption "tt-rss"; 93 94 user = mkOption { 95 type = types.str; 96 default = "nginx"; 97 example = "nginx"; 98 description = '' 99 - User account under which both the service and the web-application run. 100 ''; 101 }; 102 ··· 110 ''; 111 }; 112 113 - # TODO: Re-enable after https://github.com/NixOS/nixpkgs/pull/15862 is merged 114 - 115 - # virtualHost = mkOption { 116 - # type = types.str; 117 - # default = "${virtualHostName}"; 118 - # description = '' 119 - # Name of existing nginx virtual host that is used to run web-application. 120 - # If not specified a host will be created automatically with 121 - # default values. 122 - # ''; 123 - # }; 124 125 database = { 126 type = mkOption { ··· 132 }; 133 134 host = mkOption { 135 - type = types.str; 136 - default = "localhost"; 137 description = '' 138 - Host of the database. 139 ''; 140 }; 141 ··· 362 363 singleUserMode = mkOption { 364 type = types.bool; 365 - default = true; 366 367 description = '' 368 Operate in single user mode, disables all functionality related to ··· 445 446 ###### implementation 447 448 - config = let 449 - root = "/var/lib/tt-rss"; 450 - in mkIf cfg.enable { 451 452 - services.phpfpm.poolConfigs = if cfg.pool == "${poolName}" then { 453 "${poolName}" = '' 454 listen = "${phpfpmSocketName}"; 455 listen.owner = nginx 456 listen.group = nginx 457 listen.mode = 0600 458 - user = nginx 459 pm = dynamic 460 pm.max_children = 75 461 pm.start_servers = 10 ··· 464 pm.max_requests = 500 465 catch_workers_output = 1 466 ''; 467 - } else {}; 468 469 - # TODO: Re-enable after https://github.com/NixOS/nixpkgs/pull/15862 is merged 470 471 - # services.nginx.virtualHosts = if cfg.virtualHost == "${virtualHostName}" then { 472 - # "${virtualHostName}" = { 473 - # root = "${root}"; 474 - # extraConfig = '' 475 - # access_log /var/log/nginx-${virtualHostName}-access.log; 476 - # error_log /var/log/nginx-${virtualHostName}-error.log; 477 - # ''; 478 - 479 - # locations."/" = { 480 - # extraConfig = '' 481 - # index index.php; 482 - # ''; 483 - # }; 484 - 485 - # locations."~ \.php$" = { 486 - # extraConfig = '' 487 - # fastcgi_split_path_info ^(.+\.php)(/.+)$; 488 - # fastcgi_pass unix:${phpfpmSocketName}; 489 - # fastcgi_index index.php; 490 - # fastcgi_param SCRIPT_FILENAME ${root}/$fastcgi_script_name; 491 492 - # include ${pkgs.nginx}/conf/fastcgi_params; 493 - # ''; 494 - # }; 495 - # }; 496 - # } else {}; 497 498 499 systemd.services.tt-rss = let ··· 503 description = "Tiny Tiny RSS feeds update daemon"; 504 505 preStart = let 506 - callSql = if cfg.database.type == "pgsql" then (e: '' 507 - ${optionalString (cfg.database.password != null) 508 - "PGPASSWORD=${cfg.database.password}"} ${pkgs.postgresql95}/bin/psql \ 509 - -U ${cfg.database.user} \ 510 - -h ${cfg.database.host} \ 511 - --port ${toString dbPort} \ 512 - -c '${e}' \ 513 - ${cfg.database.name}'') 514 515 - else if cfg.database.type == "mysql" then (e: '' 516 - echo '${e}' | ${pkgs.mysql}/bin/mysql \ 517 - ${optionalString (cfg.database.password != null) 518 - "-p${cfg.database.password}"} \ 519 - -u ${cfg.database.user} \ 520 - -h ${cfg.database.host} \ 521 - -P ${toString dbPort} \ 522 - ${cfg.database.name}'') 523 524 - else ""; 525 526 in '' 527 - rm -rf "${root}/*" 528 - mkdir -m 755 -p "${root}" 529 - cp -r "${pkgs.tt-rss}/"* "${root}" 530 - ln -sf "${tt-rss-config}" "${root}/config.php" 531 - chown -R "${cfg.user}" "${root}" 532 - chmod -R 755 "${root}" 533 - '' + (optionalString (cfg.database.type == "pgsql") '' 534 535 exists=$(${callSql "select count(*) > 0 from pg_tables where tableowner = user"} \ 536 | tail -n+3 | head -n-2 | sed -e 's/[ \n\t]*//') 537 ··· 540 else 541 echo 'The database contains some data. Leaving it as it is.' 542 fi; 543 - '') + (optionalString (cfg.database.type == "mysql") '' 544 545 exists=$(${callSql "select count(*) > 0 from information_schema.tables where table_schema = schema()"} \ 546 | tail -n+2 | sed -e 's/[ \n\t]*//') 547 ··· 554 555 serviceConfig = { 556 User = "${cfg.user}"; 557 - ExecStart = "${pkgs.php}/bin/php /var/lib/tt-rss/update.php --daemon"; 558 StandardOutput = "syslog"; 559 StandardError = "syslog"; 560 PermissionsStartOnly = true;
··· 18 19 poolName = "tt-rss"; 20 phpfpmSocketName = "/var/run/phpfpm/${poolName}.sock"; 21 22 tt-rss-config = pkgs.writeText "config.php" '' 23 <?php ··· 33 define('MYSQL_CHARSET', 'UTF8'); 34 35 define('DB_TYPE', '${cfg.database.type}'); 36 + define('DB_HOST', '${optionalString (cfg.database.host != null) cfg.database.host}'); 37 define('DB_USER', '${cfg.database.user}'); 38 define('DB_NAME', '${cfg.database.name}'); 39 + define('DB_PASS', '${optionalString (cfg.database.password != null) (escape ["'" "\\"] cfg.database.password)}'); 40 define('DB_PORT', '${toString dbPort}'); 41 42 define('AUTH_AUTO_CREATE', ${boolToString cfg.auth.autoCreate}); ··· 90 91 enable = mkEnableOption "tt-rss"; 92 93 + root = mkOption { 94 + type = types.path; 95 + default = "/var/lib/tt-rss"; 96 + example = "/var/lib/tt-rss"; 97 + description = '' 98 + Root of the application. 99 + ''; 100 + }; 101 + 102 user = mkOption { 103 type = types.str; 104 default = "nginx"; 105 example = "nginx"; 106 description = '' 107 + User account under which both the update daemon and the web-application run. 108 ''; 109 }; 110 ··· 118 ''; 119 }; 120 121 + virtualHost = mkOption { 122 + type = types.nullOr types.str; 123 + default = "tt-rss"; 124 + description = '' 125 + Name of the nginx virtualhost to use and setup. If null, do not setup any virtualhost. 126 + ''; 127 + }; 128 129 database = { 130 type = mkOption { ··· 136 }; 137 138 host = mkOption { 139 + type = types.nullOr types.str; 140 + default = null; 141 description = '' 142 + Host of the database. Leave null to use Unix domain socket. 143 ''; 144 }; 145 ··· 366 367 singleUserMode = mkOption { 368 type = types.bool; 369 + default = false; 370 371 description = '' 372 Operate in single user mode, disables all functionality related to ··· 449 450 ###### implementation 451 452 + config = mkIf cfg.enable { 453 454 + services.phpfpm.poolConfigs = mkIf (cfg.pool == "${poolName}") { 455 "${poolName}" = '' 456 listen = "${phpfpmSocketName}"; 457 listen.owner = nginx 458 listen.group = nginx 459 listen.mode = 0600 460 + user = ${cfg.user} 461 pm = dynamic 462 pm.max_children = 75 463 pm.start_servers = 10 ··· 466 pm.max_requests = 500 467 catch_workers_output = 1 468 ''; 469 + }; 470 471 + services.nginx.virtualHosts = mkIf (cfg.virtualHost != null) { 472 + "${cfg.virtualHost}" = { 473 + root = "${cfg.root}"; 474 475 + locations."/" = { 476 + index = "index.php"; 477 + }; 478 479 + locations."~ \.php$" = { 480 + extraConfig = '' 481 + fastcgi_split_path_info ^(.+\.php)(/.+)$; 482 + fastcgi_pass unix:${phpfpmSocketName}; 483 + fastcgi_index index.php; 484 + fastcgi_param SCRIPT_FILENAME ${cfg.root}/$fastcgi_script_name; 485 + ''; 486 + }; 487 + }; 488 + }; 489 490 491 systemd.services.tt-rss = let ··· 495 description = "Tiny Tiny RSS feeds update daemon"; 496 497 preStart = let 498 + callSql = e: 499 + if cfg.database.type == "pgsql" then '' 500 + ${optionalString (cfg.database.password != null) "PGPASSWORD=${cfg.database.password}"} \ 501 + ${pkgs.postgresql95}/bin/psql \ 502 + -U ${cfg.database.user} \ 503 + ${optionalString (cfg.database.host != null) "-h ${cfg.database.host} --port ${toString dbPort}"} \ 504 + -c '${e}' \ 505 + ${cfg.database.name}'' 506 507 + else if cfg.database.type == "mysql" then '' 508 + echo '${e}' | ${pkgs.mysql}/bin/mysql \ 509 + -u ${cfg.database.user} \ 510 + ${optionalString (cfg.database.password != null) "-p${cfg.database.password}"} \ 511 + ${optionalString (cfg.database.host != null) "-h ${cfg.database.host} -P ${toString dbPort}"} \ 512 + ${cfg.database.name}'' 513 514 + else ""; 515 516 in '' 517 + rm -rf "${cfg.root}/*" 518 + mkdir -m 755 -p "${cfg.root}" 519 + cp -r "${pkgs.tt-rss}/"* "${cfg.root}" 520 + ln -sf "${tt-rss-config}" "${cfg.root}/config.php" 521 + chown -R "${cfg.user}" "${cfg.root}" 522 + chmod -R 755 "${cfg.root}" 523 + '' 524 525 + + (optionalString (cfg.database.type == "pgsql") '' 526 exists=$(${callSql "select count(*) > 0 from pg_tables where tableowner = user"} \ 527 | tail -n+3 | head -n-2 | sed -e 's/[ \n\t]*//') 528 ··· 531 else 532 echo 'The database contains some data. Leaving it as it is.' 533 fi; 534 + '') 535 536 + + (optionalString (cfg.database.type == "mysql") '' 537 exists=$(${callSql "select count(*) > 0 from information_schema.tables where table_schema = schema()"} \ 538 | tail -n+2 | sed -e 's/[ \n\t]*//') 539 ··· 546 547 serviceConfig = { 548 User = "${cfg.user}"; 549 + ExecStart = "${pkgs.php}/bin/php ${cfg.root}/update.php --daemon"; 550 StandardOutput = "syslog"; 551 StandardError = "syslog"; 552 PermissionsStartOnly = true;