Skip to content

Commit 3f0bd8a

Browse files
committed
nixos/healthchecks: add settingsFile option
Single unified env file read by systemd
1 parent 0be5a16 commit 3f0bd8a

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

nixos/modules/services/web-apps/healthchecks.nix

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ let
1111
environment = {
1212
PYTHONPATH = pkg.pythonPath;
1313
STATIC_ROOT = cfg.dataDir + "/static";
14-
} // cfg.settings;
14+
} // lib.filterAttrs (_: v: !builtins.isNull v) cfg.settings;
1515

1616
environmentFile = pkgs.writeText "healthchecks-environment" (lib.generators.toKeyValue { } environment);
1717

@@ -21,6 +21,7 @@ let
2121
sudo='exec /run/wrappers/bin/sudo -u ${cfg.user} --preserve-env --preserve-env=PYTHONPATH'
2222
fi
2323
export $(cat ${environmentFile} | xargs)
24+
${lib.optionalString (cfg.settingsFile != null) "export $(cat ${cfg.settingsFile} | xargs)"}
2425
$sudo ${pkg}/opt/healthchecks/manage.py "$@"
2526
'';
2627
in
@@ -89,6 +90,12 @@ in
8990
'';
9091
};
9192

93+
settingsFile = lib.mkOption {
94+
type = lib.types.nullOr lib.types.path;
95+
default = null;
96+
description = opt.settings.description;
97+
};
98+
9299
settings = lib.mkOption {
93100
description = ''
94101
Environment variables which are read by healthchecks `(local)_settings.py`.
@@ -109,6 +116,8 @@ in
109116
have support for a `_FILE` variant, run:
110117
- `nix-instantiate --eval --expr '(import <nixpkgs> {}).healthchecks.secrets'`
111118
- or `nix eval 'nixpkgs#healthchecks.secrets'` if the flake support has been enabled.
119+
120+
If the same variable is set in both `settings` and `settingsFile` the value from `settingsFile` has priority.
112121
'';
113122
type = types.submodule (settings: {
114123
freeformType = types.attrsOf types.str;
@@ -121,8 +130,9 @@ in
121130
};
122131

123132
SECRET_KEY_FILE = mkOption {
124-
type = types.path;
133+
type = types.nullOr types.path;
125134
description = "Path to a file containing the secret key.";
135+
default = null;
126136
};
127137

128138
DEBUG = mkOption {
@@ -186,7 +196,9 @@ in
186196
WorkingDirectory = cfg.dataDir;
187197
User = cfg.user;
188198
Group = cfg.group;
189-
EnvironmentFile = [ environmentFile ];
199+
EnvironmentFile = [
200+
environmentFile
201+
] ++ lib.optional (cfg.settingsFile != null) cfg.settingsFile;
190202
StateDirectory = mkIf (cfg.dataDir == "/var/lib/healthchecks") "healthchecks";
191203
StateDirectoryMode = mkIf (cfg.dataDir == "/var/lib/healthchecks") "0750";
192204
};

0 commit comments

Comments
 (0)