2018-12-21 18:36:58 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
let
|
|
|
|
cfg = config.services.miniflux;
|
|
|
|
|
2022-01-02 12:00:00 +00:00
|
|
|
defaultAddress = "localhost:8080";
|
|
|
|
|
2018-12-21 18:36:58 +00:00
|
|
|
dbUser = "miniflux";
|
|
|
|
dbName = "miniflux";
|
|
|
|
|
|
|
|
pgbin = "${config.services.postgresql.package}/bin";
|
|
|
|
preStart = pkgs.writeScript "miniflux-pre-start" ''
|
|
|
|
#!${pkgs.runtimeShell}
|
2022-01-02 12:00:00 +00:00
|
|
|
${pgbin}/psql "${dbName}" -c "CREATE EXTENSION IF NOT EXISTS hstore"
|
2018-12-21 18:36:58 +00:00
|
|
|
'';
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
options = {
|
|
|
|
services.miniflux = {
|
2022-01-02 12:00:00 +00:00
|
|
|
enable = mkEnableOption "miniflux and creates a local postgres database for it";
|
2018-12-21 18:36:58 +00:00
|
|
|
|
|
|
|
config = mkOption {
|
|
|
|
type = types.attrsOf types.str;
|
2021-10-03 16:06:03 +00:00
|
|
|
example = literalExpression ''
|
2018-12-21 18:36:58 +00:00
|
|
|
{
|
|
|
|
CLEANUP_FREQUENCY = "48";
|
|
|
|
LISTEN_ADDR = "localhost:8080";
|
|
|
|
}
|
|
|
|
'';
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc ''
|
2018-12-21 18:36:58 +00:00
|
|
|
Configuration for Miniflux, refer to
|
2022-07-28 21:19:15 +00:00
|
|
|
<https://miniflux.app/docs/configuration.html>
|
2018-12-21 18:36:58 +00:00
|
|
|
for documentation on the supported values.
|
2022-01-02 12:00:00 +00:00
|
|
|
|
|
|
|
Correct configuration for the database is already provided.
|
|
|
|
By default, listens on ${defaultAddress}.
|
2018-12-21 18:36:58 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
adminCredentialsFile = mkOption {
|
2022-01-02 12:00:00 +00:00
|
|
|
type = types.path;
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc ''
|
2022-01-02 12:00:00 +00:00
|
|
|
File containing the ADMIN_USERNAME and
|
|
|
|
ADMIN_PASSWORD (length >= 6) in the format of
|
2018-12-21 18:36:58 +00:00
|
|
|
an EnvironmentFile=, as described by systemd.exec(5).
|
|
|
|
'';
|
|
|
|
example = "/etc/nixos/miniflux-admin-credentials";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
|
|
|
services.miniflux.config = {
|
2022-01-02 12:00:00 +00:00
|
|
|
LISTEN_ADDR = mkDefault defaultAddress;
|
2022-01-02 12:00:00 +00:00
|
|
|
DATABASE_URL = "user=${dbUser} host=/run/postgresql dbname=${dbName}";
|
2018-12-21 18:36:58 +00:00
|
|
|
RUN_MIGRATIONS = "1";
|
|
|
|
CREATE_ADMIN = "1";
|
|
|
|
};
|
|
|
|
|
2022-01-02 12:00:00 +00:00
|
|
|
services.postgresql = {
|
|
|
|
enable = true;
|
|
|
|
ensureUsers = [ {
|
|
|
|
name = dbUser;
|
|
|
|
ensurePermissions = {
|
|
|
|
"DATABASE ${dbName}" = "ALL PRIVILEGES";
|
|
|
|
};
|
|
|
|
} ];
|
|
|
|
ensureDatabases = [ dbName ];
|
|
|
|
};
|
2018-12-21 18:36:58 +00:00
|
|
|
|
2021-01-28 18:09:31 +00:00
|
|
|
systemd.services.miniflux-dbsetup = {
|
|
|
|
description = "Miniflux database setup";
|
|
|
|
requires = [ "postgresql.service" ];
|
|
|
|
after = [ "network.target" "postgresql.service" ];
|
|
|
|
serviceConfig = {
|
|
|
|
Type = "oneshot";
|
|
|
|
User = config.services.postgresql.superUser;
|
|
|
|
ExecStart = preStart;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2018-12-21 18:36:58 +00:00
|
|
|
systemd.services.miniflux = {
|
|
|
|
description = "Miniflux service";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
2022-01-02 12:00:00 +00:00
|
|
|
requires = [ "miniflux-dbsetup.service" ];
|
2021-01-28 18:09:31 +00:00
|
|
|
after = [ "network.target" "postgresql.service" "miniflux-dbsetup.service" ];
|
2018-12-21 18:36:58 +00:00
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
ExecStart = "${pkgs.miniflux}/bin/miniflux";
|
2022-01-02 12:00:00 +00:00
|
|
|
User = dbUser;
|
2018-12-21 18:36:58 +00:00
|
|
|
DynamicUser = true;
|
|
|
|
RuntimeDirectory = "miniflux";
|
|
|
|
RuntimeDirectoryMode = "0700";
|
2022-01-02 12:00:00 +00:00
|
|
|
EnvironmentFile = cfg.adminCredentialsFile;
|
2021-08-08 11:58:30 +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";
|
2022-01-02 12:00:00 +00:00
|
|
|
RestrictAddressFamilies = [ "AF_INET" "AF_INET6" "AF_UNIX" ];
|
2021-08-08 11:58:30 +00:00
|
|
|
RestrictNamespaces = true;
|
|
|
|
RestrictRealtime = true;
|
|
|
|
RestrictSUIDSGID = true;
|
|
|
|
SystemCallArchitectures = "native";
|
|
|
|
SystemCallFilter = [ "@system-service" "~@privileged" "~@resources" ];
|
|
|
|
UMask = "0077";
|
2018-12-21 18:36:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
environment = cfg.config;
|
|
|
|
};
|
|
|
|
environment.systemPackages = [ pkgs.miniflux ];
|
|
|
|
};
|
|
|
|
}
|