satnogs-client-docker-flake/satnogs-client-docker-modul...

163 lines
5.7 KiB
Nix
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

{ lib, config, pkgs, ... }:
with lib;
let
cfg = config.services.satnogs-client-docker;
in
{
options.services.satnogs-client-docker = {
enable = mkEnableOption "satnogs-client docker service";
satnogs-api-token = mkOption {
type = types.str;
default = "";
description = mdDoc ''
It is recommended to use additional-env-files instead and provide the token,
via something like agenix, so that it wont end up in the nix-store;
The API token assigned to your ground station on the SatNOGS Network website,
please dont share your api key as this can give access to anyone to upload and change
things in network related to your station and its observations.
To find your API token, log in to network.satnogs.org,
click on the user icon at the top right corner and then click on the "Dashboard" option.
On the top of the dashboard page right under the user icon click the button "API key" to show your API token.
'';
};
satnogs-soapy-rx-device = mkOption {
type = types.str;
default = "driver=rtlsdr";
description = mdDoc ''
If you are using an RTL-SDR, this is `driver=rtlsdr`.
For other devices tested configurations can be found at [Software Defined Radio](https://wiki.satnogs.org/Software_Defined_Radio).
See [pothosware/SoapyRTLSDR/wiki#modules](https://github.com/pothosware/SoapyRTLSDR/wiki#modules) for other SDR modules.
If multiple devices are attached to your station you should also specify the serial of the desired device here,
e.g. `driver=uhd,serial=3164495`.
'';
};
satnogs-antenna = mkOption {
type = types.str;
default = "RX";
description = mdDoc ''
If you are using an RTL-SDR, this is RX.
For other devices tested configurations can be found at [Software Defined Radio](https://wiki.satnogs.org/Software_Defined_Radio).
If your device is not listed there yet, use `SoapySDRUtil --probe 2>&1| grep Antennas` to get available antennas.
'';
};
satnogs-rx-samp-rate = mkOption {
type = types.str;
default = "2.048e6";
description = mdDoc ''
Specify the receiver sampling rate.
Recommended value for RTL-SDR: 2.048e6 (for 2Msps),
other devices will need different sample rates described at [Software Defined Radio](https://wiki.satnogs.org/Software_Defined_Radio).
The command `SoapySDRUtil --probe 2>&1 | grep Sample` can be used to find all valid sample rates.
'';
};
satnogs-rf-gain = mkOption {
type = types.str;
default = "32.8";
description = mdDoc ''
RF Gain value for your SDR hardware.
Run `SoapySDRUtil --probe` to see all possible gain values for your hardware.
Example: For RTL-SDR without pre-amp, 32.8 is a good starting value.
Follow [Setting the gain](https://wiki.satnogs.org/Omnidirectional_Station_How_To#Setting_the_gain) to find a good gain value.
'';
};
satnogs-station-elev = mkOption {
type = types.str;
default = "";
description = mdDoc ''
The height of your ground station above sea level in metres.
'';
};
satnogs-station-id = mkOption {
type = types.str;
default = "";
description = mdDoc ''
The **numeric ID** assigned to your station in the SatNOGS Network site when the groundstation was created.
'';
};
satnogs-station-lat = mkOption {
type = types.str;
default = "";
description = mdDoc ''
The latitude of your station. North is positive, south is negative.
'';
};
satnogs-station-lon = mkOption {
type = types.str;
default = "";
description = mdDoc ''
The longitude of your station. East is positive, west is negative.
'';
};
additional-env-files = mkOption {
type = with types; listOf path;
default = [ ];
description = lib.mdDoc ''
Additional environment files containing settings in the form:
```
NAME = VALUE
SATNOGS_API_TOKEN = dead-beef-coffee
'';
};
};
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}"
]
++ 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" ];
};
};
}