Commit fbfe35abb609
Changed files (4)
secrets/rhea/joplin.env.age
@@ -0,0 +1,9 @@
+age-encryption.org/v1
+-> piv-p256 ItIHHA A6VmJFyYka86D6wydgKa1+XDZAPjQRhW1mnHzOahN6US
+UR19THkDMPrizE7yaysKadAlTRyUu1GTGHEnNBrFFEg
+-> piv-p256 cUinNw A+9jOpKsAvkFrzX6USOpuvSQnQFRtjWCZyzRpLb/roYR
+fM5Hk+34TbuVFyyYrNg3nR1WszLUDU75hij7D5TVvCQ
+-> ssh-ed25519 EboMJg PN6NkaSs9Lx01H+B+3GAOWo/Rt3IYdR/jvtC1uxLRDw
+r+gHskWNlQTUnOlSu7uObFImPy8NColBgE6zEmutD4I
+--- VuoL4fHBdX47eDC606CF72fEFMcTWa6eHNEiqT1KfS4
+g�B[�C��
�_�Oy�t��9\
/��4�v��xF���Lv���Ēl,�l7���(�!V�[p�tz�!db��*�z���OG��[�ZY�����Xk=�d�i�
\ No newline at end of file
systems/rhea/extra.nix
@@ -95,6 +95,10 @@ in
owner = "traefik";
group = "traefik";
};
+ "joplin.env" = {
+ file = ../../secrets/rhea/joplin.env.age;
+ mode = "400";
+ };
"webdav-password" = {
file = ../../secrets/rhea/webdav-password.age;
mode = "400";
@@ -249,6 +253,7 @@ in
altHosts = [ "books.sbr.pm" ];
};
dav.port = 6065;
+ joplin.port = 22300;
};
# Generate routers for local services
@@ -327,6 +332,7 @@ in
syncthingRouters
// localRouters
// {
+ joplin = mkRouterWithMiddlewares "joplin" [ "joplin.sbr.pm" ] [ "joplin-allowlist" ];
# Override immich router to add large file upload middleware
immich = mkRouterWithMiddlewares "immich" [ "immich.sbr.pm" ] [ "immich-buffering" ];
# Override home router to add Home Assistant headers
@@ -387,6 +393,7 @@ in
syncthingMiddlewares
// syncthingAddSlashMiddlewares
// {
+ joplin-allowlist.ipAllowList.sourceRange = globals.net.dns.cacheNetworks;
# Middleware for handling large file uploads (Immich)
immich-buffering = {
buffering = {
@@ -490,13 +497,21 @@ in
};
postgresql = {
package = pkgs.postgresql_16;
+ authentication = lib.mkBefore ''
+ local joplin joplin scram-sha-256
+ '';
ensureDatabases = [
"immich"
+ "joplin"
];
ensureUsers = [
{
name = "vincent";
}
+ {
+ name = "joplin";
+ ensureDBOwnership = true;
+ }
];
};
jellyfin = serviceDefaults // {
@@ -728,6 +743,35 @@ in
}
) exportarrServices;
+ # Stream a fresh consistent PostgreSQL dump directly to restic. A failed
+ # pg_dump fails the backup; there is no on-disk dump that can become stale.
+ restic.backups.aix-joplin = {
+ user = "vincent";
+ repository = "sftp:vincent@aix.sbr.pm:/data/backup/restic/rhea";
+ passwordFile = config.age.secrets."restic-aix-password".path;
+ command = [
+ "${config.services.postgresql.package}/bin/pg_dump"
+ "--format=custom"
+ "--dbname=joplin"
+ ];
+ extraBackupArgs = [
+ "--stdin-filename=joplin.dump"
+ "--tag=joplin"
+ ];
+ timerConfig = {
+ OnCalendar = "daily";
+ Persistent = true;
+ RandomizedDelaySec = "2h";
+ };
+ pruneOpts = [
+ "--keep-daily 7"
+ "--keep-weekly 4"
+ "--keep-monthly 12"
+ "--group-by host,paths,tags"
+ "--tag joplin"
+ ];
+ };
+
# Restic backup to aix (off-site backup)
# Note: Media files are rsync'd (rhea → aion → aix)
# This backup focuses on arr service databases and configs
@@ -831,10 +875,52 @@ in
$PSQL immich -tAc "ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON TABLES TO vincent"
'';
+ # Set the dedicated role's password without putting it in the Nix store or
+ # process arguments. The generated secret contains only a hex password.
+ systemd.services.joplin-db-password = {
+ requires = [ "postgresql.service" ];
+ after = [ "postgresql.service" ];
+ before = [ "podman-joplin.service" ];
+ serviceConfig = {
+ Type = "oneshot";
+ EnvironmentFile = config.age.secrets."joplin.env".path;
+ };
+ script = ''
+ case "$POSTGRES_PASSWORD" in
+ ""|*[!0-9a-f]*) exit 1 ;;
+ esac
+ printf "ALTER ROLE joplin PASSWORD '%s';\n" "$POSTGRES_PASSWORD" | \
+ ${pkgs.util-linux}/bin/runuser -u postgres -- ${config.services.postgresql.package}/bin/psql -v ON_ERROR_STOP=1 -d postgres
+ '';
+ };
+ systemd.services.podman-joplin = {
+ requires = [ "joplin-db-password.service" ];
+ after = [ "joplin-db-password.service" ];
+ };
+ systemd.services.restic-backups-aix-joplin = {
+ requires = [ "postgresql.service" ];
+ after = [ "postgresql.service" ];
+ };
+
# Liseur Sync indexes the Calibre library and synchronizes reader state.
virtualisation.podman.enable = true;
virtualisation.oci-containers = {
backend = "podman";
+ containers.joplin = {
+ image = "docker.io/joplin/server@sha256:1cd9097ec3f788ba9813b7907dd8d525c834b93c725da1add189bfd08f746cf0";
+ environment = {
+ APP_BASE_URL = "https://joplin.sbr.pm";
+ APP_PORT = "22300";
+ DB_CLIENT = "pg";
+ POSTGRES_DATABASE = "joplin";
+ POSTGRES_USER = "joplin";
+ POSTGRES_HOST = "/var/run/postgresql";
+ POSTGRES_PORT = toString config.services.postgresql.settings.port;
+ };
+ environmentFiles = [ config.age.secrets."joplin.env".path ];
+ ports = [ "127.0.0.1:22300:22300" ];
+ volumes = [ "/run/postgresql:/var/run/postgresql" ];
+ };
containers.liseur-sync = {
image = "ghcr.io/chmouel/liseur-sync@sha256:5015b61a6ac32eea9fdaa641b15c9a6234a4700b9d2a8a07ffcba2485efdaf24";
pull = "newer";
globals.nix
@@ -753,6 +753,7 @@ _: {
host = "rhea";
aliases = [ "photos" ];
};
+ joplin.host = "rhea";
jellyfin.host = "rhea";
jellyseerr.host = "rhea";
sonarr.host = "rhea";
secrets.nix
@@ -38,6 +38,8 @@ in
# Restic backup password for carthage
"secrets/carthage/restic-aix-password.age".publicKeys = users ++ [ carthage ];
+ "secrets/rhea/joplin.env.age".publicKeys = users ++ [ rhea ];
+
# Mail passwords
"secrets/mails/icloud-vdemeester.age".publicKeys = users ++ [
sakhalin