1
1
Fork 1
mirror of https://github.com/oddlama/nix-config.git synced 2025-10-10 23:00:39 +02:00

feat: reenable immich with native module, prepare nixos-extra-modules update

This commit is contained in:
oddlama 2025-09-13 20:18:54 +02:00
parent ef2f2a9b77
commit 157c303f38
No known key found for this signature in database
GPG key ID: 14EFE510775FE39A
25 changed files with 1521 additions and 184 deletions

View file

@ -14,7 +14,7 @@
inputs.idmail.nixosModules.default inputs.idmail.nixosModules.default
inputs.impermanence.nixosModules.impermanence inputs.impermanence.nixosModules.impermanence
inputs.nix-topology.nixosModules.default inputs.nix-topology.nixosModules.default
inputs.nixos-extra-modules.nixosModules.default (inputs.nixos-extra-modules + "/modules")
inputs.nixos-nftables-firewall.nixosModules.default inputs.nixos-nftables-firewall.nixosModules.default
../modules ../modules

811
flake.lock generated

File diff suppressed because it is too large Load diff

View file

@ -104,14 +104,15 @@
inputs: inputs:
inputs.flake-parts.lib.mkFlake { inherit inputs; } { inputs.flake-parts.lib.mkFlake { inherit inputs; } {
imports = [ imports = [
./nix/agenix-rekey.nix ./flake/agenix-rekey.nix
./nix/devshell.nix ./flake/devshell.nix
./nix/globals.nix ./flake/globals.nix
./nix/hosts.nix ./flake/hosts.nix
./nix/iso.nix ./flake/iso.nix
./nix/pkgs.nix ./flake/pkgs.nix
./nix/storage-box.nix ./flake/storage-box.nix
./topology/flake-module.nix ./topology/flake-module.nix
(inputs.nixos-extra-modules + "/flake-modules/globals.nix")
]; ];
systems = [ systems = [

View file

@ -81,7 +81,7 @@
name = "NIX_CONFIG"; name = "NIX_CONFIG";
value = '' value = ''
plugin-files = ${pkgs.nix-plugins}/lib/nix/plugins plugin-files = ${pkgs.nix-plugins}/lib/nix/plugins
extra-builtins-file = ${./..}/nix/extra-builtins.nix extra-builtins-file = ${./..}/flake/extra-builtins.nix
''; '';
} }
]; ];

22
flake/globals.nix Normal file
View file

@ -0,0 +1,22 @@
{
globals = {
optModules = [
../modules/globals.nix
];
defModules = [
../globals.nix
];
attrkeys = [
"domains"
"hetzner"
"kanidm"
"macs"
"mail"
"monitoring"
"myuser"
"net"
"root"
"services"
];
};
}

View file

@ -42,7 +42,13 @@
"usb_storage" "usb_storage"
"sd_mod" "sd_mod"
]; ];
boot.binfmt.emulatedSystems = [ "aarch64-linux" ]; boot.binfmt.emulatedSystems = [
"aarch64-linux"
"i686-linux"
"x86_64-windows"
"riscv32-linux"
"riscv64-linux"
];
} }
// lib.optionalAttrs (!minimal) { // lib.optionalAttrs (!minimal) {
# TODO goodbye once -sk keys. # TODO goodbye once -sk keys.

View file

@ -19,7 +19,7 @@ let
"photos.${globals.domains.me}" "photos.${globals.domains.me}"
"s3.photos.${globals.domains.me}" "s3.photos.${globals.domains.me}"
globals.services.mealie.domain globals.services.mealie.domain
# globals.services.immich.domain globals.services.immich.domain
globals.services.influxdb.domain globals.services.influxdb.domain
globals.services.loki.domain globals.services.loki.domain
globals.services.paperless.domain globals.services.paperless.domain

View file

@ -145,9 +145,9 @@
// mkMicrovm "paperless" { // mkMicrovm "paperless" {
enablePaperlessDataset = true; enablePaperlessDataset = true;
} }
# // mkMicrovm "immich" { // mkMicrovm "immich" {
# enableStorageDataset = true; enableStorageDataset = true;
# } }
// mkMicrovm "ai" { } // mkMicrovm "ai" { }
// mkMicrovm "minecraft" { } // mkMicrovm "minecraft" { }
// mkMicrovm "ente" { // mkMicrovm "ente" {

View file

@ -0,0 +1,288 @@
{
config,
globals,
lib,
nodes,
...
}:
let
immichDomain = "immich.${globals.domains.me}";
in
{
microvm.mem = 1024 * 12;
microvm.vcpu = 16;
# Mirror the original oauth2 secret
age.secrets.immich-oauth2-client-secret = {
inherit (nodes.ward-kanidm.config.age.secrets.kanidm-oauth2-immich) rekeyFile;
mode = "440";
group = "immich";
};
wireguard.proxy-sentinel = {
client.via = "sentinel";
firewallRuleForNode.sentinel.allowedTCPPorts = [ 2283 ];
};
wireguard.proxy-home = {
client.via = "ward";
firewallRuleForNode.ward-web-proxy.allowedTCPPorts = [ 2283 ];
};
globals.services.immich.domain = immichDomain;
globals.monitoring.http.immich = {
url = "https://${immichDomain}";
expectedBodyRegex = "immutable.entry.app";
network = "internet";
};
environment.persistence."/persist".directories = [
{
directory = "/var/cache/immich";
user = "immich";
group = "immich";
mode = "0750";
}
];
environment.persistence."/storage".directories = [
{
directory = "/var/lib/immich";
user = "immich";
group = "immich";
mode = "0750";
}
];
services.immich = {
enable = true;
# We use VectorChord from the beginning
database.enableVectors = false;
environment = {
IMMICH_LOG_LEVEL = "verbose";
IMMICH_TRUSTED_PROXIES = lib.concatStringsSep "," [
];
};
settings = {
backup.database = {
cronExpression = "0 02 * * *";
enabled = true;
keepLastAmount = 14;
};
ffmpeg = {
accel = "disabled";
accelDecode = false;
acceptedAudioCodecs = [
"aac"
"mp3"
"libopus"
"pcm_s16le"
];
acceptedContainers = [
"mov"
"ogg"
"webm"
];
acceptedVideoCodecs = [ "h264" ];
bframes = -1;
cqMode = "auto";
crf = 23;
gopSize = 0;
maxBitrate = "0";
preferredHwDevice = "auto";
preset = "ultrafast";
refs = 0;
targetAudioCodec = "aac";
targetResolution = "720";
targetVideoCodec = "h264";
temporalAQ = false;
threads = 0;
tonemap = "hable";
transcode = "required";
twoPass = false;
};
image = {
colorspace = "p3";
extractEmbedded = false;
preview = {
format = "jpeg";
quality = 80;
size = 1440;
};
thumbnail = {
format = "webp";
quality = 80;
size = 250;
};
};
job = {
backgroundTask.concurrency = 5;
faceDetection.concurrency = 2;
library.concurrency = 5;
metadataExtraction.concurrency = 5;
migration.concurrency = 5;
notifications.concurrency = 5;
search.concurrency = 5;
sidecar.concurrency = 5;
smartSearch.concurrency = 2;
thumbnailGeneration.concurrency = 3;
videoConversion.concurrency = 1;
};
library = {
scan = {
cronExpression = "0 0 * * *";
enabled = true;
};
watch.enabled = false;
};
logging = {
enabled = true;
level = "log";
};
machineLearning = {
clip = {
enabled = true;
modelName = "ViT-B-32__openai";
};
duplicateDetection = {
enabled = true;
maxDistance = 0.01;
};
enabled = true;
facialRecognition = {
enabled = true;
maxDistance = 0.5;
minFaces = 2;
minScore = 0.65;
modelName = "buffalo_l";
};
urls = [ "http://localhost:3003" ];
};
map = {
darkStyle = "https://tiles.immich.cloud/v1/style/dark.json";
enabled = true;
lightStyle = "https://tiles.immich.cloud/v1/style/light.json";
};
metadata.faces.import = false;
newVersionCheck.enabled = true;
notifications = {
smtp = {
enabled = false;
from = "";
replyTo = "";
transport = {
host = "";
ignoreCert = false;
password = "";
port = 587;
username = "";
};
};
};
oauth = rec {
autoLaunch = false;
autoRegister = true;
buttonText = "Login with Kanidm";
clientId = "immich";
clientSecret._secret = config.age.secrets.immich-oauth2-client-secret.path;
defaultStorageQuota = null;
enabled = true;
issuerUrl = "https://${globals.services.kanidm.domain}/oauth2/openid/${clientId}";
mobileOverrideEnabled = true;
mobileRedirectUri = "https://${immichDomain}/api/oauth/mobile-redirect";
profileSigningAlgorithm = "none";
scope = "openid email profile";
signingAlgorithm = "ES256";
storageLabelClaim = "preferred_username";
storageQuotaClaim = "immich_quota";
};
passwordLogin.enabled = true;
reverseGeocoding.enabled = true;
server = {
externalDomain = "https://${immichDomain}";
loginPageMessage = "Besser im Stuhl einschlafen als im Schlaf einstuhlen.";
};
storageTemplate = {
enabled = true;
hashVerificationEnabled = true;
template = "{{y}}/{{y}}-{{MM}}-{{dd}}/{{filename}}";
};
theme.customCss = "";
trash = {
days = 30;
enabled = true;
};
user.deleteDelay = 7;
};
};
nodes.sentinel = {
services.nginx = {
upstreams.immich = {
servers."${config.wireguard.proxy-sentinel.ipv4}:2283" = { };
extraConfig = ''
zone immich 64k;
keepalive 2;
'';
monitoring = {
enable = true;
expectedBodyRegex = "immutable.entry.app";
};
};
virtualHosts.${immichDomain} = {
forceSSL = true;
useACMEWildcardHost = true;
locations."/" = {
proxyPass = "http://immich";
proxyWebsockets = true;
};
extraConfig = ''
client_max_body_size 50G;
proxy_buffering off;
proxy_request_buffering off;
proxy_read_timeout 600s;
proxy_send_timeout 600s;
send_timeout 600s;
'';
};
};
};
nodes.ward-web-proxy = {
services.nginx = {
upstreams.immich = {
servers."${config.wireguard.proxy-home.ipv4}:2283" = { };
extraConfig = ''
zone immich 64k;
keepalive 2;
'';
monitoring = {
enable = true;
expectedBodyRegex = "immutable.entry.app";
};
};
virtualHosts.${immichDomain} = {
forceSSL = true;
useACMEWildcardHost = true;
locations."/" = {
proxyPass = "http://immich";
proxyWebsockets = true;
extraConfig = '''';
};
extraConfig = ''
client_max_body_size 50G;
proxy_buffering off;
proxy_request_buffering off;
proxy_read_timeout 600s;
proxy_send_timeout 600s;
send_timeout 600s;
allow ${globals.net.home-lan.vlans.home.cidrv4};
allow ${globals.net.home-lan.vlans.home.cidrv6};
# Firezone traffic
allow ${globals.net.home-lan.vlans.services.hosts.ward.ipv4};
allow ${globals.net.home-lan.vlans.services.hosts.ward.ipv6};
deny all;
'';
};
};
};
}

View file

@ -0,0 +1 @@
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIKE+geXK2RVVNwZVoYOuX7pW+6mbgCa9SIghJCdHmbSB

View file

@ -21,7 +21,7 @@ let
"photos.${globals.domains.me}" "photos.${globals.domains.me}"
"s3.photos.${globals.domains.me}" "s3.photos.${globals.domains.me}"
globals.services.mealie.domain globals.services.mealie.domain
# globals.services.immich.domain globals.services.immich.domain
globals.services.influxdb.domain globals.services.influxdb.domain
globals.services.loki.domain globals.services.loki.domain
globals.services.paperless.domain globals.services.paperless.domain

View file

@ -118,7 +118,7 @@ in
"photos.${globals.domains.me}" "photos.${globals.domains.me}"
"s3.photos.${globals.domains.me}" "s3.photos.${globals.domains.me}"
globals.services.mealie.domain globals.services.mealie.domain
# globals.services.immich.domain globals.services.immich.domain
globals.services.influxdb.domain globals.services.influxdb.domain
globals.services.loki.domain globals.services.loki.domain
globals.services.paperless.domain globals.services.paperless.domain

View file

@ -37,7 +37,7 @@ in
age.secrets.kanidm-oauth2-forgejo = mkRandomSecret; age.secrets.kanidm-oauth2-forgejo = mkRandomSecret;
age.secrets.kanidm-oauth2-grafana = mkRandomSecret; age.secrets.kanidm-oauth2-grafana = mkRandomSecret;
# age.secrets.kanidm-oauth2-immich = mkRandomSecret; age.secrets.kanidm-oauth2-immich = mkRandomSecret;
age.secrets.kanidm-oauth2-firezone = mkRandomSecret; age.secrets.kanidm-oauth2-firezone = mkRandomSecret;
age.secrets.kanidm-oauth2-mealie = mkRandomSecret; age.secrets.kanidm-oauth2-mealie = mkRandomSecret;
age.secrets.kanidm-oauth2-paperless = mkRandomSecret; age.secrets.kanidm-oauth2-paperless = mkRandomSecret;
@ -115,27 +115,23 @@ in
inherit (globals.kanidm) persons; inherit (globals.kanidm) persons;
# # Immich # Immich
# groups."immich.access" = { }; groups."immich.access" = { };
# systems.oauth2.immich = { systems.oauth2.immich = {
# displayName = "Immich"; displayName = "Immich";
# originUrl = [ originUrl = [
# "https://${globals.services.immich.domain}/auth/login" "https://${globals.services.immich.domain}/auth/login"
# "https://${globals.services.immich.domain}/api/oauth/mobile-redirect" "https://${globals.services.immich.domain}/api/oauth/mobile-redirect"
# ]; ];
# originLanding = "https://${globals.services.immich.domain}/"; originLanding = "https://${globals.services.immich.domain}/";
# basicSecretFile = config.age.secrets.kanidm-oauth2-immich.path; basicSecretFile = config.age.secrets.kanidm-oauth2-immich.path;
# preferShortUsername = true; preferShortUsername = true;
# # XXX: PKCE is currently not supported by immich scopeMaps."immich.access" = [
# allowInsecureClientDisablePkce = true; "openid"
# # XXX: RS256 is used instead of ES256 so additionally we need legacy crypto "email"
# enableLegacyCrypto = true; "profile"
# scopeMaps."immich.access" = [ ];
# "openid" };
# "email"
# "profile"
# ];
# };
# Firezone # Firezone
groups."firezone.access" = { }; groups."firezone.access" = { };

View file

@ -1,6 +1,7 @@
{ {
disabledModules = [ disabledModules = [
"services/web-apps/mealie.nix" "services/web-apps/mealie.nix"
"services/web-apps/immich.nix"
]; ];
imports = [ imports = [
./acme-wildcard.nix ./acme-wildcard.nix
@ -10,6 +11,7 @@
./ente.nix ./ente.nix
./globals.nix ./globals.nix
./mealie.nix ./mealie.nix
./immich.nix
./meta.nix ./meta.nix
./nginx-upstream-monitoring.nix ./nginx-upstream-monitoring.nix
./oauth2-proxy.nix ./oauth2-proxy.nix

View file

@ -88,7 +88,7 @@ let
in in
{ {
options.nodes = mkOption { options.nodes = mkOption {
description = "Options forwareded to the given node."; description = "Options forwarded to the given node.";
default = { }; default = { };
type = types.attrsOf ( type = types.attrsOf (
types.submodule { types.submodule {

445
modules/immich.nix Normal file
View file

@ -0,0 +1,445 @@
{
config,
lib,
pkgs,
utils,
...
}:
let
cfg = config.services.immich;
format = pkgs.formats.json { };
isPostgresUnixSocket = lib.hasPrefix "/" cfg.database.host;
isRedisUnixSocket = lib.hasPrefix "/" cfg.redis.host;
commonServiceConfig = {
Type = "simple";
Restart = "on-failure";
RestartSec = 3;
# Hardening
CapabilityBoundingSet = "";
NoNewPrivileges = true;
PrivateUsers = true;
PrivateTmp = true;
PrivateDevices = cfg.accelerationDevices == [ ];
DeviceAllow = mkIf (cfg.accelerationDevices != null) cfg.accelerationDevices;
PrivateMounts = true;
ProtectClock = true;
ProtectControlGroups = true;
ProtectHome = true;
ProtectHostname = true;
ProtectKernelLogs = true;
ProtectKernelModules = true;
ProtectKernelTunables = true;
RestrictAddressFamilies = [
"AF_INET"
"AF_INET6"
"AF_UNIX"
];
RestrictNamespaces = true;
RestrictRealtime = true;
RestrictSUIDSGID = true;
UMask = "0077";
};
inherit (lib)
types
mkIf
mkOption
mkEnableOption
;
postgresqlPackage =
if cfg.database.enable then config.services.postgresql.package else pkgs.postgresql;
in
{
options.services.immich = {
enable = mkEnableOption "Immich";
package = lib.mkPackageOption pkgs "immich" { };
mediaLocation = mkOption {
type = types.path;
default = "/var/lib/immich";
description = "Directory used to store media files. If it is not the default, the directory has to be created manually such that the immich user is able to read and write to it.";
};
environment = mkOption {
type = types.submodule { freeformType = types.attrsOf types.str; };
default = { };
example = {
IMMICH_LOG_LEVEL = "verbose";
};
description = ''
Extra configuration environment variables. Refer to the [documentation](https://immich.app/docs/install/environment-variables) for options tagged with 'server', 'api' or 'microservices'.
'';
};
secretsFile = mkOption {
type = types.nullOr (
types.str
// {
# We don't want users to be able to pass a path literal here but
# it should look like a path.
check = it: lib.isString it && lib.types.path.check it;
}
);
default = null;
example = "/run/secrets/immich";
description = ''
Path of a file with extra environment variables to be loaded from disk. This file is not added to the nix store, so it can be used to pass secrets to immich. Refer to the [documentation](https://immich.app/docs/install/environment-variables) for options.
To set a database password set this to a file containing:
```
DB_PASSWORD=<pass>
```
'';
};
host = mkOption {
type = types.str;
default = "localhost";
description = "The host that immich will listen on.";
};
port = mkOption {
type = types.port;
default = 2283;
description = "The port that immich will listen on.";
};
openFirewall = mkOption {
type = types.bool;
default = false;
description = "Whether to open the immich port in the firewall";
};
user = mkOption {
type = types.str;
default = "immich";
description = "The user immich should run as.";
};
group = mkOption {
type = types.str;
default = "immich";
description = "The group immich should run as.";
};
settings = mkOption {
default = null;
description = ''
Configuration for Immich.
See <https://immich.app/docs/install/config-file/> or navigate to
<https://my.immich.app/admin/system-settings> for
options and defaults.
Setting it to `null` allows configuring Immich in the web interface.
'';
type = types.nullOr (
types.submodule {
freeformType = format.type;
options = {
newVersionCheck.enabled = mkOption {
type = types.bool;
default = false;
description = ''
Check for new versions.
This feature relies on periodic communication with github.com.
'';
};
server.externalDomain = mkOption {
type = types.str;
default = "";
description = "Domain for publicly shared links, including `http(s)://`.";
};
};
}
);
};
machine-learning = {
enable =
mkEnableOption "immich's machine-learning functionality to detect faces and search for objects"
// {
default = true;
};
environment = mkOption {
type = types.submodule { freeformType = types.attrsOf types.str; };
default = { };
example = {
MACHINE_LEARNING_MODEL_TTL = "600";
};
description = ''
Extra configuration environment variables. Refer to the [documentation](https://immich.app/docs/install/environment-variables) for options tagged with 'machine-learning'.
'';
};
};
accelerationDevices = mkOption {
type = types.nullOr (types.listOf types.str);
default = [ ];
example = [ "/dev/dri/renderD128" ];
description = ''
A list of device paths to hardware acceleration devices that immich should
have access to. This is useful when transcoding media files.
The special value `[ ]` will disallow all devices using `PrivateDevices`. `null` will give access to all devices.
'';
};
database = {
enable =
mkEnableOption "the postgresql database for use with immich. See {option}`services.postgresql`"
// {
default = true;
};
enableVectorChord =
mkEnableOption "the new VectorChord extension for full-text search in Postgres"
// {
default = true;
};
enableVectors =
mkEnableOption "pgvecto.rs in the database. You may disable this, if you have migrated to VectorChord and deleted the `vectors` schema."
// {
default = lib.versionOlder config.system.stateVersion "25.11";
defaultText = lib.literalExpression "lib.versionOlder config.system.stateVersion \"25.11\"";
};
createDB = mkEnableOption "the automatic creation of the database for immich." // {
default = true;
};
name = mkOption {
type = types.str;
default = "immich";
description = "The name of the immich database.";
};
host = mkOption {
type = types.str;
default = "/run/postgresql";
example = "127.0.0.1";
description = "Hostname or address of the postgresql server. If an absolute path is given here, it will be interpreted as a unix socket path.";
};
port = mkOption {
type = types.port;
default = 5432;
description = "Port of the postgresql server.";
};
user = mkOption {
type = types.str;
default = "immich";
description = "The database user for immich.";
};
};
redis = {
enable = mkEnableOption "a redis cache for use with immich" // {
default = true;
};
host = mkOption {
type = types.str;
default = config.services.redis.servers.immich.unixSocket;
defaultText = lib.literalExpression "config.services.redis.servers.immich.unixSocket";
description = "The host that redis will listen on.";
};
port = mkOption {
type = types.port;
default = 0;
description = "The port that redis will listen on. Set to zero to disable TCP.";
};
};
};
config = mkIf cfg.enable {
assertions = [
{
assertion = !isPostgresUnixSocket -> cfg.secretsFile != null;
message = "A secrets file containing at least the database password must be provided when unix sockets are not used.";
}
{
# When removing this assertion, please adjust the nixosTests accordingly.
assertion =
(cfg.database.enable && cfg.database.enableVectors)
-> lib.versionOlder config.services.postgresql.package.version "17";
message = "Immich doesn't support PostgreSQL 17+ when using pgvecto.rs. Consider disabling it using services.immich.database.enableVectors if it is not needed anymore.";
}
{
assertion = cfg.database.enable -> (cfg.database.enableVectorChord || cfg.database.enableVectors);
message = "At least one of services.immich.database.enableVectorChord and services.immich.database.enableVectors has to be enabled.";
}
];
services.postgresql = mkIf cfg.database.enable {
enable = true;
ensureDatabases = mkIf cfg.database.createDB [ cfg.database.name ];
ensureUsers = mkIf cfg.database.createDB [
{
name = cfg.database.user;
ensureDBOwnership = true;
ensureClauses.login = true;
}
];
extensions =
ps:
lib.optionals cfg.database.enableVectors [ ps.pgvecto-rs ]
++ lib.optionals cfg.database.enableVectorChord [
ps.pgvector
ps.vectorchord
];
settings = {
shared_preload_libraries =
lib.optionals cfg.database.enableVectors [
"vectors.so"
]
++ lib.optionals cfg.database.enableVectorChord [ "vchord.so" ];
search_path = "\"$user\", public, vectors";
};
};
systemd.services.postgresql-setup.serviceConfig.ExecStartPost =
let
extensions = [
"unaccent"
"uuid-ossp"
"cube"
"earthdistance"
"pg_trgm"
]
++ lib.optionals cfg.database.enableVectors [
"vectors"
]
++ lib.optionals cfg.database.enableVectorChord [
"vector"
"vchord"
];
sqlFile = pkgs.writeText "immich-pgvectors-setup.sql" ''
${lib.concatMapStringsSep "\n" (ext: "CREATE EXTENSION IF NOT EXISTS \"${ext}\";") extensions}
ALTER SCHEMA public OWNER TO ${cfg.database.user};
${lib.optionalString cfg.database.enableVectors "ALTER SCHEMA vectors OWNER TO ${cfg.database.user};"}
GRANT SELECT ON TABLE pg_vector_index_stat TO ${cfg.database.user};
${lib.concatMapStringsSep "\n" (ext: "ALTER EXTENSION \"${ext}\" UPDATE;") extensions}
'';
in
[
''
${lib.getExe' postgresqlPackage "psql"} -d "${cfg.database.name}" -f "${sqlFile}"
''
];
services.redis.servers = mkIf cfg.redis.enable {
immich = {
enable = true;
inherit (cfg.redis) port;
bind = mkIf (!isRedisUnixSocket) cfg.redis.host;
};
};
networking.firewall.allowedTCPPorts = mkIf cfg.openFirewall [ cfg.port ];
services.immich.environment =
let
postgresEnv =
if isPostgresUnixSocket then
{ DB_URL = "postgresql:///${cfg.database.name}?host=${cfg.database.host}"; }
else
{
DB_HOSTNAME = cfg.database.host;
DB_PORT = toString cfg.database.port;
DB_DATABASE_NAME = cfg.database.name;
DB_USERNAME = cfg.database.user;
};
redisEnv =
if isRedisUnixSocket then
{ REDIS_SOCKET = cfg.redis.host; }
else
{
REDIS_PORT = toString cfg.redis.port;
REDIS_HOSTNAME = cfg.redis.host;
};
in
postgresEnv
// redisEnv
// {
IMMICH_HOST = cfg.host;
IMMICH_PORT = toString cfg.port;
IMMICH_MEDIA_LOCATION = cfg.mediaLocation;
IMMICH_MACHINE_LEARNING_URL = "http://localhost:3003";
}
// lib.optionalAttrs (cfg.settings != null) {
IMMICH_CONFIG_FILE = "/run/immich/config.json";
};
services.immich.machine-learning.environment = {
MACHINE_LEARNING_WORKERS = "1";
MACHINE_LEARNING_WORKER_TIMEOUT = "120";
MACHINE_LEARNING_CACHE_FOLDER = "/var/cache/immich";
IMMICH_HOST = "localhost";
IMMICH_PORT = "3003";
};
systemd.slices.system-immich = {
description = "Immich (self-hosted photo and video backup solution) slice";
documentation = [ "https://immich.app/docs" ];
};
systemd.services.immich-server = {
description = "Immich backend server (Self-hosted photo and video backup solution)";
requires = lib.mkIf cfg.database.enable [ "postgresql.target" ];
after = [ "network.target" ] ++ lib.optionals cfg.database.enable [ "postgresql.target" ];
wantedBy = [ "multi-user.target" ];
inherit (cfg) environment;
path = [
# gzip and pg_dumpall are used by the backup service
pkgs.gzip
postgresqlPackage
];
preStart = ''
# Splice secrets into json configuration
${utils.genJqSecretsReplacementSnippet cfg.settings "/run/immich/config.json"}
'';
serviceConfig = commonServiceConfig // {
ExecStart = lib.getExe cfg.package;
EnvironmentFile = mkIf (cfg.secretsFile != null) cfg.secretsFile;
Slice = "system-immich.slice";
StateDirectory = "immich";
SyslogIdentifier = "immich";
RuntimeDirectory = "immich";
User = cfg.user;
Group = cfg.group;
# ensure that immich-server has permission to connect to the redis socket.
SupplementaryGroups = mkIf (cfg.redis.enable && isRedisUnixSocket) [
config.services.redis.servers.immich.group
];
};
};
systemd.services.immich-machine-learning = mkIf cfg.machine-learning.enable {
description = "immich machine learning";
requires = lib.mkIf cfg.database.enable [ "postgresql.target" ];
after = [ "network.target" ] ++ lib.optionals cfg.database.enable [ "postgresql.target" ];
wantedBy = [ "multi-user.target" ];
inherit (cfg.machine-learning) environment;
serviceConfig = commonServiceConfig // {
ExecStart = lib.getExe (cfg.package.machine-learning.override { immich = cfg.package; });
Slice = "system-immich.slice";
CacheDirectory = "immich";
User = cfg.user;
Group = cfg.group;
};
};
systemd.tmpfiles.settings = {
immich = {
# Redundant to the `UMask` service config setting on new installs, but installs made in
# early 24.11 created world-readable media storage by default, which is a privacy risk. This
# fixes those installs.
"${cfg.mediaLocation}" = {
e = {
inherit (cfg) user;
inherit (cfg) group;
mode = "0700";
};
};
};
};
users.users = mkIf (cfg.user == "immich") {
immich = {
name = "immich";
inherit (cfg) group;
isSystemUser = true;
};
};
users.groups = mkIf (cfg.group == "immich") { immich = { }; };
};
}

View file

@ -1,55 +0,0 @@
{ inputs, ... }:
{
flake =
{
config,
lib,
...
}:
{
globals =
let
globalsSystem = lib.evalModules {
prefix = [ "globals" ];
specialArgs = {
inherit (inputs.self.pkgs.x86_64-linux) lib;
inherit inputs;
inherit (config) nodes;
};
modules = [
../modules/globals.nix
../globals.nix
(
{ lib, ... }:
{
globals = lib.mkMerge (
lib.concatLists (
lib.flip lib.mapAttrsToList config.nodes (
name: cfg:
builtins.addErrorContext "while aggregating globals from nixosConfigurations.${name} into flake-level globals:" cfg.config._globalsDefs
)
)
);
}
)
];
};
in
{
# Make sure the keys of this attrset are trivially evaluatable to avoid infinite recursion,
# therefore we inherit relevant attributes from the config.
inherit (globalsSystem.config.globals)
domains
hetzner
kanidm
macs
mail
monitoring
myuser
net
root
services
;
};
};
}