2020-04-24 23:36:52 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
let
|
|
|
|
cfg = config.services.miniflux;
|
|
|
|
|
2022-02-10 20:34:41 +00:00
|
|
|
defaultAddress = "localhost:8080";
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
dbUser = "miniflux";
|
|
|
|
dbPassword = "miniflux";
|
|
|
|
dbHost = "localhost";
|
|
|
|
dbName = "miniflux";
|
|
|
|
|
|
|
|
defaultCredentials = pkgs.writeText "miniflux-admin-credentials" ''
|
|
|
|
ADMIN_USERNAME=admin
|
|
|
|
ADMIN_PASSWORD=password
|
|
|
|
'';
|
|
|
|
|
|
|
|
pgbin = "${config.services.postgresql.package}/bin";
|
|
|
|
preStart = pkgs.writeScript "miniflux-pre-start" ''
|
|
|
|
#!${pkgs.runtimeShell}
|
|
|
|
db_exists() {
|
2021-03-15 08:37:03 +00:00
|
|
|
[ "$(${pgbin}/psql -Atc "select 1 from pg_database where datname='$1'")" == "1" ]
|
2020-04-24 23:36:52 +00:00
|
|
|
}
|
|
|
|
if ! db_exists "${dbName}"; then
|
2021-03-15 08:37:03 +00:00
|
|
|
${pgbin}/psql postgres -c "CREATE ROLE ${dbUser} WITH LOGIN NOCREATEDB NOCREATEROLE ENCRYPTED PASSWORD '${dbPassword}'"
|
|
|
|
${pgbin}/createdb --owner "${dbUser}" "${dbName}"
|
|
|
|
${pgbin}/psql "${dbName}" -c "CREATE EXTENSION IF NOT EXISTS hstore"
|
2020-04-24 23:36:52 +00:00
|
|
|
fi
|
|
|
|
'';
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
options = {
|
|
|
|
services.miniflux = {
|
2022-02-10 20:34:41 +00:00
|
|
|
enable = mkEnableOption "miniflux and creates a local postgres database for it";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
config = mkOption {
|
|
|
|
type = types.attrsOf types.str;
|
2021-10-06 13:57:05 +00:00
|
|
|
example = literalExpression ''
|
2020-04-24 23:36:52 +00:00
|
|
|
{
|
|
|
|
CLEANUP_FREQUENCY = "48";
|
|
|
|
LISTEN_ADDR = "localhost:8080";
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
description = ''
|
|
|
|
Configuration for Miniflux, refer to
|
2021-02-22 21:28:39 +00:00
|
|
|
<link xlink:href="https://miniflux.app/docs/configuration.html"/>
|
2020-04-24 23:36:52 +00:00
|
|
|
for documentation on the supported values.
|
2022-02-10 20:34:41 +00:00
|
|
|
|
|
|
|
Correct configuration for the database is already provided.
|
|
|
|
By default, listens on ${defaultAddress}.
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
adminCredentialsFile = mkOption {
|
|
|
|
type = types.nullOr types.path;
|
|
|
|
default = null;
|
|
|
|
description = ''
|
|
|
|
File containing the ADMIN_USERNAME, default is "admin", and
|
|
|
|
ADMIN_PASSWORD (length >= 6), default is "password"; in the format of
|
|
|
|
an EnvironmentFile=, as described by systemd.exec(5).
|
|
|
|
'';
|
|
|
|
example = "/etc/nixos/miniflux-admin-credentials";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
|
|
|
services.miniflux.config = {
|
2022-02-10 20:34:41 +00:00
|
|
|
LISTEN_ADDR = mkDefault defaultAddress;
|
2020-04-24 23:36:52 +00:00
|
|
|
DATABASE_URL = "postgresql://${dbUser}:${dbPassword}@${dbHost}/${dbName}?sslmode=disable";
|
|
|
|
RUN_MIGRATIONS = "1";
|
|
|
|
CREATE_ADMIN = "1";
|
|
|
|
};
|
|
|
|
|
|
|
|
services.postgresql.enable = true;
|
|
|
|
|
2021-03-15 08:37:03 +00:00
|
|
|
systemd.services.miniflux-dbsetup = {
|
|
|
|
description = "Miniflux database setup";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
requires = [ "postgresql.service" ];
|
|
|
|
after = [ "network.target" "postgresql.service" ];
|
|
|
|
serviceConfig = {
|
|
|
|
Type = "oneshot";
|
|
|
|
User = config.services.postgresql.superUser;
|
|
|
|
ExecStart = preStart;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
systemd.services.miniflux = {
|
|
|
|
description = "Miniflux service";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
requires = [ "postgresql.service" ];
|
2021-03-15 08:37:03 +00:00
|
|
|
after = [ "network.target" "postgresql.service" "miniflux-dbsetup.service" ];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
ExecStart = "${pkgs.miniflux}/bin/miniflux";
|
|
|
|
DynamicUser = true;
|
|
|
|
RuntimeDirectory = "miniflux";
|
|
|
|
RuntimeDirectoryMode = "0700";
|
|
|
|
EnvironmentFile = if cfg.adminCredentialsFile == null
|
|
|
|
then defaultCredentials
|
|
|
|
else cfg.adminCredentialsFile;
|
2021-08-08 23:34:03 +00:00
|
|
|
# Hardening
|
|
|
|
CapabilityBoundingSet = [ "" ];
|
|
|
|
DeviceAllow = [ "" ];
|
|
|
|
LockPersonality = true;
|
|
|
|
MemoryDenyWriteExecute = true;
|
|
|
|
PrivateDevices = true;
|
|
|
|
PrivateUsers = true;
|
|
|
|
ProcSubset = "pid";
|
|
|
|
ProtectClock = true;
|
|
|
|
ProtectControlGroups = true;
|
|
|
|
ProtectHome = true;
|
|
|
|
ProtectHostname = true;
|
|
|
|
ProtectKernelLogs = true;
|
|
|
|
ProtectKernelModules = true;
|
|
|
|
ProtectKernelTunables = true;
|
|
|
|
ProtectProc = "invisible";
|
|
|
|
RestrictAddressFamilies = [ "AF_INET" "AF_INET6" ];
|
|
|
|
RestrictNamespaces = true;
|
|
|
|
RestrictRealtime = true;
|
|
|
|
RestrictSUIDSGID = true;
|
|
|
|
SystemCallArchitectures = "native";
|
|
|
|
SystemCallFilter = [ "@system-service" "~@privileged" "~@resources" ];
|
|
|
|
UMask = "0077";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
environment = cfg.config;
|
|
|
|
};
|
|
|
|
environment.systemPackages = [ pkgs.miniflux ];
|
|
|
|
};
|
|
|
|
}
|