From 11f6c18f13fd2990fa62de5f5c564b8950a2a1ff Mon Sep 17 00:00:00 2001 From: Gabe Venberg Date: Sat, 3 May 2025 22:26:25 +0200 Subject: [PATCH] added immich to the homelab. --- configs/nixos/homepage.nix | 8 ++++++ configs/nixos/immich.nix | 43 ++++++++++++++++++++++++++++++ hosts/cirrostratus/default.nix | 1 + hosts/cirrostratus/disk-config.nix | 8 ++++++ modules/nixos/restic.nix | 6 +++++ 5 files changed, 66 insertions(+) create mode 100644 configs/nixos/immich.nix diff --git a/configs/nixos/homepage.nix b/configs/nixos/homepage.nix index 62e2c8c..107635a 100644 --- a/configs/nixos/homepage.nix +++ b/configs/nixos/homepage.nix @@ -80,6 +80,14 @@ in { description = "Movies"; }; } + { + Immich = { + icon = "sh-immich.svg"; + href = "https://pics.venberg.xyz"; + siteMonitor = "https://pics.venberg.xyz"; + description = "Pictures"; + }; + } { Grocy = { icon = "sh-grocy.svg"; diff --git a/configs/nixos/immich.nix b/configs/nixos/immich.nix new file mode 100644 index 0000000..ac36e83 --- /dev/null +++ b/configs/nixos/immich.nix @@ -0,0 +1,43 @@ +{ + inputs, + config, + pkgs, + lib, + ... +}: let + port = 2283; + cfg = config.services.immich; + backupPrepare = pkgs.writeShellScriptBin "postgres-immich-dump" '' + set -euxo pipefail + ${lib.getExe pkgs.sudo} -iu postgres pg_dump -Fc immich > /backup/immich_psql.dump + ''; +in { + # make sure your postgres database is on big storage, and if using zfs, create with the following settings: + # zfs create -o recordsize=8K -o primarycache=metadata -o mountpoint=/var/lib/postgresql /postgresql + services.immich = { + enable = true; + port = port; + machine-learning.enable = true; + mediaLocation = "/storage/immich"; + settings = null; + }; + imports = [ + ./nginx.nix + ]; + services.nginx.virtualHosts."pics.venberg.xyz" = { + enableACME = true; + forceSSL = true; + locations."/" = { + proxyPass = "http://localhost:${toString port}"; + }; + }; + host.restic.backups.immich = { + preBackupCommands = lib.getExe backupPrepare; + paths = [ + "/backup/immich_psql.dump" + "${cfg.mediaLocation}/library" + "${cfg.mediaLocation}/upload" + "${cfg.mediaLocation}/profile" + ]; + }; +} diff --git a/hosts/cirrostratus/default.nix b/hosts/cirrostratus/default.nix index 3473b5f..902e158 100644 --- a/hosts/cirrostratus/default.nix +++ b/hosts/cirrostratus/default.nix @@ -31,6 +31,7 @@ inputs.nixpkgs.lib.nixosSystem { ../../configs/nixos/miniserve-tmp-upload.nix ../../configs/nixos/minecraft-docker.nix ../../configs/nixos/nginx-static.nix + ../../configs/nixos/immich.nix ({ config, pkgs, diff --git a/hosts/cirrostratus/disk-config.nix b/hosts/cirrostratus/disk-config.nix index a244546..b140f48 100644 --- a/hosts/cirrostratus/disk-config.nix +++ b/hosts/cirrostratus/disk-config.nix @@ -69,6 +69,14 @@ mountpoint = "/storage"; }; datasets = { + database={ + type = "zfs_fs"; + options = { + mountpoint ="/postgres"; + recordsize = "8K"; + primarycache="metadata"; + }; + }; backup = { type = "zfs_fs"; options = { diff --git a/modules/nixos/restic.nix b/modules/nixos/restic.nix index 92a0625..b1f0c95 100644 --- a/modules/nixos/restic.nix +++ b/modules/nixos/restic.nix @@ -50,6 +50,11 @@ type = lib.types.listOf lib.types.path; description = "paths to back up."; }; + user = lib.mkOption { + type = lib.types.str; + description = "what user to run the backup under."; + default = "root"; + }; preBackupCommands = lib.mkOption { type = lib.types.nullOr lib.types.lines; description = "commands to run before the start of the backup."; @@ -139,6 +144,7 @@ backupPrepareCommand = backup.preBackupCommands; backupCleanupCommand = backup.postBackupCommands; paths = backup.paths; + user = backup.user; } ) cfg.backups