diff --git a/lib/maintainers.nix b/lib/maintainers.nix index 6b35d99572ea..0a08b2885624 100644 --- a/lib/maintainers.nix +++ b/lib/maintainers.nix @@ -342,6 +342,7 @@ redbaron = "Maxim Ivanov "; redvers = "Redvers Davies "; refnil = "Martin Lavoie "; + regnat = "Théophane Hufschmitt "; relrod = "Ricky Elrod "; renzo = "Renzo Carbonara "; retrry = "Tadas Barzdžius "; diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix index 07da64c63847..2c422085a74f 100644 --- a/nixos/modules/module-list.nix +++ b/nixos/modules/module-list.nix @@ -477,6 +477,7 @@ ./services/web-apps/mattermost.nix ./services/web-apps/pump.io.nix ./services/web-apps/tt-rss.nix + ./services/web-apps/selfoss.nix ./services/web-servers/apache-httpd/default.nix ./services/web-servers/caddy.nix ./services/web-servers/fcgiwrap.nix diff --git a/nixos/modules/services/web-apps/selfoss.nix b/nixos/modules/services/web-apps/selfoss.nix new file mode 100644 index 000000000000..5571f77334cc --- /dev/null +++ b/nixos/modules/services/web-apps/selfoss.nix @@ -0,0 +1,166 @@ +{ config, lib, pkgs, ... }: +with lib; +let + cfg = config.services.selfoss; + + poolName = "selfoss_pool"; + phpfpmSocketName = "/var/run/phpfpm/${poolName}.sock"; + + dataDir = "/var/lib/selfoss"; + + selfoss-config = + let + db_type = cfg.database.type; + default_port = if (db_type == "mysql") then 3306 else 5342; + in + pkgs.writeText "selfoss-config.ini" '' + [globals] + ${lib.optionalString (db_type != "sqlite") '' + db_type=${db_type} + db_host=${cfg.database.host} + db_database=${cfg.database.name} + db_username=${cfg.database.user} + db_password=${cfg.database.password} + db_port=${if (cfg.database.port != null) then cfg.database.port + else default_port} + '' + } + ${cfg.extraConfig} + ''; +in + { + options = { + services.selfoss = { + enable = mkEnableOption "selfoss"; + + user = mkOption { + type = types.str; + default = "nginx"; + example = "nginx"; + description = '' + User account under which both the service and the web-application run. + ''; + }; + + pool = mkOption { + type = types.str; + default = "${poolName}"; + description = '' + Name of existing phpfpm pool that is used to run web-application. + If not specified a pool will be created automatically with + default values. + ''; + }; + + database = { + type = mkOption { + type = types.enum ["pgsql" "mysql" "sqlite"]; + default = "sqlite"; + description = '' + Database to store feeds. Supported are sqlite, pgsql and mysql. + ''; + }; + + host = mkOption { + type = types.str; + default = "localhost"; + description = '' + Host of the database (has no effect if type is "sqlite"). + ''; + }; + + name = mkOption { + type = types.str; + default = "tt_rss"; + description = '' + Name of the existing database (has no effect if type is "sqlite"). + ''; + }; + + user = mkOption { + type = types.str; + default = "tt_rss"; + description = '' + The database user. The user must exist and has access to + the specified database (has no effect if type is "sqlite"). + ''; + }; + + password = mkOption { + type = types.nullOr types.str; + default = null; + description = '' + The database user's password (has no effect if type is "sqlite"). + ''; + }; + + port = mkOption { + type = types.nullOr types.int; + default = null; + description = '' + The database's port. If not set, the default ports will be + provided (5432 and 3306 for pgsql and mysql respectively) + (has no effect if type is "sqlite"). + ''; + }; + }; + extraConfig = mkOption { + type = types.lines; + default = ""; + description = '' + Extra configuration added to config.ini + ''; + }; + }; + }; + + config = mkIf cfg.enable { + + services.phpfpm.poolConfigs = mkIf (cfg.pool == "${poolName}") { + "${poolName}" = '' + listen = "${phpfpmSocketName}"; + listen.owner = nginx + listen.group = nginx + listen.mode = 0600 + user = nginx + pm = dynamic + pm.max_children = 75 + pm.start_servers = 10 + pm.min_spare_servers = 5 + pm.max_spare_servers = 20 + pm.max_requests = 500 + catch_workers_output = 1 + ''; + }; + + systemd.services.selfoss-config = { + serviceConfig.Type = "oneshot"; + script = '' + mkdir -m 755 -p ${dataDir} + cd ${dataDir} + + # Delete all but the "data" folder + ls | grep -v data | while read line; do rm -rf $line; done || true + + # Create the files + cp -r "${pkgs.selfoss}/"* "${dataDir}" + ln -sf "${selfoss-config}" "${dataDir}/config.ini" + chown -R "${cfg.user}" "${dataDir}" + chmod -R 755 "${dataDir}" + ''; + wantedBy = [ "multi-user.target" ]; + }; + + systemd.services.selfoss-update = { + serviceConfig = { + ExecStart = "${pkgs.php}/bin/php ${dataDir}/cliupdate.php"; + User = "${cfg.user}"; + }; + startAt = "hourly"; + after = [ "selfoss-config.service" ]; + wantedBy = [ "multi-user.target" ]; + + }; + + }; +} diff --git a/pkgs/servers/web-apps/selfoss/default.nix b/pkgs/servers/web-apps/selfoss/default.nix new file mode 100644 index 000000000000..9b11e1261372 --- /dev/null +++ b/pkgs/servers/web-apps/selfoss/default.nix @@ -0,0 +1,29 @@ +{ stdenv, fetchFromGitHub }: + +stdenv.mkDerivation rec { + name = "selfoss-${version}"; + version = "2.15"; + + src = fetchFromGitHub { + owner = "SSilence"; + repo = "selfoss"; + rev = version; + sha256 = "0ljpyd354yalpnqwj6xk9b9mq4h6p8jbqznapj7nvfybas8faq15"; + }; + + buildPhases = ["unpackPhase" "installPhase"]; + + installPhase = '' + mkdir $out + cp -ra * $out/ + ''; + + meta = with stdenv.lib; { + description = "Web-based news feed (RSS/Atom) aggregator"; + license = licenses.gpl3; + homepage = http://http://selfoss.aditu.de/; + platforms = platforms.all; + maintainers = [ maintainers.regnat ]; + }; +} + diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 067c74e27a3c..24a55fe6ce80 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -10959,6 +10959,8 @@ in tt-rss = callPackage ../servers/tt-rss { }; + selfoss = callPackage ../servers/web-apps/selfoss { }; + axis2 = callPackage ../servers/http/tomcat/axis2 { }; unifi = callPackage ../servers/unifi { };