feat(jupiter): shrink system closure for the 29G eMMC
Run immich and seerr as official images (their node/python stacks live in podman's graphroot on the array), ship only the firmware the board loads, and point jellyfin at intel-media-driver directly instead of hardware.graphics (mesa + llvm). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+159
-81
@@ -1,103 +1,181 @@
|
||||
{ config, pkgs, inputs, ... }:
|
||||
{ config, lib, pkgs, ... }:
|
||||
|
||||
# Immich photo/video library. Native nixpkgs module, not the upstream compose
|
||||
# stack — it owns its own postgres (pgvector + vectorchord) and a unix-socket redis.
|
||||
# Immich photo/video library. Postgres (pgvector + vectorchord) and a unix-socket
|
||||
# redis are native; the server and machine-learning run as the official images so
|
||||
# their ~2.5G node/python/onnx stacks live in podman's graphroot on the array
|
||||
# instead of the system closure on the eMMC.
|
||||
#
|
||||
# Storage lives under /mnt/data/AppData/immich, migrated from the old ZimaOS/CasaOS
|
||||
# UPLOAD_LOCATION (same subfolder layout); see scripts/immich-import-legacy-db for
|
||||
# the matching DB import. The postgres cluster itself stays on the OS disk.
|
||||
# the matching DB import.
|
||||
#
|
||||
# ⚠️ The immich DB is the only copy of albums/faces/dates — the files alone
|
||||
# can't rebuild it. It joins the other unbacked databases on this network.
|
||||
let
|
||||
# Package pinned to nixpkgs-unstable (3.0.3) while the module stays on the 26.05
|
||||
# pin (2.7.5) — safe only because the two module files are byte-identical
|
||||
# (verified by diff; re-check on any input bump). Needed because immich's
|
||||
# migrations are forward-only and jupiter's imported DB was last written by
|
||||
# 3.0.0, which 2.7.5 refuses to start against; drop once the pin ships >= 3.0.0.
|
||||
# diff <(nixpkgs)/nixos/modules/services/web-apps/immich.nix \
|
||||
# <(unstable)/nixos/modules/services/web-apps/immich.nix
|
||||
unstable = import inputs.nixpkgs-unstable {
|
||||
inherit (pkgs.stdenv.hostPlatform) system;
|
||||
# Migrations are forward-only: never move this tag backwards.
|
||||
version = "v3.2.4";
|
||||
mediaLocation = "/mnt/data/AppData/immich";
|
||||
mlCache = "/mnt/data/AppData/immich-ml-cache";
|
||||
# Containers run as the host's immich user so postgres peer auth and the
|
||||
# 0700 media dir keep working; ids are pinned below to keep this stable.
|
||||
uid = 988;
|
||||
gid = 985;
|
||||
redisGid = 984;
|
||||
usersGid = 100; # traverse /mnt/data/AppData (drwx--x--- darman:users)
|
||||
|
||||
# IMMICH_CONFIG_FILE is all-or-nothing: undeclared keys fall back to immich's
|
||||
# defaults, not the admin UI's saved values (which stay in system_metadata and
|
||||
# return if this file is dropped), and the admin settings UI goes read-only. An
|
||||
# unknown/misspelled key is a hard startup failure, so keys are copied verbatim
|
||||
# from `defaults` in immich's dist/config.js.
|
||||
settings = {
|
||||
server.externalDomain = "https://immich.mgaction.town";
|
||||
newVersionCheck.enabled = false; # the image tag pins the version, not immich
|
||||
|
||||
# OIDC via Authentik on neptun; the application/provider is created by hand
|
||||
# in its UI (like headscale's and headplane's, separate apps).
|
||||
oauth = {
|
||||
enabled = true;
|
||||
# Authentik's per-application issuer. Trailing slash matters: immich
|
||||
# appends /.well-known/openid-configuration to it.
|
||||
issuerUrl = "https://auth.mgaction.town/application/o/immich/";
|
||||
# Not a secret (it is sent in the browser redirect).
|
||||
clientId = "FxrkWFe8keBrN83tu03UbAshSck52he2GphJDYSQ";
|
||||
clientSecret = config.sops.placeholder.immich_oauth_client_secret;
|
||||
scope = "openid email profile";
|
||||
buttonText = "Login with Authentik";
|
||||
# Matches by email, so the 2 imported users adopt their Authentik account
|
||||
# instead of getting a duplicate.
|
||||
autoRegister = true;
|
||||
# Leave the password form reachable — autoLaunch would bounce straight
|
||||
# to Authentik, locking everyone out if the OIDC app is misconfigured.
|
||||
autoLaunch = false;
|
||||
# Without this, logout dumps you on Authentik's own page instead of back
|
||||
# here. Ends the immich session only; the Authentik SSO session survives.
|
||||
endSessionEndpoint = "https://auth.mgaction.town/application/o/immich/end-session?post_logout_redirect_url=https://immich.mgaction.town";
|
||||
# The mobile app can't follow a browser redirect back to a custom
|
||||
# scheme through Authentik, so immich bounces it via this endpoint.
|
||||
mobileOverrideEnabled = true;
|
||||
mobileRedirectUri = "https://immich.mgaction.town/api/oauth/mobile-redirect";
|
||||
};
|
||||
};
|
||||
|
||||
runAs = [
|
||||
"--network=host"
|
||||
"--user=${toString uid}:${toString gid}"
|
||||
"--group-add=${toString usersGid}"
|
||||
];
|
||||
in
|
||||
{
|
||||
services.immich = {
|
||||
# What the nixpkgs immich module set up besides the server itself — not used
|
||||
# because evaluating it forces its (insecure, too old) default package.
|
||||
services.postgresql = {
|
||||
enable = true;
|
||||
# Both the server and immich-machine-learning follow this: the module takes
|
||||
# the ML service from cfg.package.machine-learning (passthru).
|
||||
package = unstable.immich;
|
||||
# Listens on all interfaces: :2283 stays closed on the LAN (no
|
||||
# openFirewall), reachable over tailscale0 and via localhost (caddy).
|
||||
host = "0.0.0.0";
|
||||
port = 2283;
|
||||
mediaLocation = "/mnt/data/AppData/immich";
|
||||
machine-learning.enable = true;
|
||||
|
||||
# ⚠️ Setting `settings` at all switches immich to IMMICH_CONFIG_FILE mode,
|
||||
# which is all-or-nothing: undeclared keys fall back to immich's defaults, not
|
||||
# the admin UI's saved values (which stay in system_metadata and return if
|
||||
# this block is deleted), and the admin settings UI goes read-only. An
|
||||
# unknown/misspelled key is a hard startup failure here (just a warning
|
||||
# without a config file), so keys are copied verbatim from `defaults` in
|
||||
# immich's dist/config.js.
|
||||
ensureDatabases = [ "immich" ];
|
||||
ensureUsers = [{
|
||||
name = "immich";
|
||||
ensureDBOwnership = true;
|
||||
ensureClauses.login = true;
|
||||
}];
|
||||
extensions = ps: [ ps.pgvector ps.vectorchord ];
|
||||
settings = {
|
||||
server.externalDomain = "https://immich.mgaction.town";
|
||||
newVersionCheck.enabled = false; # nixpkgs pins the version, not immich
|
||||
|
||||
# OIDC via Authentik on neptun; the application/provider is created by hand
|
||||
# in its UI (like headscale's and headplane's, separate apps) — only the
|
||||
# client secret is managed here (hosts/neptun/secrets.nix).
|
||||
oauth = {
|
||||
enabled = true;
|
||||
# Authentik's per-application issuer. Trailing slash matters: immich
|
||||
# appends /.well-known/openid-configuration to it.
|
||||
issuerUrl = "https://auth.mgaction.town/application/o/immich/";
|
||||
# Authentik generates this; not a secret (it is sent in the browser
|
||||
# redirect), so it lives here rather than in sops.
|
||||
clientId = "FxrkWFe8keBrN83tu03UbAshSck52he2GphJDYSQ";
|
||||
# Read at runtime via systemd LoadCredential — never lands in the
|
||||
# world-readable /nix/store copy of the rendered config.
|
||||
clientSecret._secret = config.sops.secrets.immich_oauth_client_secret.path;
|
||||
scope = "openid email profile";
|
||||
buttonText = "Login with Authentik";
|
||||
# Matches by email, so the 2 imported users adopt their Authentik account
|
||||
# instead of getting a duplicate.
|
||||
autoRegister = true;
|
||||
# Leave the password form reachable — autoLaunch would bounce straight
|
||||
# to Authentik, locking everyone out if the OIDC app is misconfigured.
|
||||
autoLaunch = false;
|
||||
# Without this, immich falls back to the IdP's discovered
|
||||
# end_session_endpoint and logout dumps you on Authentik's own page
|
||||
# instead of back here — must be an absolute url, mirroring immich's
|
||||
# internal LOGIN_URL. This ends the immich session only; the Authentik
|
||||
# SSO session survives, so the next login skips the credential prompt —
|
||||
# drop this line to end both.
|
||||
endSessionEndpoint = "https://auth.mgaction.town/application/o/immich/end-session?post_logout_redirect_url=https://immich.mgaction.town";
|
||||
# The mobile app can't follow a browser redirect back to a custom
|
||||
# scheme through Authentik, so immich bounces it via this endpoint.
|
||||
mobileOverrideEnabled = true;
|
||||
mobileRedirectUri = "https://immich.mgaction.town/api/oauth/mobile-redirect";
|
||||
};
|
||||
shared_preload_libraries = [ "vchord.so" ];
|
||||
search_path = "\"$user\", public, vectors";
|
||||
};
|
||||
# Hardware transcoding needs accelerationDevices set explicitly (e.g.
|
||||
# "/dev/dri/renderD128"); default CPU-only transcode is slow on the
|
||||
# ZimaBlade's Celeron but only runs on upload.
|
||||
};
|
||||
# Reindex when vectorchord changes version:
|
||||
# https://docs.immich.app/administration/postgres-standalone/#updating-vectorchord
|
||||
systemd.services.postgresql-setup.serviceConfig.ExecStartPost =
|
||||
let
|
||||
extensions = [ "unaccent" "uuid-ossp" "cube" "earthdistance" "pg_trgm" "vector" "vchord" ];
|
||||
sqlFile = pkgs.writeText "immich-pgvectors-setup.sql" ''
|
||||
SELECT COALESCE(installed_version, ''') AS vchord_version_before FROM pg_available_extensions WHERE name = 'vchord' \gset
|
||||
${lib.concatMapStringsSep "\n" (ext: "CREATE EXTENSION IF NOT EXISTS \"${ext}\";") extensions}
|
||||
${lib.concatMapStringsSep "\n" (ext: "ALTER EXTENSION \"${ext}\" UPDATE;") extensions}
|
||||
ALTER SCHEMA public OWNER TO immich;
|
||||
SELECT COALESCE(installed_version, ''') AS vchord_version_after FROM pg_available_extensions WHERE name = 'vchord' \gset
|
||||
SELECT (:'vchord_version_before' != ''' AND :'vchord_version_before' != :'vchord_version_after') AS has_vchord_updated \gset
|
||||
\if :has_vchord_updated
|
||||
REINDEX INDEX face_index;
|
||||
REINDEX INDEX clip_index;
|
||||
\endif
|
||||
'';
|
||||
in
|
||||
[ "${lib.getExe' config.services.postgresql.package "psql"} -d immich -f ${sqlFile}" ];
|
||||
|
||||
services.redis.servers.immich = {
|
||||
enable = true;
|
||||
port = 0; # unix socket only
|
||||
};
|
||||
|
||||
# /mnt/data/AppData is drwx--x--- darman:users; immich only needs group "users"
|
||||
# to traverse into it — the dir itself stays 0700 immich:immich (tmpfiles +
|
||||
# UMask=0077 reassert that), so this grants nothing else.
|
||||
users.users.immich.extraGroups = [ "users" ];
|
||||
users.users.immich = {
|
||||
isSystemUser = true;
|
||||
group = "immich";
|
||||
inherit uid;
|
||||
# /mnt/data/AppData is drwx--x--- darman:users; group "users" only grants traversal.
|
||||
extraGroups = [ "users" ];
|
||||
};
|
||||
users.groups.immich.gid = gid;
|
||||
users.groups.redis-immich.gid = redisGid;
|
||||
|
||||
sops.templates."immich-config.json" = {
|
||||
owner = "immich";
|
||||
content = builtins.toJSON settings;
|
||||
};
|
||||
|
||||
virtualisation.oci-containers.containers = {
|
||||
immich-server = {
|
||||
image = "ghcr.io/immich-app/immich-server:${version}";
|
||||
# :2283 on all interfaces but closed on the LAN (no firewall rule):
|
||||
# reachable over tailscale0 and via localhost (caddy).
|
||||
extraOptions = runAs ++ [ "--group-add=${toString redisGid}" ];
|
||||
volumes = [
|
||||
# Same path inside as out: the DB stores absolute asset paths.
|
||||
"${mediaLocation}:${mediaLocation}"
|
||||
"/run/postgresql:/run/postgresql"
|
||||
"/run/redis-immich:/run/redis-immich"
|
||||
"${config.sops.templates."immich-config.json".path}:/run/immich/config.json:ro"
|
||||
"/etc/localtime:/etc/localtime:ro"
|
||||
];
|
||||
environment = {
|
||||
DB_URL = "postgresql:///immich?host=/run/postgresql";
|
||||
REDIS_SOCKET = "/run/redis-immich/redis.sock";
|
||||
IMMICH_HOST = "0.0.0.0";
|
||||
IMMICH_PORT = "2283";
|
||||
IMMICH_MEDIA_LOCATION = mediaLocation;
|
||||
IMMICH_MACHINE_LEARNING_URL = "http://127.0.0.1:3003";
|
||||
IMMICH_CONFIG_FILE = "/run/immich/config.json";
|
||||
};
|
||||
};
|
||||
|
||||
immich-machine-learning = {
|
||||
image = "ghcr.io/immich-app/immich-machine-learning:${version}";
|
||||
extraOptions = runAs;
|
||||
# Models (~1G) are re-downloaded on first use.
|
||||
volumes = [ "${mlCache}:/cache" ];
|
||||
environment = {
|
||||
IMMICH_HOST = "127.0.0.1";
|
||||
IMMICH_PORT = "3003";
|
||||
MACHINE_LEARNING_CACHE_FOLDER = "/cache";
|
||||
XDG_CACHE_HOME = "/cache";
|
||||
MPLCONFIGDIR = "/cache/matplotlib";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
systemd.services.podman-immich-server = {
|
||||
requires = [ "postgresql.target" "redis-immich.service" ];
|
||||
after = [ "postgresql.target" "redis-immich.service" ];
|
||||
# Without this, immich starts before /mnt/data mounts and writes uploads onto
|
||||
# the 29G eMMC, invisibly, under the future mountpoint.
|
||||
unitConfig.RequiresMountsFor = [ "/mnt/data" ];
|
||||
};
|
||||
systemd.services.podman-immich-machine-learning.unitConfig.RequiresMountsFor = [ "/mnt/data" ];
|
||||
|
||||
# mediaLocation is outside /var/lib, so the module won't create it — this rule
|
||||
# only adjusts perms on the dir the legacy import already created.
|
||||
systemd.tmpfiles.rules = [
|
||||
"d /mnt/data/AppData/immich 0700 immich immich -"
|
||||
"d ${mediaLocation} 0700 immich immich -"
|
||||
"d ${mlCache} 0700 immich immich -"
|
||||
];
|
||||
|
||||
# The unit's automatic RequiresMountsFor doesn't cover mediaLocation — without
|
||||
# this, immich starts before /mnt/data mounts and writes uploads onto the 29G
|
||||
# eMMC, invisibly, under the future mountpoint.
|
||||
systemd.services.immich-server.unitConfig.RequiresMountsFor = [ "/mnt/data" ];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user