1 { config, lib, pkgs, ... }:
4 inherit (lib) mkEnableOption mkPackageOption mkOption types literalExpression mkIf mkDefault;
5 cfg = config.services.miniflux;
7 defaultAddress = "localhost:8080";
9 pgbin = "${config.services.postgresql.package}/bin";
10 preStart = pkgs.writeScript "miniflux-pre-start" ''
11 #!${pkgs.runtimeShell}
12 ${pgbin}/psql "miniflux" -c "CREATE EXTENSION IF NOT EXISTS hstore"
19 enable = mkEnableOption "miniflux";
21 package = mkPackageOption pkgs "miniflux" { };
23 createDatabaseLocally = mkOption {
27 Whether a PostgreSQL database should be automatically created and
28 configured on the local host. If set to `false`, you need provision a
29 database yourself and make sure to create the hstore extension in it.
34 type = with types; attrsOf (oneOf [ str int ]);
35 example = literalExpression ''
37 CLEANUP_FREQUENCY = 48;
38 LISTEN_ADDR = "localhost:8080";
42 Configuration for Miniflux, refer to
43 <https://miniflux.app/docs/configuration.html>
44 for documentation on the supported values.
46 Correct configuration for the database is already provided.
47 By default, listens on ${defaultAddress}.
51 adminCredentialsFile = mkOption {
52 type = types.nullOr types.path;
55 File containing the ADMIN_USERNAME and
56 ADMIN_PASSWORD (length >= 6) in the format of
57 an EnvironmentFile=, as described by systemd.exec(5).
59 example = "/etc/nixos/miniflux-admin-credentials";
64 config = mkIf cfg.enable {
66 { assertion = cfg.config.CREATE_ADMIN == 0 || cfg.adminCredentialsFile != null;
67 message = "services.miniflux.adminCredentialsFile must be set if services.miniflux.config.CREATE_ADMIN is 1";
70 services.miniflux.config = {
71 LISTEN_ADDR = mkDefault defaultAddress;
72 DATABASE_URL = lib.mkIf cfg.createDatabaseLocally "user=miniflux host=/run/postgresql dbname=miniflux";
74 CREATE_ADMIN = lib.mkDefault 1;
78 services.postgresql = lib.mkIf cfg.createDatabaseLocally {
82 ensureDBOwnership = true;
84 ensureDatabases = [ "miniflux" ];
87 systemd.services.miniflux-dbsetup = lib.mkIf cfg.createDatabaseLocally {
88 description = "Miniflux database setup";
89 requires = [ "postgresql.service" ];
90 after = [ "network.target" "postgresql.service" ];
93 User = config.services.postgresql.superUser;
98 systemd.services.miniflux = {
99 description = "Miniflux service";
100 wantedBy = [ "multi-user.target" ];
101 requires = lib.optional cfg.createDatabaseLocally "miniflux-dbsetup.service";
102 after = [ "network.target" ]
103 ++ lib.optionals cfg.createDatabaseLocally [ "postgresql.service" "miniflux-dbsetup.service" ];
107 ExecStart = lib.getExe cfg.package;
110 RuntimeDirectory = "miniflux";
111 RuntimeDirectoryMode = "0750";
112 EnvironmentFile = lib.mkIf (cfg.adminCredentialsFile != null) cfg.adminCredentialsFile;
114 WatchdogSignal = "SIGKILL";
119 CapabilityBoundingSet = [ "" ];
120 DeviceAllow = [ "" ];
121 LockPersonality = true;
122 MemoryDenyWriteExecute = true;
123 PrivateDevices = true;
127 ProtectControlGroups = true;
129 ProtectHostname = true;
130 ProtectKernelLogs = true;
131 ProtectKernelModules = true;
132 ProtectKernelTunables = true;
133 ProtectProc = "invisible";
134 RestrictAddressFamilies = [ "AF_INET" "AF_INET6" "AF_UNIX" ];
135 RestrictNamespaces = true;
136 RestrictRealtime = true;
137 RestrictSUIDSGID = true;
138 SystemCallArchitectures = "native";
139 SystemCallFilter = [ "@system-service" "~@privileged" ];
143 environment = lib.mapAttrs (_: toString) cfg.config;
145 environment.systemPackages = [ cfg.package ];
147 security.apparmor.policies."bin.miniflux".profile = ''
148 include <tunables/global>
149 ${cfg.package}/bin/miniflux {
150 include <abstractions/base>
151 include <abstractions/nameservice>
152 include <abstractions/ssl_certs>
153 include "${pkgs.apparmorRulesFromClosure { name = "miniflux"; } cfg.package}"
154 r ${cfg.package}/bin/miniflux,
155 r @{sys}/kernel/mm/transparent_hugepage/hpage_pmd_size,