From c6e91fc5235ea5d8cf1f6298debf19feca314c31 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Sun, 11 Feb 2024 17:07:06 +0100 Subject: [PATCH] Started to add options --- flake.lock | 61 ++++++++++++++++++++++++++++++ flake.nix | 21 +++++++++++ satnogs-client-docker-module.nix | 64 ++++++++++++++++++++++++++++++++ 3 files changed, 146 insertions(+) create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 satnogs-client-docker-module.nix diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..ee34300 --- /dev/null +++ b/flake.lock @@ -0,0 +1,61 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1705309234, + "narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "1ef2e671c3b0c19053962c07dbda38332dcebf26", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1701282334, + "narHash": "sha256-MxCVrXY6v4QmfTwIysjjaX0XUhqBbxTWWB4HXtDYsdk=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "057f9aecfb71c4437d2b27d3323df7f93c010b7e", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "23.11", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..00849ad --- /dev/null +++ b/flake.nix @@ -0,0 +1,21 @@ +{ + description = "A flake for setting up satnogs client using docker"; + + inputs = { + flake-utils.url = "github:numtide/flake-utils"; + nixpkgs.url = "github:NixOS/nixpkgs/23.11"; + }; + outputs = { self, nixpkgs, flake-utils }: + flake-utils.lib.eachSystem [ "x86_64-linux" "aarch64-linux" ] (system: + let + pkgs = nixpkgs.legacyPackages.${system}; + in + { + nixosModules.default = { config, pkgs, ... }: { + imports = [ ./stanogs-client-module.nix ]; + }; + + formatter = pkgs.nixpkgs-fmt; + } + ); +} diff --git a/satnogs-client-docker-module.nix b/satnogs-client-docker-module.nix new file mode 100644 index 0000000..8bf4fd9 --- /dev/null +++ b/satnogs-client-docker-module.nix @@ -0,0 +1,64 @@ +{ 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; + 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 don’t 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; + 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`. + ''; + }; + + + }; + + config = mkIf cfg.enable { + warnings = [ + mkIf + (cfg.satnogs-api-token != "") + "It is not recommended to use some form of secret management e.g. agenix to store your token." + ]; + + virtualisation.docker.enable = true; + + 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-env) + ++ [ "up" ]); + + preStop = "${pkgs.docker-compose}/bin/docker-compose -f ${./satnogs-docker-compose.yml} down"; + + wantedBy = [ "multi-user.target" ]; + after = [ "docker.service" "docker.socket" ]; + }; + }; +}