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
|
|
|
pgbin = "${config.services.postgresql.package}/bin";
|
|
|
|
preStart = pkgs.writeScript "miniflux-pre-start" ''
|
|
|
|
#!${pkgs.runtimeShell}
|
2024-01-02 11:29:13 +00:00
|
|
|
${pgbin}/psql "miniflux" -c "CREATE EXTENSION IF NOT EXISTS hstore"
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
options = {
|
|
|
|
services.miniflux = {
|
2024-04-21 15:54:59 +00:00
|
|
|
enable = mkEnableOption "miniflux";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2024-01-02 11:29:13 +00:00
|
|
|
package = mkPackageOption pkgs "miniflux" { };
|
2022-12-17 10:02:37 +00:00
|
|
|
|
2024-04-21 15:54:59 +00:00
|
|
|
createDatabaseLocally = lib.mkOption {
|
|
|
|
type = lib.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.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
config = mkOption {
|
2024-01-25 14:12:00 +00:00
|
|
|
type = with types; attrsOf (oneOf [ str int ]);
|
2021-10-06 13:57:05 +00:00
|
|
|
example = literalExpression ''
|
2020-04-24 23:36:52 +00:00
|
|
|
{
|
2024-01-25 14:12:00 +00:00
|
|
|
CLEANUP_FREQUENCY = 48;
|
2020-04-24 23:36:52 +00:00
|
|
|
LISTEN_ADDR = "localhost:8080";
|
|
|
|
}
|
|
|
|
'';
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Configuration for Miniflux, refer to
|
2022-08-12 12:06:08 +00:00
|
|
|
<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
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-04-21 15:54:59 +00:00
|
|
|
adminCredentialsFile = mkOption {
|
2022-03-05 16:20:37 +00:00
|
|
|
type = types.path;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2022-03-05 16:20:37 +00:00
|
|
|
File containing the ADMIN_USERNAME and
|
|
|
|
ADMIN_PASSWORD (length >= 6) in the format of
|
2020-04-24 23:36:52 +00:00
|
|
|
an EnvironmentFile=, as described by systemd.exec(5).
|
|
|
|
'';
|
|
|
|
example = "/etc/nixos/miniflux-admin-credentials";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2024-04-21 15:54:59 +00:00
|
|
|
services.miniflux.config = {
|
2022-02-10 20:34:41 +00:00
|
|
|
LISTEN_ADDR = mkDefault defaultAddress;
|
2024-04-21 15:54:59 +00:00
|
|
|
DATABASE_URL = lib.mkIf cfg.createDatabaseLocally "user=miniflux host=/run/postgresql dbname=miniflux";
|
2024-01-25 14:12:00 +00:00
|
|
|
RUN_MIGRATIONS = 1;
|
|
|
|
CREATE_ADMIN = 1;
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
2024-04-21 15:54:59 +00:00
|
|
|
services.postgresql = lib.mkIf cfg.createDatabaseLocally {
|
2022-03-05 16:20:37 +00:00
|
|
|
enable = true;
|
|
|
|
ensureUsers = [ {
|
2024-01-02 11:29:13 +00:00
|
|
|
name = "miniflux";
|
|
|
|
ensureDBOwnership = true;
|
2022-03-05 16:20:37 +00:00
|
|
|
} ];
|
2024-01-02 11:29:13 +00:00
|
|
|
ensureDatabases = [ "miniflux" ];
|
2022-03-05 16:20:37 +00:00
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2024-04-21 15:54:59 +00:00
|
|
|
systemd.services.miniflux-dbsetup = lib.mkIf cfg.createDatabaseLocally {
|
2021-03-15 08:37:03 +00:00
|
|
|
description = "Miniflux database setup";
|
|
|
|
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" ];
|
2024-04-21 15:54:59 +00:00
|
|
|
requires = lib.optional cfg.createDatabaseLocally "miniflux-dbsetup.service";
|
|
|
|
after = [ "network.target" ]
|
|
|
|
++ lib.optionals cfg.createDatabaseLocally [ "postgresql.service" "miniflux-dbsetup.service" ];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
serviceConfig = {
|
2022-12-17 10:02:37 +00:00
|
|
|
ExecStart = "${cfg.package}/bin/miniflux";
|
2024-01-02 11:29:13 +00:00
|
|
|
User = "miniflux";
|
2020-04-24 23:36:52 +00:00
|
|
|
DynamicUser = true;
|
|
|
|
RuntimeDirectory = "miniflux";
|
2024-01-25 14:12:00 +00:00
|
|
|
RuntimeDirectoryMode = "0750";
|
2022-03-05 16:20:37 +00:00
|
|
|
EnvironmentFile = 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";
|
2022-03-05 16:20:37 +00:00
|
|
|
RestrictAddressFamilies = [ "AF_INET" "AF_INET6" "AF_UNIX" ];
|
2021-08-08 23:34:03 +00:00
|
|
|
RestrictNamespaces = true;
|
|
|
|
RestrictRealtime = true;
|
|
|
|
RestrictSUIDSGID = true;
|
|
|
|
SystemCallArchitectures = "native";
|
2022-10-30 15:09:59 +00:00
|
|
|
SystemCallFilter = [ "@system-service" "~@privileged" ];
|
2021-08-08 23:34:03 +00:00
|
|
|
UMask = "0077";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
2024-01-25 14:12:00 +00:00
|
|
|
environment = lib.mapAttrs (_: toString) cfg.config;
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
2022-12-17 10:02:37 +00:00
|
|
|
environment.systemPackages = [ cfg.package ];
|
2023-08-04 22:07:22 +00:00
|
|
|
|
|
|
|
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,
|
2024-04-21 15:54:59 +00:00
|
|
|
rw /run/miniflux/**,
|
2023-08-04 22:07:22 +00:00
|
|
|
}
|
|
|
|
'';
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
}
|