nixos module: add the ability to pass environment variables from the config
This commit is contained in:
parent
7ca272b612
commit
0139f6bac5
2 changed files with 15 additions and 4 deletions
|
@ -25,7 +25,7 @@ through (standard) environment variables.
|
||||||
```
|
```
|
||||||
custom.restic-alarm = {
|
custom.restic-alarm = {
|
||||||
enable = true;
|
enable = true;
|
||||||
env_file = "/path/to/secret/env";
|
environmentFile = "/path/to/secret/env";
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
where `/path/to/secret/env` points to a file containing the environment
|
where `/path/to/secret/env` points to a file containing the environment
|
||||||
|
|
17
flake.nix
17
flake.nix
|
@ -49,7 +49,16 @@
|
||||||
options.custom.restic-alarm = {
|
options.custom.restic-alarm = {
|
||||||
enable = mkEnableOption (lib.mdDoc "restic-alarm: send alarms for inactive backups");
|
enable = mkEnableOption (lib.mdDoc "restic-alarm: send alarms for inactive backups");
|
||||||
|
|
||||||
env_file = mkOption {
|
extraEnvironment = mkOption {
|
||||||
|
type = types.attrsOf types.str;
|
||||||
|
description = "Extra environment variables to pass to restic-alarm";
|
||||||
|
default = { };
|
||||||
|
example = {
|
||||||
|
AWS_ENDPOINT_URL = "https://mygarage.net";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
environmentFile = mkOption {
|
||||||
type = types.path;
|
type = types.path;
|
||||||
description = lib.mdDoc
|
description = lib.mdDoc
|
||||||
"The file containing the environment variables to pass to restic-alarm, for e.g. S3 access keys";
|
"The file containing the environment variables to pass to restic-alarm, for e.g. S3 access keys";
|
||||||
|
@ -65,18 +74,20 @@
|
||||||
after = [ "network.target" "network-online.target" ];
|
after = [ "network.target" "network-online.target" ];
|
||||||
wants = [ "network.target" "network-online.target" ];
|
wants = [ "network.target" "network-online.target" ];
|
||||||
wantedBy = [ "multi-user.target" ];
|
wantedBy = [ "multi-user.target" ];
|
||||||
restartTriggers = [ cfg.env_file ];
|
restartTriggers = [ cfg.environmentFile ];
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
ExecStart = "${pkg}/bin/restic-alarm";
|
ExecStart = "${pkg}/bin/restic-alarm";
|
||||||
DynamicUser = true;
|
DynamicUser = true;
|
||||||
EnvironmentFile = "${cfg.env_file}";
|
EnvironmentFile = "${cfg.environmentFile}";
|
||||||
};
|
};
|
||||||
|
environment = cfg.extraEnvironment;
|
||||||
};
|
};
|
||||||
|
|
||||||
systemd.timers.restic-alarm = {
|
systemd.timers.restic-alarm = {
|
||||||
partOf = [ "restic-alarm.service" ];
|
partOf = [ "restic-alarm.service" ];
|
||||||
wantedBy = [ "timers.target" ];
|
wantedBy = [ "timers.target" ];
|
||||||
after = [ "network-online.target" ];
|
after = [ "network-online.target" ];
|
||||||
|
wants = [ "network-online.target" ];
|
||||||
timerConfig = {
|
timerConfig = {
|
||||||
Unit = "restic-alarm.service";
|
Unit = "restic-alarm.service";
|
||||||
Persistent = true;
|
Persistent = true;
|
||||||
|
|
Loading…
Add table
Reference in a new issue