modules/miniflux: use custom module to replace the upstream one

This commit is contained in:
xinyangli 2024-08-05 20:04:10 +08:00
parent 1b2ed92211
commit 1906c39add
Signed by: xin
SSH key fingerprint: SHA256:qZ/tzd8lYRtUFSrfBDBMcUqV4GHKxqeqRA3huItgvbk
5 changed files with 136 additions and 18 deletions

View file

@ -3,7 +3,7 @@ gts_env: ENC[AES256_GCM,data:CKFKHXCJvTD0HFkVrBWhabcl/cloCT03qcZIc5JymiIAu+o6wef
hedgedoc_env: ENC[AES256_GCM,data:zwAA+zKSJT0tZyYArCaa1lfL0y8DNHDp/thS11DrVxNvjmk38o0ydsKArfZKzFYye+qNBzz1B4sPCdW4cFgQUNgbM+n9AvoMB8CssdmQ+sALKmozA5aEV23q+khZSGlHocP6WA==,iv:SgZruOS1nanK64Ex1dvgoD1HzbGbNa4DFSBuVoaNgEc=,tag:R+I8m1AloDCXs5PdpEpS0w==,type:str] hedgedoc_env: ENC[AES256_GCM,data:zwAA+zKSJT0tZyYArCaa1lfL0y8DNHDp/thS11DrVxNvjmk38o0ydsKArfZKzFYye+qNBzz1B4sPCdW4cFgQUNgbM+n9AvoMB8CssdmQ+sALKmozA5aEV23q+khZSGlHocP6WA==,iv:SgZruOS1nanK64Ex1dvgoD1HzbGbNa4DFSBuVoaNgEc=,tag:R+I8m1AloDCXs5PdpEpS0w==,type:str]
grafana_oauth_secret: ENC[AES256_GCM,data:2dSgxeWXNtlvbrgW9whCVuM6tfzd4lVhynwQTSPbBJndhI8scpJle7LjI1+b14FS9boBsuYO+ym4Pf1I8/jJtKkj6X6I0BmXFBC/SfpCpo+ZGrxacg==,iv:N8iTPqMagKP3hWc7n0bjgYKvaFaw11ITvDn9lUkkAPY=,tag:Cz59fA2Zq3jVvhfxaFuGAA==,type:str] grafana_oauth_secret: ENC[AES256_GCM,data:2dSgxeWXNtlvbrgW9whCVuM6tfzd4lVhynwQTSPbBJndhI8scpJle7LjI1+b14FS9boBsuYO+ym4Pf1I8/jJtKkj6X6I0BmXFBC/SfpCpo+ZGrxacg==,iv:N8iTPqMagKP3hWc7n0bjgYKvaFaw11ITvDn9lUkkAPY=,tag:Cz59fA2Zq3jVvhfxaFuGAA==,type:str]
miniflux: miniflux:
oauth2_secret: ENC[AES256_GCM,data:ktwQgPwcXTmMFhiTjXUGmPysfSg6X+EFBbfZMQ==,iv:vYF86NFW1EGf1TYLicTGiTIRKP/XC914zmVm42SyWPc=,tag:E1BdVp35362X373EE1HKvg==,type:str] oauth2_secret: ENC[AES256_GCM,data:Q0JeT5VHGEDATXB9jf5+eU1Hoi9FsJrw6IK2T0bodvVgki+1oF+sWld5NGpoiXm/bQ==,iv:e8+84Zk5eXNIyIPhTG8jFhO+DCRorPFG0lDDNT4OxCs=,tag:IxlyFBcFaSy7Nz0aQCH3bw==,type:str]
sops: sops:
kms: [] kms: []
gcp_kms: [] gcp_kms: []
@ -28,8 +28,8 @@ sops:
dnFBa0lDWWZtS1BHdzBoVzNTaGNkSEEKi/W1n7RT8NpTp00SBMwxsUJAPDhumJ/i dnFBa0lDWWZtS1BHdzBoVzNTaGNkSEEKi/W1n7RT8NpTp00SBMwxsUJAPDhumJ/i
V2VnaSNwouD3SswTcoBzqQpBP9XrqzjIYGke90ZODFQbMY9WDQ+O0g== V2VnaSNwouD3SswTcoBzqQpBP9XrqzjIYGke90ZODFQbMY9WDQ+O0g==
-----END AGE ENCRYPTED FILE----- -----END AGE ENCRYPTED FILE-----
lastmodified: "2024-08-05T07:07:04Z" lastmodified: "2024-08-05T08:53:56Z"
mac: ENC[AES256_GCM,data:1/PFLb8fgNgBz4YZDqNUxw5JMzt+ATD1wuFWNwJkVGVlXgLpSuOYZc5TYte3W8HTLDY8YOFYdcZtvDyjeFf7PAGxAVhqE1TgAfs0HxEHY3S8Ivcen86LTmcsiPy1frGHOLhzFfim3GRLyNA+MUFzCSLCbERJ0t0iK+L0EZ9SoyY=,iv:+DeQvoP3xBBEkv0IaQ5R0EFtQ/19bKSG/eRrDp4JPJs=,tag:Xz3sSbS07rcNaoImy10P5A==,type:str] mac: ENC[AES256_GCM,data:DtAL9k/t4pGV2UqCrb1R/1nT3gjJ8wced5yQOF5oneoncg/uuyX7IDZ0iZz0eGirj9Zadh9UQWNwxMzoiNu6pD1v04MkxT0NVDJ32vt5X+YDQJ60vRJjn9+zKvLk8Esx9sFsuBxjVXXmbtev7+djU+LbpPLfaobdheO2XlJXtdU=,iv:y2KI5ylgvuQ7ktYAr6XPEX3qyxnSP7BWC79mdsr4hgk=,tag:cvXvXeKvRwvttgQfmZRi2w==,type:str]
pgp: [] pgp: []
unencrypted_suffix: _unencrypted unencrypted_suffix: _unencrypted
version: 3.9.0 version: 3.9.0

View file

@ -29,6 +29,7 @@ in
custom.prometheus = { custom.prometheus = {
enable = true; enable = true;
exporters.blackbox.enable = true; exporters.blackbox.enable = true;
exporters.miniflux.enable = true;
}; };
systemd.mounts = map systemd.mounts = map
@ -89,13 +90,14 @@ in
custom.miniflux = { custom.miniflux = {
enable = true; enable = true;
environment = { environment = {
LOG_LEVEL = "debug";
LISTEN_ADDR = "127.0.0.1:58173"; LISTEN_ADDR = "127.0.0.1:58173";
BASE_URL = "https://rss.xinyang.life/";
OAUTH2_PROVIDER = "oidc"; OAUTH2_PROVIDER = "oidc";
OAUTH2_CLIEND_ID = "miniflux"; OAUTH2_CLIENT_ID = "miniflux";
OAUTH2_REDIRECT_URL = "https://rss.xinyang.life/oauth2/oidc/callback"; OAUTH2_REDIRECT_URL = "https://rss.xinyang.life/oauth2/oidc/callback";
OAUTH2_OIDC_DISCOVERY_ENDPOINT = "https://auth.xinyang.life/oauth2/openid/miniflux"; OAUTH2_OIDC_DISCOVERY_ENDPOINT = "https://auth.xinyang.life/oauth2/openid/miniflux";
OAUTH2_USER_CREATION = 1; OAUTH2_USER_CREATION = 1;
CREATE_ADMIN = lib.mkForce "";
}; };
oauth2SecretFile = config.sops.secrets."miniflux/oauth2_secret".path; oauth2SecretFile = config.sops.secrets."miniflux/oauth2_secret".path;
}; };
@ -255,7 +257,7 @@ in
''; '';
virtualHosts."https://rss.xinyang.life".extraConfig = '' virtualHosts."https://rss.xinyang.life".extraConfig = ''
reverse_proxy ${config.services.miniflux.config.LISTEN_ADDR} reverse_proxy ${config.custom.miniflux.environment.LISTEN_ADDR}
''; '';
virtualHosts."https://ntfy.xinyang.life".extraConfig = '' virtualHosts."https://ntfy.xinyang.life".extraConfig = ''

View file

@ -1,36 +1,133 @@
{ config, pkgs, lib, ... }: { config, pkgs, lib, ... }:
let let
inherit (lib) mkEnableOption mkOption types; inherit (lib) mkEnableOption mkPackageOption mkOption types literalExpression mkIf mkDefault;
cfg = config.custom.miniflux; cfg = config.custom.miniflux;
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"
'';
in in
{ {
options = { options = {
custom.miniflux = { custom.miniflux = {
enable = mkEnableOption "miniflux"; enable = mkEnableOption "miniflux";
package = mkPackageOption pkgs "miniflux" { };
oauth2SecretFile = mkOption { oauth2SecretFile = mkOption {
type = types.path; type = types.path;
}; };
environmentFile = mkOption {
type = types.path;
default = "/dev/null";
};
environment = mkOption { environment = mkOption {
type = with types; attrsOf (oneOf [ int str ]); type = with types; attrsOf (oneOf [ int str ]);
}; };
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.
'';
};
}; };
}; };
config = lib.mkIf cfg.enable { config = lib.mkIf cfg.enable {
services.miniflux = { 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 {
enable = true; enable = true;
adminCredentialsFile = cfg.environmentFile; ensureUsers = [{
name = "miniflux";
ensureDBOwnership = true;
}];
ensureDatabases = [ "miniflux" ];
}; };
systemd.services.miniflux = {
systemd.services.miniflux-dbsetup = lib.mkIf cfg.createDatabaseLocally {
description = "Miniflux database setup";
requires = [ "postgresql.service" ];
after = [ "network.target" "postgresql.service" ];
serviceConfig = { serviceConfig = {
Type = "oneshot";
User = config.services.postgresql.superUser;
ExecStart = preStart;
};
};
systemd.services.miniflux = {
description = "Miniflux service";
wantedBy = [ "multi-user.target" ];
requires = lib.optional cfg.createDatabaseLocally "miniflux-dbsetup.service";
after = [ "network.target" ]
++ lib.optionals cfg.createDatabaseLocally [ "postgresql.service" "miniflux-dbsetup.service" ];
serviceConfig = {
Type = "notify";
ExecStart = lib.getExe cfg.package;
User = "miniflux";
DynamicUser = true;
LoadCredential = [ "oauth2_secret:${cfg.oauth2SecretFile}" ]; LoadCredential = [ "oauth2_secret:${cfg.oauth2SecretFile}" ];
EnvironmentFile = [ "%d/oauth2_secret" ]; 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";
RestrictAddressFamilies = [ "AF_INET" "AF_INET6" "AF_UNIX" ];
RestrictNamespaces = true;
RestrictRealtime = true;
RestrictSUIDSGID = true;
SystemCallArchitectures = "native";
SystemCallFilter = [ "@system-service" "~@privileged" ];
UMask = "0077";
}; };
environment = lib.mapAttrs (_: lib.mkForce) (lib.mapAttrs (_: toString) cfg.environment);
environment = lib.mapAttrs (_: toString) cfg.environment;
}; };
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/**,
}
'';
}; };
} }

View file

@ -29,6 +29,7 @@ in
./caddy.nix ./caddy.nix
./gotosocial.nix ./gotosocial.nix
./immich.nix ./immich.nix
./miniflux.nix
./ntfy-sh.nix ./ntfy-sh.nix
./restic.nix ./restic.nix
]; ];
@ -48,7 +49,8 @@ in
caddy.enable = mkExporterOption config.services.caddy.enable; caddy.enable = mkExporterOption config.services.caddy.enable;
gotosocial.enable = mkExporterOption config.services.gotosocial.enable; gotosocial.enable = mkExporterOption config.services.gotosocial.enable;
immich.enable = mkExporterOption config.services.immich.enable; immich.enable = mkExporterOption config.services.immich.enable;
ntfy-sh.enable = mkExporterOption config.services.gotosocial.enable; miniflux.enable = mkExporterOption config.services.miniflux.enable;
ntfy-sh.enable = mkExporterOption config.services.ntfy-sh.enable;
}; };
grafana = { grafana = {
enable = mkEnableOption "Grafana Cloud"; enable = mkEnableOption "Grafana Cloud";

View file

@ -0,0 +1,17 @@
{ config, lib, ... }:
let
cfg = config.custom.prometheus;
in
{
config = lib.mkIf (cfg.enable && cfg.exporters.miniflux.enable) {
systemd.services.miniflux.environment.METRICS_COLLECTOR = 1;
services.prometheus.scrapeConfigs = [
{
job_name = "miniflux";
static_configs = [
{ targets = [ config.systemd.services.miniflux.environment.LISTEN_ADDR ]; }
];
}
];
};
}