1 { config, pkgs, lib, ... }:
3 cfg = config.services.photoprism;
6 PHOTOPRISM_ORIGINALS_PATH = cfg.originalsPath;
7 PHOTOPRISM_STORAGE_PATH = cfg.storagePath;
8 PHOTOPRISM_IMPORT_PATH = cfg.importPath;
9 PHOTOPRISM_HTTP_HOST = cfg.address;
10 PHOTOPRISM_HTTP_PORT = toString cfg.port;
12 lib.mapAttrs (_: toString) cfg.settings
15 manage = pkgs.writeShellScript "manage" ''
16 set -o allexport # Export the following env vars
17 ${lib.toShellVars env}
18 eval "$(${config.systemd.package}/bin/systemctl show -pUID,MainPID photoprism.service | ${pkgs.gnused}/bin/sed "s/UID/ServiceUID/")"
19 exec ${pkgs.util-linux}/bin/nsenter \
20 -t $MainPID -m -S $ServiceUID -G $ServiceUID --wdns=${cfg.storagePath} \
21 ${cfg.package}/bin/photoprism "$@"
25 meta.maintainers = with lib.maintainers; [ stunkymonkey ];
27 options.services.photoprism = {
29 enable = lib.mkEnableOption "Photoprism web server";
31 passwordFile = lib.mkOption {
32 type = lib.types.nullOr lib.types.path;
39 address = lib.mkOption {
41 default = "localhost";
43 Web interface address.
48 type = lib.types.port;
55 originalsPath = lib.mkOption {
56 type = lib.types.path;
58 example = "/data/photos";
60 Storage path of your original media files (photos and videos).
64 importPath = lib.mkOption {
68 Relative or absolute to the `originalsPath` from where the files should be imported.
72 storagePath = lib.mkOption {
73 type = lib.types.path;
74 default = "/var/lib/photoprism";
76 Location for sidecar, cache, and database files.
80 package = lib.mkPackageOption pkgs "photoprism" { };
82 settings = lib.mkOption {
83 type = lib.types.attrsOf lib.types.str;
86 See [the getting-started guide](https://docs.photoprism.app/getting-started/config-options/) for available options.
89 PHOTOPRISM_DEFAULT_LOCALE = "de";
90 PHOTOPRISM_ADMIN_USER = "root";
95 config = lib.mkIf cfg.enable {
96 systemd.services.photoprism = {
97 description = "Photoprism server";
100 Restart = "on-failure";
102 Group = "photoprism";
104 StateDirectory = "photoprism";
105 WorkingDirectory = "/var/lib/photoprism";
106 RuntimeDirectory = "photoprism";
107 ReadWritePaths = [ cfg.originalsPath cfg.importPath cfg.storagePath ];
109 LoadCredential = lib.optionalString (cfg.passwordFile != null)
110 "PHOTOPRISM_ADMIN_PASSWORD:${cfg.passwordFile}";
112 CapabilityBoundingSet = "";
113 LockPersonality = true;
114 PrivateDevices = true;
117 ProtectControlGroups = true;
119 ProtectHostname = true;
120 ProtectKernelLogs = true;
121 ProtectKernelModules = true;
122 ProtectKernelTunables = true;
123 RestrictAddressFamilies = [ "AF_UNIX" "AF_INET" "AF_INET6" ];
124 RestrictNamespaces = true;
125 RestrictRealtime = true;
126 SystemCallArchitectures = "native";
127 SystemCallFilter = [ "@system-service" "~@setuid @keyring" ];
129 } // lib.optionalAttrs (cfg.port < 1024) {
130 AmbientCapabilities = [ "CAP_NET_BIND_SERVICE" ];
131 CapabilityBoundingSet = [ "CAP_NET_BIND_SERVICE" ];
134 wantedBy = [ "multi-user.target" ];
137 # reminder: easier password configuration will come in https://github.com/photoprism/photoprism/pull/2302
139 ln -sf ${manage} photoprism-manage
141 ${lib.optionalString (cfg.passwordFile != null) ''
142 export PHOTOPRISM_ADMIN_PASSWORD=$(cat "$CREDENTIALS_DIRECTORY/PHOTOPRISM_ADMIN_PASSWORD")
144 exec ${cfg.package}/bin/photoprism migrations run -f
148 ${lib.optionalString (cfg.passwordFile != null) ''
149 export PHOTOPRISM_ADMIN_PASSWORD=$(cat "$CREDENTIALS_DIRECTORY/PHOTOPRISM_ADMIN_PASSWORD")
151 exec ${cfg.package}/bin/photoprism start