|
| 1 | +{ pkgs, config, lib, ... }: |
| 2 | +let |
| 3 | + cfg = config.services.pocket-id; |
| 4 | + types = lib.types; |
| 5 | + pocket-id-storage = config.env.DEVENV_STATE + "/pocket-id"; |
| 6 | +in |
| 7 | +{ |
| 8 | + options.services.pocket-id = { |
| 9 | + enable = lib.mkEnableOption "Pocket ID server, an OIDC provider. [pocket-id.org](https://pocket-id.org)"; |
| 10 | + |
| 11 | + package = lib.mkOption { |
| 12 | + type = types.package; |
| 13 | + default = pkgs.pocket-id; |
| 14 | + defaultText = lib.literalExpression "pkgs.pocket-id"; |
| 15 | + description = "The pocket-id package to use."; |
| 16 | + }; |
| 17 | + |
| 18 | + app_url = lib.mkOption { |
| 19 | + type = types.str; |
| 20 | + default = "http://localhost:1411"; |
| 21 | + description = '' |
| 22 | + Specifies the connection string used to connect to the database. |
| 23 | +
|
| 24 | + This will set the environment variable `APP_URL`. |
| 25 | + ''; |
| 26 | + }; |
| 27 | + |
| 28 | + disable_analytics = lib.mkOption { |
| 29 | + type = types.bool; |
| 30 | + description = '' |
| 31 | + Disable heartbeat that gets sent every 24 hours to count how many Pocket ID instances are running. |
| 32 | +
|
| 33 | + See [docs page](https://pocket-id.org/docs/configuration/analytics/). |
| 34 | +
|
| 35 | + This will set the environment variable `ANALYTICS_DISABLED`. |
| 36 | + ''; |
| 37 | + default = false; |
| 38 | + }; |
| 39 | + |
| 40 | + disable_geolite = lib.mkOption { |
| 41 | + type = types.bool; |
| 42 | + default = false; |
| 43 | + description = '' |
| 44 | + Disable usage of GeoLite by setting the download URL for the GeoLite database to an empty string. |
| 45 | +
|
| 46 | + This will set the environment variable `GEOLITE_DB_URL` with an empty string. |
| 47 | + ''; |
| 48 | + }; |
| 49 | + |
| 50 | + reverse_proxy = lib.mkOption { |
| 51 | + type = types.bool; |
| 52 | + default = false; |
| 53 | + description = '' |
| 54 | + Whether the app is behind a reverse proxy. |
| 55 | +
|
| 56 | + This will set the environment variable `TRUST_PROXY`. |
| 57 | + ''; |
| 58 | + }; |
| 59 | + |
| 60 | + use_unix_socket = lib.mkOption { |
| 61 | + type = types.bool; |
| 62 | + default = false; |
| 63 | + description = '' |
| 64 | + Make pocket-id listen to a UNIX socket instead of TCP. The socket will be located at `$DEVENV_RUNTIME/pocket-id.sock`. |
| 65 | +
|
| 66 | + This will set the `UNIX_SOCKET` environment variable with the socket location. Pocket ID will ignore the environment variables `HOST` and `PORT`. |
| 67 | +
|
| 68 | + Additionally, the option `reverse_proxy` will be set to `true`. |
| 69 | + ''; |
| 70 | + }; |
| 71 | + |
| 72 | + disable_ui_configuration = lib.mkOption { |
| 73 | + type = types.bool; |
| 74 | + default = false; |
| 75 | + description = '' |
| 76 | + Disable the ability to configure the UI through the web client. Customization will be done exclusively through environment variables. |
| 77 | +
|
| 78 | + This will set the environment variable `UI_CONFIG_DISABLED`. |
| 79 | + ''; |
| 80 | + }; |
| 81 | + |
| 82 | + env = lib.mkOption { |
| 83 | + type = types.attrsOf types.str; |
| 84 | + default = { }; |
| 85 | + description = '' |
| 86 | + Additional environment variables for pocket-id. |
| 87 | +
|
| 88 | + See [list of all variables](https://pocket-id.org/docs/configuration/environment-variables). |
| 89 | + ''; |
| 90 | + }; |
| 91 | + |
| 92 | + }; |
| 93 | + |
| 94 | + config = lib.mkIf cfg.enable { |
| 95 | + packages = [ cfg.package ]; |
| 96 | + |
| 97 | + env = { |
| 98 | + ANALYTICS_DISABLED = if cfg.disable_analytics then "true" else null; |
| 99 | + |
| 100 | + APP_URL = cfg.app_url; |
| 101 | + |
| 102 | + DB_CONNECTION_STRING = "file:${pocket-id-storage}/pocket-id.db"; |
| 103 | + UPLOAD_PATH = "${pocket-id-storage}/uploads"; |
| 104 | + KEYS_PATH = "${pocket-id-storage}/keys"; |
| 105 | + GEOLITE_DB_PATH = "${pocket-id-storage}/GeoLite2-City.mmdb"; |
| 106 | + |
| 107 | + UNIX_SOCKET = if cfg.use_unix_socket then "${config.env.DEVENV_RUNTIME}/pocket-id.sock" else null; |
| 108 | + TRUST_PROXY = if cfg.use_unix_socket or cfg.reverse_proxy then "true" else null; |
| 109 | + |
| 110 | + GEOLITE_DB_URL = if cfg.disable_geolite then "" else null; |
| 111 | + |
| 112 | + UI_CONFIG_DISABLED = if cfg.disable_ui_configuration then "true" else null; |
| 113 | + } // cfg.env; |
| 114 | + |
| 115 | + processes.pocket-id.exec = '' |
| 116 | + mkdir -p ${pocket-id-storage} |
| 117 | + exec "${cfg.package}/bin/pocket-id" |
| 118 | + ''; |
| 119 | + }; |
| 120 | + |
| 121 | +} |
0 commit comments