2024-08-25 09:45:58 +00:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
pkgs,
|
|
|
|
lib,
|
|
|
|
...
|
|
|
|
}:
|
2024-08-05 02:52:54 +00:00
|
|
|
let
|
2024-08-25 09:45:58 +00:00
|
|
|
inherit (lib)
|
|
|
|
mkEnableOption
|
|
|
|
mkPackageOption
|
|
|
|
mkOption
|
|
|
|
types
|
|
|
|
literalExpression
|
|
|
|
mkIf
|
|
|
|
mkDefault
|
|
|
|
;
|
2024-08-05 02:52:54 +00:00
|
|
|
cfg = config.custom.miniflux;
|
2024-08-05 12:04:10 +00:00
|
|
|
|
|
|
|
defaultAddress = "localhost:8080";
|
|
|
|
|
|
|
|
pgbin = "${config.services.postgresql.package}/bin";
|
|
|
|
preStart = pkgs.writeScript "miniflux-pre-start" ''
|
|
|
|
#!${pkgs.runtimeShell}
|
|
|
|
${pgbin}/psql "miniflux" -c "CREATE EXTENSION IF NOT EXISTS hstore"
|
|
|
|
'';
|
2024-08-05 02:52:54 +00:00
|
|
|
in
|
|
|
|
{
|
|
|
|
options = {
|
|
|
|
custom.miniflux = {
|
|
|
|
enable = mkEnableOption "miniflux";
|
2024-08-05 12:04:10 +00:00
|
|
|
|
|
|
|
package = mkPackageOption pkgs "miniflux" { };
|
|
|
|
|
2024-08-25 09:45:58 +00:00
|
|
|
oauth2SecretFile = mkOption { type = types.path; };
|
2024-08-05 12:04:10 +00:00
|
|
|
|
2024-08-05 02:52:54 +00:00
|
|
|
environment = mkOption {
|
2024-08-25 09:45:58 +00:00
|
|
|
type =
|
|
|
|
with types;
|
|
|
|
attrsOf (oneOf [
|
|
|
|
int
|
|
|
|
str
|
|
|
|
]);
|
2024-08-05 02:52:54 +00:00
|
|
|
};
|
2024-08-05 12:04:10 +00:00
|
|
|
|
|
|
|
createDatabaseLocally = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
|
|
|
description = ''
|
|
|
|
Whether a PostgreSQL database should be automatically created and
|
|
|
|
configured on the local host. If set to `false`, you need provision a
|
|
|
|
database yourself and make sure to create the hstore extension in it.
|
|
|
|
'';
|
|
|
|
};
|
2024-08-05 02:52:54 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = lib.mkIf cfg.enable {
|
2024-08-05 12:04:10 +00:00
|
|
|
services.miniflux.enable = false;
|
|
|
|
custom.miniflux.environment = {
|
|
|
|
LISTEN_ADDR = mkDefault defaultAddress;
|
|
|
|
RUN_MIGRATIONS = mkDefault 1;
|
|
|
|
DATABASE_URL = lib.mkIf cfg.createDatabaseLocally "user=miniflux host=/run/postgresql dbname=miniflux";
|
|
|
|
OAUTH2_CLIENT_SECRET_FILE = "%d/oauth2_secret";
|
|
|
|
WATCHDOG = mkDefault 1;
|
|
|
|
};
|
|
|
|
|
|
|
|
services.postgresql = lib.mkIf cfg.createDatabaseLocally {
|
2024-08-05 02:52:54 +00:00
|
|
|
enable = true;
|
2024-08-25 09:45:58 +00:00
|
|
|
ensureUsers = [
|
|
|
|
{
|
|
|
|
name = "miniflux";
|
|
|
|
ensureDBOwnership = true;
|
|
|
|
}
|
|
|
|
];
|
2024-08-05 12:04:10 +00:00
|
|
|
ensureDatabases = [ "miniflux" ];
|
|
|
|
};
|
|
|
|
|
|
|
|
systemd.services.miniflux-dbsetup = lib.mkIf cfg.createDatabaseLocally {
|
|
|
|
description = "Miniflux database setup";
|
|
|
|
requires = [ "postgresql.service" ];
|
2024-08-25 09:45:58 +00:00
|
|
|
after = [
|
|
|
|
"network.target"
|
|
|
|
"postgresql.service"
|
|
|
|
];
|
2024-08-05 12:04:10 +00:00
|
|
|
serviceConfig = {
|
|
|
|
Type = "oneshot";
|
|
|
|
User = config.services.postgresql.superUser;
|
|
|
|
ExecStart = preStart;
|
|
|
|
};
|
2024-08-05 02:52:54 +00:00
|
|
|
};
|
2024-08-05 12:04:10 +00:00
|
|
|
|
2024-08-05 02:52:54 +00:00
|
|
|
systemd.services.miniflux = {
|
2024-08-05 12:04:10 +00:00
|
|
|
description = "Miniflux service";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
requires = lib.optional cfg.createDatabaseLocally "miniflux-dbsetup.service";
|
2024-08-25 09:45:58 +00:00
|
|
|
after =
|
|
|
|
[ "network.target" ]
|
|
|
|
++ lib.optionals cfg.createDatabaseLocally [
|
|
|
|
"postgresql.service"
|
|
|
|
"miniflux-dbsetup.service"
|
|
|
|
];
|
2024-08-05 12:04:10 +00:00
|
|
|
|
2024-08-05 02:52:54 +00:00
|
|
|
serviceConfig = {
|
2024-08-05 12:04:10 +00:00
|
|
|
Type = "notify";
|
|
|
|
ExecStart = lib.getExe cfg.package;
|
|
|
|
User = "miniflux";
|
|
|
|
DynamicUser = true;
|
2024-08-05 02:52:54 +00:00
|
|
|
LoadCredential = [ "oauth2_secret:${cfg.oauth2SecretFile}" ];
|
2024-08-05 12:04:10 +00:00
|
|
|
RuntimeDirectory = "miniflux";
|
|
|
|
RuntimeDirectoryMode = "0750";
|
|
|
|
WatchdogSec = 60;
|
|
|
|
WatchdogSignal = "SIGKILL";
|
|
|
|
Restart = "always";
|
|
|
|
RestartSec = 5;
|
|
|
|
|
|
|
|
# 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";
|
2024-08-25 09:45:58 +00:00
|
|
|
RestrictAddressFamilies = [
|
|
|
|
"AF_INET"
|
|
|
|
"AF_INET6"
|
|
|
|
"AF_UNIX"
|
|
|
|
];
|
2024-08-05 12:04:10 +00:00
|
|
|
RestrictNamespaces = true;
|
|
|
|
RestrictRealtime = true;
|
|
|
|
RestrictSUIDSGID = true;
|
|
|
|
SystemCallArchitectures = "native";
|
2024-08-25 09:45:58 +00:00
|
|
|
SystemCallFilter = [
|
|
|
|
"@system-service"
|
|
|
|
"~@privileged"
|
|
|
|
];
|
2024-08-05 12:04:10 +00:00
|
|
|
UMask = "0077";
|
2024-08-05 02:52:54 +00:00
|
|
|
};
|
2024-08-05 12:04:10 +00:00
|
|
|
|
|
|
|
environment = lib.mapAttrs (_: toString) cfg.environment;
|
2024-08-05 02:52:54 +00:00
|
|
|
};
|
2024-08-05 12:04:10 +00:00
|
|
|
environment.systemPackages = [ cfg.package ];
|
|
|
|
|
|
|
|
security.apparmor.policies."bin.miniflux".profile = ''
|
|
|
|
include <tunables/global>
|
|
|
|
${cfg.package}/bin/miniflux {
|
|
|
|
include <abstractions/base>
|
|
|
|
include <abstractions/nameservice>
|
|
|
|
include <abstractions/ssl_certs>
|
|
|
|
include "${pkgs.apparmorRulesFromClosure { name = "miniflux"; } cfg.package}"
|
|
|
|
r ${cfg.package}/bin/miniflux,
|
|
|
|
r @{sys}/kernel/mm/transparent_hugepage/hpage_pmd_size,
|
|
|
|
rw /run/miniflux/**,
|
|
|
|
}
|
|
|
|
'';
|
2024-08-05 02:52:54 +00:00
|
|
|
};
|
|
|
|
}
|