···11-{ config, lib, pkgs, buildEnv, ... }:
11+{ config, lib, options, pkgs, buildEnv, ... }:
2233with lib;
4455let
66 defaultUser = "healthchecks";
77 cfg = config.services.healthchecks;
88+ opt = options.services.healthchecks;
89 pkg = cfg.package;
910 boolToPython = b: if b then "True" else "False";
1011 environment = {
1112 PYTHONPATH = pkg.pythonPath;
1213 STATIC_ROOT = cfg.dataDir + "/static";
1313- DB_NAME = "${cfg.dataDir}/healthchecks.sqlite";
1414 } // cfg.settings;
15151616 environmentFile = pkgs.writeText "healthchecks-environment" (lib.generators.toKeyValue { } environment);
···9898 description = lib.mdDoc ''
9999 Environment variables which are read by healthchecks `(local)_settings.py`.
100100101101- Settings which are explicitly covered in options bewlow, are type-checked and/or transformed
101101+ Settings which are explicitly covered in options below, are type-checked and/or transformed
102102 before added to the environment, everything else is passed as a string.
103103104104 See <https://healthchecks.io/docs/self_hosted_configuration/>
105105 for a full documentation of settings.
106106107107- We add two variables to this list inside the packages `local_settings.py.`
108108- - STATIC_ROOT to set a state directory for dynamically generated static files.
109109- - SECRET_KEY_FILE to read SECRET_KEY from a file at runtime and keep it out of /nix/store.
107107+ We add additional variables to this list inside the packages `local_settings.py.`
108108+ - `STATIC_ROOT` to set a state directory for dynamically generated static files.
109109+ - `SECRET_KEY_FILE` to read `SECRET_KEY` from a file at runtime and keep it out of
110110+ /nix/store.
111111+ - `_FILE` variants for several values that hold sensitive information in
112112+ [Healthchecks configuration](https://healthchecks.io/docs/self_hosted_configuration/) so
113113+ that they also can be read from a file and kept out of /nix/store. To see which values
114114+ have support for a `_FILE` variant, run:
115115+ - `nix-instantiate --eval --expr '(import <nixpkgs> {}).healthchecks.secrets'`
116116+ - or `nix eval 'nixpkgs#healthchecks.secrets'` if the flake support has been enabled.
110117 '';
111111- type = types.submodule {
118118+ type = types.submodule (settings: {
112119 freeformType = types.attrsOf types.str;
113120 options = {
114121 ALLOWED_HOSTS = lib.mkOption {
···143150 '';
144151 apply = boolToPython;
145152 };
153153+154154+ DB = mkOption {
155155+ type = types.enum [ "sqlite" "postgres" "mysql" ];
156156+ default = "sqlite";
157157+ description = lib.mdDoc "Database engine to use.";
158158+ };
159159+160160+ DB_NAME = mkOption {
161161+ type = types.str;
162162+ default =
163163+ if settings.config.DB == "sqlite"
164164+ then "${cfg.dataDir}/healthchecks.sqlite"
165165+ else "hc";
166166+ defaultText = lib.literalExpression ''
167167+ if config.${settings.options.DB} == "sqlite"
168168+ then "''${config.${opt.dataDir}}/healthchecks.sqlite"
169169+ else "hc"
170170+ '';
171171+ description = lib.mdDoc "Database name.";
172172+ };
146173 };
147147- };
174174+ });
148175 };
149176 };
150177···168195 StateDirectoryMode = mkIf (cfg.dataDir == "/var/lib/healthchecks") "0750";
169196 };
170197 in
171171- {
198198+ {
172199 healthchecks-migration = {
173200 description = "Healthchecks migrations";
174201 wantedBy = [ "healthchecks.target" ];