Immich Service

Defined in /modules/services/immich.nix.

This NixOS module is a service that sets up an Immich instance.

Compared to the stock module from nixpkgs, this one adds:

Features

Usage

Initial Configuration

The following snippet assumes a few blocks have been setup already:

shb.immich = {
  enable = true;
  subdomain = "immich";
  domain = "example.com";

  initialAdmin = {
    email = "admin@example.com";
    name = "Admin";
    password.result = config.shb.sops.secret."immich/adminPassword".result;
  };
};

shb.sops.secret."immich/adminPassword".request = config.shb.immich.admin.password.request;

Secrets can be randomly generated with nix run nixpkgs#openssl -- rand -hex 64.

Certificates

For Let’s Encrypt certificates with the shb.ssl block, add:

{
  shb.certs.certs.letsencrypt."example.com" = {
    domain = "example.com";

    group = "nginx";
    reloadServices = [ "nginx.service" ];

    adminEmail = "shb@example.com";
  };

  shb.certs.certs.letsencrypt."example.com".extraDomains = [
    "${config.shb.immich.subdomain}.${config.shb.immich.domain}"
  ];

  shb.immich.ssl = config.shb.certs.certs.letsencrypt."example.com";
}

Backup

Backing up Immich using the Restic block is done like so:

shb.restic.instances."immich" = {
  request = config.shb.immich.backup;
  settings = {
    enable = true;
  };
};

The name "immich" in the instances can be anything. The config.shb.immich.backup option provides what directories to backup. You can define any number of Restic instances to backup Immich multiple times.

You will then need to configure more options like the repository, as explained in the restic documentation.

Impermanence

To save the data folder in an impermanence setup, add:

{
  shb.zfs.datasets."safe/immich" = {
    path = config.shb.immich.mediaLocation;
    owner = "immich";
    group = "immich";
  };
}

Application Dashboard

Integration with the dashboard contract is provided by the dashboard option.

For example using the Homepage service:

{
  shb.homepage.servicesGroups.Media.services.Immich = {
    sortOrder = 1;
    dashboard.request = config.shb.immich.dashboard.request;
  };
}

An API key with server.statistics permissions can be set to show extra info:

{
  shb.homepage.servicesGroups.Media.services.Immich = {
    apiKey.result = config.shb.sops.secret."immich/homepageApiKey".result;
  };

  shb.sops.secret."immich/homepageApiKey".request =
    config.shb.homepage.servicesGroups.Media.services.Immich.apiKey.request;
}

Debug

In case of an issue, check the logs for systemd service immich-server.service.

Enable verbose logging by setting the shb.immich.debug boolean to true.

Options Reference

shb.immich.enable

Whether to enable selfhostblocks.immich.

Type: boolean

Default:

false

Example:

true

Declared by:

<selfhostblocks/modules/services/immich.nix>
shb.immich.accelerationDevices

Hardware acceleration devices for Immich. Set to null to allow access to all devices. Set to empty list to disable hardware acceleration.

Type: null or (list of absolute path)

Default:

null

Example:

[
  "/dev/dri"
]

Declared by:

<selfhostblocks/modules/services/immich.nix>
shb.immich.backup

Backup configuration for Immich media files and database.

Type: submodule

Default:

{ }

Declared by:

<selfhostblocks/modules/services/immich.nix>
shb.immich.backup.request

Request part of the backup contract.

Options set by the requester module enforcing how to backup files.

Type: submodule

Default:

""

Declared by:

<selfhostblocks/modules/services/immich.nix>
shb.immich.backup.request.excludePatterns

File patterns to exclude.

Type: list of string

Default:

[
  "*.tmp"
  "cache/*"
  "encoded-video/*"
]

Declared by:

<selfhostblocks/modules/services/immich.nix>
shb.immich.backup.request.hooks

Hooks to run around the backup.

Type: submodule

Default:

{ }

Declared by:

<selfhostblocks/modules/services/immich.nix>
shb.immich.backup.request.hooks.afterBackup

Hooks to run after backup.

Type: list of string

Default:

[ ]

Declared by:

<selfhostblocks/modules/services/immich.nix>
shb.immich.backup.request.hooks.beforeBackup

Hooks to run before backup.

Type: list of string

Default:

[ ]

Declared by:

<selfhostblocks/modules/services/immich.nix>
shb.immich.backup.request.sourceDirectories

Directories to backup.

Type: non-empty (list of string)

Default:

[
  "/var/lib/immich"
]

Example:

"/var/lib/vaultwarden"

Declared by:

<selfhostblocks/modules/services/immich.nix>
shb.immich.backup.request.user

Unix user doing the backups.

Type: string

Default:

"immich"

Example:

"vaultwarden"

Declared by:

<selfhostblocks/modules/services/immich.nix>
shb.immich.backup.result

Result part of the backup contract.

Options set by the provider module that indicates the name of the backup and restore scripts.

Type: submodule

Default:

""

Declared by:

<selfhostblocks/modules/services/immich.nix>
shb.immich.backup.result.backupService

Name of service backing up the database.

This script can be ran manually to backup the database:

$ systemctl start backup.service

Type: string

Default:

"backup.service"

Declared by:

<selfhostblocks/modules/services/immich.nix>
shb.immich.backup.result.restoreScript

Name of script that can restore the database. One can then list snapshots with:

$ restore snapshots
<snapshot 1> <metadata>
<snapshot 2> <metadata>

And restore the database with:

$ restore restore <snapshot 1>

Type: string

Default:

"restore"

Declared by:

<selfhostblocks/modules/services/immich.nix>
shb.immich.dashboard

Dashboard contract consumer

Type: submodule

Default:

{ }

Declared by:

<selfhostblocks/modules/services/immich.nix>
shb.immich.dashboard.request

Request part of the dashboard contract.

Type: submodule

Default:

{ }

Declared by:

<selfhostblocks/modules/services/immich.nix>
shb.immich.dashboard.request.externalUrl

URL at which the service can be accessed.

This URL should go through the reverse proxy.

Type: string

Default:

"https://\${config.shb.immich.subdomain}.\${config.shb.immich.domain}"

Example:

"https://jellyfin.example.com"

Declared by:

<selfhostblocks/modules/services/immich.nix>
shb.immich.dashboard.request.internalUrl

URL at which the service can be accessed directly.

This URL should bypass the reverse proxy. It can be used for example to ping the service and making sure it is up and running correctly.

Type: null or string

Default:

"http://127.0.0.1:2283"

Example:

"http://127.0.0.1:8081"

Declared by:

<selfhostblocks/modules/services/immich.nix>
shb.immich.dashboard.result

Result part of the dashboard contract.

No option is provided here.

Type: submodule

Default:

{ }

Declared by:

<selfhostblocks/modules/services/immich.nix>
shb.immich.debug

Set to true to enable debug logging.

Type: boolean

Default:

false

Example:

true

Declared by:

<selfhostblocks/modules/services/immich.nix>
shb.immich.domain

Domain under which Immich is served.

<subdomain>.<domain>

Type: string

Example:

"example.com"

Declared by:

<selfhostblocks/modules/services/immich.nix>
shb.immich.initialAdmin

Declaratively create an admin.

If set, this means the admin user will be created when Immich server starts. If the admin already exists, nothing will be done.

This does not skip onboarding unless you set shb.immich.skipOnboarding to true.

Type: null or (submodule)

Default:

null

Declared by:

<selfhostblocks/modules/services/immich.nix>
shb.immich.initialAdmin.email

Initial email of declaratively setup admin.

Subsequent changes in the UI will override this value. Also, changing this value will not update the actual email.

Type: string

Declared by:

<selfhostblocks/modules/services/immich.nix>
shb.immich.initialAdmin.name

Initial name of declaratively setup admin.

Subsequent changes in the UI will override this value. Also, changing this value will not update the actual name.

Type: string

Declared by:

<selfhostblocks/modules/services/immich.nix>
shb.immich.initialAdmin.passwordFile

Initial password of declaratively setup admin.

Subsequent changes in the UI will override this value. Also, changing this value will not update the actual password.

Type: submodule

Declared by:

<selfhostblocks/modules/services/immich.nix>
shb.immich.initialAdmin.passwordFile.request

Request part of the secret contract.

Options set by the requester module enforcing some properties the secret should have.

Type: submodule

Default:

""

Declared by:

<selfhostblocks/modules/services/immich.nix>
shb.immich.initialAdmin.passwordFile.request.group

Linux group owning the secret file.

Type: string

Default:

"root"

Declared by:

<selfhostblocks/modules/services/immich.nix>
shb.immich.initialAdmin.passwordFile.request.mode

Mode of the secret file.

Type: string

Default:

"0400"

Declared by:

<selfhostblocks/modules/services/immich.nix>
shb.immich.initialAdmin.passwordFile.request.owner

Linux user owning the secret file.

Type: string

Default:

"immich"

Declared by:

<selfhostblocks/modules/services/immich.nix>
shb.immich.initialAdmin.passwordFile.request.restartUnits

Systemd units to restart after the secret is updated.

Type: list of string

Default:

[
  "immich-server.service"
]

Declared by:

<selfhostblocks/modules/services/immich.nix>
shb.immich.initialAdmin.passwordFile.result

Result part of the secret contract.

Options set by the provider module that indicates where the secret can be found.

Type: submodule

Default:

{
  path = "/run/secrets/secret";
}

Declared by:

<selfhostblocks/modules/services/immich.nix>
shb.immich.initialAdmin.passwordFile.result.path

Path to the file containing the secret generated out of band.

This path will exist after deploying to a target host, it is not available through the nix store.

Type: absolute path

Default:

"/run/secrets/secret"

Declared by:

<selfhostblocks/modules/services/immich.nix>
shb.immich.jwtSecretFile

File containing Immich’s JWT secret key for sessions. This is required for secure session management.

Type: null or (submodule)

Default:

null

Declared by:

<selfhostblocks/modules/services/immich.nix>
shb.immich.jwtSecretFile.request

Request part of the secret contract.

Options set by the requester module enforcing some properties the secret should have.

Type: submodule

Default:

""

Declared by:

<selfhostblocks/modules/services/immich.nix>
shb.immich.jwtSecretFile.request.group

Linux group owning the secret file.

Type: string

Default:

"root"

Declared by:

<selfhostblocks/modules/services/immich.nix>
shb.immich.jwtSecretFile.request.mode

Mode of the secret file.

Type: string

Default:

"0400"

Declared by:

<selfhostblocks/modules/services/immich.nix>
shb.immich.jwtSecretFile.request.owner

Linux user owning the secret file.

Type: string

Default:

"immich"

Declared by:

<selfhostblocks/modules/services/immich.nix>
shb.immich.jwtSecretFile.request.restartUnits

Systemd units to restart after the secret is updated.

Type: list of string

Default:

[
  "immich-server.service"
]

Declared by:

<selfhostblocks/modules/services/immich.nix>
shb.immich.jwtSecretFile.result

Result part of the secret contract.

Options set by the provider module that indicates where the secret can be found.

Type: submodule

Default:

{
  path = "/run/secrets/secret";
}

Declared by:

<selfhostblocks/modules/services/immich.nix>
shb.immich.jwtSecretFile.result.path

Path to the file containing the secret generated out of band.

This path will exist after deploying to a target host, it is not available through the nix store.

Type: absolute path

Default:

"/run/secrets/secret"

Declared by:

<selfhostblocks/modules/services/immich.nix>
shb.immich.machineLearning

Machine learning configuration.

Type: submodule

Default:

{ }

Declared by:

<selfhostblocks/modules/services/immich.nix>
shb.immich.machineLearning.enable

Enable machine learning features.

Type: boolean

Default:

true

Declared by:

<selfhostblocks/modules/services/immich.nix>
shb.immich.machineLearning.environment

Extra environment variables for machine learning service.

Type: attribute set of string

Default:

{ }

Example:

{
  MACHINE_LEARNING_WORKERS = "2";
  MACHINE_LEARNING_WORKER_TIMEOUT = "180";
}

Declared by:

<selfhostblocks/modules/services/immich.nix>
shb.immich.mediaLocation

Directory where Immich will store media files.

Type: string

Default:

"/var/lib/immich"

Declared by:

<selfhostblocks/modules/services/immich.nix>
shb.immich.newVersionCheck

Set to true to allow Immich to phone home so it can check if a new version is available.

In the spirit of not sending any telemetry by default, this option is set to false by default.

Type: boolean

Default:

false

Declared by:

<selfhostblocks/modules/services/immich.nix>
shb.immich.port

Port under which Immich will listen.

Type: 16 bit unsigned integer; between 0 and 65535 (both inclusive)

Default:

2283

Declared by:

<selfhostblocks/modules/services/immich.nix>
shb.immich.publicProxyEnable

Enable Immich Public Proxy service for sharing media publically.

Type: boolean

Default:

false

Declared by:

<selfhostblocks/modules/services/immich.nix>
shb.immich.publicProxyPort

Port under which Immich Public Proxy will listen.

Type: 16 bit unsigned integer; between 0 and 65535 (both inclusive)

Default:

2284

Declared by:

<selfhostblocks/modules/services/immich.nix>
shb.immich.settings

Immich configuration settings. Only specify settings that you want SHB to manage declaratively. Other settings can be configured through Immich’s admin UI.

See https://immich.app/docs/install/config-file/ for available options.

Type: attribute set

Default:

{ }

Example:

{
  ffmpeg = {
    crf = 23;
  };
  job = {
    backgroundTask = {
      concurrency = 5;
    };
  };
  storageTemplate = {
    enabled = true;
    template = "{{y}}/{{y}}-{{MM}}-{{dd}}/{{filename}}";
  };
}

Declared by:

<selfhostblocks/modules/services/immich.nix>
shb.immich.skipOnboarding

This allows you to skip onboarding.

If set to true, you are required to fill out the shb.immich.admin options.

Type: boolean

Default:

false

Declared by:

<selfhostblocks/modules/services/immich.nix>
shb.immich.smtp

SMTP configuration for sending notifications.

Type: null or (submodule)

Default:

null

Declared by:

<selfhostblocks/modules/services/immich.nix>
shb.immich.smtp.from

SMTP address from which the emails originate.

Type: string

Example:

"noreply@example.com"

Declared by:

<selfhostblocks/modules/services/immich.nix>
shb.immich.smtp.host

SMTP host to send the emails to.

Type: string

Example:

"smtp.example.com"

Declared by:

<selfhostblocks/modules/services/immich.nix>
shb.immich.smtp.ignoreTLS

Ignore TLS certificate errors.

Type: boolean

Default:

false

Declared by:

<selfhostblocks/modules/services/immich.nix>
shb.immich.smtp.password

File containing the password to connect to the SMTP host.

Type: submodule

Declared by:

<selfhostblocks/modules/services/immich.nix>
shb.immich.smtp.password.request

Request part of the secret contract.

Options set by the requester module enforcing some properties the secret should have.

Type: submodule

Default:

""

Declared by:

<selfhostblocks/modules/services/immich.nix>
shb.immich.smtp.password.request.group

Linux group owning the secret file.

Type: string

Default:

"root"

Declared by:

<selfhostblocks/modules/services/immich.nix>
shb.immich.smtp.password.request.mode

Mode of the secret file.

Type: string

Default:

"0400"

Declared by:

<selfhostblocks/modules/services/immich.nix>
shb.immich.smtp.password.request.owner

Linux user owning the secret file.

Type: string

Default:

"immich"

Declared by:

<selfhostblocks/modules/services/immich.nix>
shb.immich.smtp.password.request.restartUnits

Systemd units to restart after the secret is updated.

Type: list of string

Default:

[
  "immich-server.service"
]

Declared by:

<selfhostblocks/modules/services/immich.nix>
shb.immich.smtp.password.result

Result part of the secret contract.

Options set by the provider module that indicates where the secret can be found.

Type: submodule

Default:

{
  path = "/run/secrets/secret";
}

Declared by:

<selfhostblocks/modules/services/immich.nix>
shb.immich.smtp.password.result.path

Path to the file containing the secret generated out of band.

This path will exist after deploying to a target host, it is not available through the nix store.

Type: absolute path

Default:

"/run/secrets/secret"

Declared by:

<selfhostblocks/modules/services/immich.nix>
shb.immich.smtp.port

SMTP port to send the emails to.

Type: 16 bit unsigned integer; between 0 and 65535 (both inclusive)

Default:

587

Declared by:

<selfhostblocks/modules/services/immich.nix>
shb.immich.smtp.replyTo

Reply-to address for emails.

Type: string

Example:

"support@example.com"

Declared by:

<selfhostblocks/modules/services/immich.nix>
shb.immich.smtp.secure

Use secure connection (SSL/TLS).

Type: boolean

Default:

false

Declared by:

<selfhostblocks/modules/services/immich.nix>
shb.immich.smtp.username

Username to connect to the SMTP host.

Type: string

Example:

"smtp-user"

Declared by:

<selfhostblocks/modules/services/immich.nix>
shb.immich.ssl

Path to SSL files

Type: null or (open submodule of anything)

Default:

null

Declared by:

<selfhostblocks/modules/services/immich.nix>
shb.immich.ssl.paths

Paths where the files for the certificate will be located.

This option is the contract output of the shb.certs.certs SSL block.

Type: open submodule of anything

Declared by:

<selfhostblocks/modules/services/immich.nix>
shb.immich.ssl.paths.cert

Path to the cert file.

Type: absolute path

Declared by:

<selfhostblocks/modules/services/immich.nix>
shb.immich.ssl.paths.key

Path to the key file.

Type: absolute path

Declared by:

<selfhostblocks/modules/services/immich.nix>
shb.immich.ssl.systemdService

Systemd oneshot service used to generate the certificate. Ends with the .service suffix.

Use this if downstream services must wait for the certificates to be generated before starting.

Type: string

Example:

"cert-generator.service"

Declared by:

<selfhostblocks/modules/services/immich.nix>
shb.immich.sso

Setup SSO integration.

Type: submodule

Default:

{ }

Declared by:

<selfhostblocks/modules/services/immich.nix>
shb.immich.sso.enable

Whether to enable SSO integration…

Type: boolean

Default:

false

Example:

true

Declared by:

<selfhostblocks/modules/services/immich.nix>
shb.immich.sso.adminUserGroup

OIDC admin group

Type: string

Default:

"immich_admin"

Declared by:

<selfhostblocks/modules/services/immich.nix>
shb.immich.sso.authorization_policy

Require one factor (password) or two factor (device) authentication.

Type: one of “one_factor”, “two_factor”

Default:

"one_factor"

Declared by:

<selfhostblocks/modules/services/immich.nix>
shb.immich.sso.autoLaunch

Automatically redirect to SSO provider.

Type: boolean

Default:

true

Declared by:

<selfhostblocks/modules/services/immich.nix>
shb.immich.sso.autoRegister

Automatically register new users from SSO provider.

Type: boolean

Default:

true

Declared by:

<selfhostblocks/modules/services/immich.nix>
shb.immich.sso.buttonText

Text to display on the SSO login button.

Type: string

Default:

"Login with SSO"

Declared by:

<selfhostblocks/modules/services/immich.nix>
shb.immich.sso.clientID

Client ID for the OIDC endpoint.

Type: string

Default:

"immich"

Declared by:

<selfhostblocks/modules/services/immich.nix>
shb.immich.sso.endpoint

OIDC endpoint for SSO.

Type: string

Example:

"https://authelia.example.com"

Declared by:

<selfhostblocks/modules/services/immich.nix>
shb.immich.sso.passwordLogin

Enable password login.

Type: boolean

Default:

true

Declared by:

<selfhostblocks/modules/services/immich.nix>
shb.immich.sso.port

If given, adds a port to the endpoint.

Type: null or 16 bit unsigned integer; between 0 and 65535 (both inclusive)

Default:

null

Declared by:

<selfhostblocks/modules/services/immich.nix>
shb.immich.sso.provider

OIDC provider name, used for display.

Type: one of “Authelia”, “Keycloak”, “Generic”

Default:

"Authelia"

Declared by:

<selfhostblocks/modules/services/immich.nix>
shb.immich.sso.sharedSecret

OIDC shared secret for Immich.

Type: submodule

Declared by:

<selfhostblocks/modules/services/immich.nix>
shb.immich.sso.sharedSecret.request

Request part of the secret contract.

Options set by the requester module enforcing some properties the secret should have.

Type: submodule

Default:

""

Declared by:

<selfhostblocks/modules/services/immich.nix>
shb.immich.sso.sharedSecret.request.group

Linux group owning the secret file.

Type: string

Default:

"immich"

Declared by:

<selfhostblocks/modules/services/immich.nix>
shb.immich.sso.sharedSecret.request.mode

Mode of the secret file.

Type: string

Default:

"0400"

Declared by:

<selfhostblocks/modules/services/immich.nix>
shb.immich.sso.sharedSecret.request.owner

Linux user owning the secret file.

Type: string

Default:

"immich"

Declared by:

<selfhostblocks/modules/services/immich.nix>
shb.immich.sso.sharedSecret.request.restartUnits

Systemd units to restart after the secret is updated.

Type: list of string

Default:

[
  "immich-server.service"
]

Declared by:

<selfhostblocks/modules/services/immich.nix>
shb.immich.sso.sharedSecret.result

Result part of the secret contract.

Options set by the provider module that indicates where the secret can be found.

Type: submodule

Default:

{
  path = "/run/secrets/secret";
}

Declared by:

<selfhostblocks/modules/services/immich.nix>
shb.immich.sso.sharedSecret.result.path

Path to the file containing the secret generated out of band.

This path will exist after deploying to a target host, it is not available through the nix store.

Type: absolute path

Default:

"/run/secrets/secret"

Declared by:

<selfhostblocks/modules/services/immich.nix>
shb.immich.sso.sharedSecretForAuthelia

OIDC shared secret for Authelia. Content must be the same as sharedSecret option.

Type: submodule

Default:

null

Declared by:

<selfhostblocks/modules/services/immich.nix>
shb.immich.sso.sharedSecretForAuthelia.request

Request part of the secret contract.

Options set by the requester module enforcing some properties the secret should have.

Type: submodule

Default:

""

Declared by:

<selfhostblocks/modules/services/immich.nix>
shb.immich.sso.sharedSecretForAuthelia.request.group

Linux group owning the secret file.

Type: string

Default:

"root"

Declared by:

<selfhostblocks/modules/services/immich.nix>
shb.immich.sso.sharedSecretForAuthelia.request.mode

Mode of the secret file.

Type: string

Default:

"0400"

Declared by:

<selfhostblocks/modules/services/immich.nix>
shb.immich.sso.sharedSecretForAuthelia.request.owner

Linux user owning the secret file.

Type: string

Default:

"authelia"

Declared by:

<selfhostblocks/modules/services/immich.nix>
shb.immich.sso.sharedSecretForAuthelia.request.restartUnits

Systemd units to restart after the secret is updated.

Type: list of string

Default:

[ ]

Declared by:

<selfhostblocks/modules/services/immich.nix>
shb.immich.sso.sharedSecretForAuthelia.result

Result part of the secret contract.

Options set by the provider module that indicates where the secret can be found.

Type: submodule

Default:

{
  path = "/run/secrets/secret";
}

Declared by:

<selfhostblocks/modules/services/immich.nix>
shb.immich.sso.sharedSecretForAuthelia.result.path

Path to the file containing the secret generated out of band.

This path will exist after deploying to a target host, it is not available through the nix store.

Type: absolute path

Default:

"/run/secrets/secret"

Declared by:

<selfhostblocks/modules/services/immich.nix>
shb.immich.sso.storageLabelClaim

Claim to use for user storage label.

Type: string

Default:

"preferred_username"

Declared by:

<selfhostblocks/modules/services/immich.nix>
shb.immich.sso.userGroup

OIDC user group

Type: string

Default:

"immich_user"

Declared by:

<selfhostblocks/modules/services/immich.nix>
shb.immich.subdomain

Subdomain under which Immich will be served.

<subdomain>.<domain>

Type: string

Example:

"photos"

Declared by:

<selfhostblocks/modules/services/immich.nix>