docker-compose up wants an env file instead of -e

This commit is contained in:
Sebastian 2024-02-12 18:49:34 +01:00
parent 376b9e3199
commit 9a5d54aa13
1 changed files with 38 additions and 31 deletions

View File

@ -117,39 +117,46 @@ in
};
config = mkIf cfg.enable {
warnings =
if (cfg.satnogs-api-token != "") then
[
"It is not recommended to use some form of secret management e.g. agenix to store your token."
config =
let
satnogs-cfg-docker-env = pkgs.writeTextFile {
name = "satnogs-cfg-docker-env";
text = concatStringsSep "\n" (mapAttrsToList (k: v: if v != "" then "${k}=${v}" else "") {
SATNOGS_API_TOKEN = cfg.satnogs-api-token;
SATNOGS_SOAPY_RX_DEVICE = cfg.satnogs-soapy-rx-device;
SATNOGS_ANTENNA = cfg.satnogs-antenna;
SATNOGS_RX_SAMP_RATE = cfg.satnogs-rx-samp-rate;
SATNOGS_RF_GAIN = cfg.satnogs-rf-gain;
SATNOGS_STATION_ELEV = cfg.satnogs-station-elev;
SATNOGS_STATION_ID = cfg.satnogs-station-id;
SATNOGS_STATION_LAT = cfg.satnogs-station-lat;
SATNOGS_STATION_LON = cfg.satnogs-station-lon;
});
};
in
mkIf cfg.enable {
warnings =
if (cfg.satnogs-api-token != "") then
[
"It is not recommended to use some form of secret management e.g. agenix to store your token."
]
else [ ];
virtualisation.docker.enable = true;
systemd.services.satnogs-docker-compose = {
script = concatStringsSep " \\\n " ([
"${pkgs.docker-compose}/bin/docker-compose"
"-f ${./satnogs-docker-compose.yml}"
"--env-file ${satnogs-cfg-docker-env}"
]
else [ ];
++ map (f: "--env-file ${escapeShellArg f}") cfg.additional-env-files
++ [ "up" ]);
virtualisation.docker.enable = true;
preStop = "${pkgs.docker-compose}/bin/docker-compose -f ${./satnogs-docker-compose.yml} down";
systemd.services.satnogs-docker-compose = {
script = concatStringsSep " \\\n " ([
"${pkgs.docker-compose}/bin/docker-compose"
"-f ${./satnogs-docker-compose.yml}"
]
++ (mapAttrsToList (k: v: "-e ${escapeShellArg k}=${escapeShellArg v}") {
SATNOGS_API_TOKEN = cfg.satnogs-api-token;
SATNOGS_SOAPY_RX_DEVICE = cfg.satnogs-soapy-rx-device;
SATNOGS_ANTENNA = cfg.satnogs-antenna;
SATNOGS_RX_SAMP_RATE = cfg.satnogs-rx-samp-rate;
SATNOGS_RF_GAIN = cfg.satnogs-rf-gain;
SATNOGS_STATION_ELEV = cfg.satnogs-station-elev;
SATNOGS_STATION_ID = cfg.satnogs-station-id;
SATNOGS_STATION_LAT = cfg.satnogs-station-lat;
SATNOGS_STATION_LON = cfg.satnogs-station-lon;
})
++ map (f: "--env-file ${escapeShellArg f}") cfg.additional-env-files
++ [ "up" ]);
preStop = "${pkgs.docker-compose}/bin/docker-compose -f ${./satnogs-docker-compose.yml} down";
wantedBy = [ "multi-user.target" ];
after = [ "docker.service" "docker.socket" ];
wantedBy = [ "multi-user.target" ];
after = [ "docker.service" "docker.socket" ];
};
};
};
}