From 756e8e8f7e922ddc7666dac7789a99b8f193f775 Mon Sep 17 00:00:00 2001 From: revol-xut Date: Sat, 11 Jun 2022 01:19:12 +0200 Subject: [PATCH] new env variables for data-accumulator --- flake.nix | 2 +- modules/data-hoarder/clicky-bunty.nix | 16 ++-- modules/data-hoarder/data-accumulator.nix | 3 + modules/data-hoarder/file_sharing.nix | 12 +-- modules/dump-dvb/gnuradio.nix | 76 +++++++-------- modules/dump-dvb/telegram-decoder.nix | 100 ++++++++++---------- modules/traffic-stop-boxes/radio-config.nix | 18 ++-- pkgs/deployment.nix | 23 +++-- user-config.nix | 18 ++-- 9 files changed, 138 insertions(+), 130 deletions(-) diff --git a/flake.nix b/flake.nix index 5a2e748..253a595 100644 --- a/flake.nix +++ b/flake.nix @@ -237,8 +237,8 @@ nixpkgs.overlays = [ radio-conf.overlay."aarch64-linux" decode-server.overlay."aarch64-linux" ]; } ]; + }; }; - }; hydraJobs = { data-hoarder."x86_64-linux" = self.nixosConfigurations.data-hoarder.config.system.build.toplevel; diff --git a/modules/data-hoarder/clicky-bunty.nix b/modules/data-hoarder/clicky-bunty.nix index 67bff3c..c50cc00 100644 --- a/modules/data-hoarder/clicky-bunty.nix +++ b/modules/data-hoarder/clicky-bunty.nix @@ -36,15 +36,15 @@ in }; }; "pg-dvbdump-setup" = { - description = "prepare dvbdump postgres database"; - wantedBy = [ "multi-user.target" ]; - after = [ "networking.target" "postgresql.service" ]; - serviceConfig.Type = "oneshot"; + description = "prepare dvbdump postgres database"; + wantedBy = [ "multi-user.target" ]; + after = [ "networking.target" "postgresql.service" ]; + serviceConfig.Type = "oneshot"; - path = [ pkgs.sudo config.services.postgresql.package ]; - script = '' - sudo -u ${config.services.postgresql.superUser} psql -c "ALTER ROLE dvbdump WITH PASSWORD '$(cat ${config.sops.secrets.postgres_password.path})'" - ''; + path = [ pkgs.sudo config.services.postgresql.package ]; + script = '' + sudo -u ${config.services.postgresql.superUser} psql -c "ALTER ROLE dvbdump WITH PASSWORD '$(cat ${config.sops.secrets.postgres_password.path})'" + ''; }; }; }; diff --git a/modules/data-hoarder/data-accumulator.nix b/modules/data-hoarder/data-accumulator.nix index b481184..cc276d2 100644 --- a/modules/data-hoarder/data-accumulator.nix +++ b/modules/data-hoarder/data-accumulator.nix @@ -12,12 +12,15 @@ wantedBy = [ "multi-user.target" ]; script = '' + export POSTGRES_PASSWORD=$(cat ${config.sops.secrets.postgres_password.path}) exec ${pkgs.data-accumulator}/bin/data-accumulator --host 0.0.0.0 --port 8080& ''; environment = { "INFLUX_HOST" = "http://localhost:8086"; "GRPC_HOST" = "http://127.0.0.1:50051"; + "POSTGRES_HOST" = "127.0.0.1"; + "POSTGRES_PORT" = "5432"; }; serviceConfig = { Type = "forking"; diff --git a/modules/data-hoarder/file_sharing.nix b/modules/data-hoarder/file_sharing.nix index 3374042..335e7c8 100644 --- a/modules/data-hoarder/file_sharing.nix +++ b/modules/data-hoarder/file_sharing.nix @@ -26,13 +26,13 @@ systemd.services.dump-csv = { path = with pkgs; [ influxdb gzip ]; script = '' - cd /tmp - TMPFILE=$(mktemp telegrams.XXXXX.csv.gz) - TIMESTAMP=$(date +"%Y%m%d-%H%M") -influx -precision rfc3339 -database dvbdump -execute "SELECT * FROM telegram_r_09 WHERE time > now()-1h" -format csv | gzip -c > $TMPFILE - chmod a+r $TMPFILE + cd /tmp + TMPFILE=$(mktemp telegrams.XXXXX.csv.gz) + TIMESTAMP=$(date +"%Y%m%d-%H%M") + influx -precision rfc3339 -database dvbdump -execute "SELECT * FROM telegram_r_09 WHERE time > now()-1h" -format csv | gzip -c > $TMPFILE + chmod a+r $TMPFILE - mv $TMPFILE /var/lib/data-accumulator/data/telegrams-''${TIMESTAMP}.csv.gz + mv $TMPFILE /var/lib/data-accumulator/data/telegrams-''${TIMESTAMP}.csv.gz ''; }; systemd.timers.dump-csv = { diff --git a/modules/dump-dvb/gnuradio.nix b/modules/dump-dvb/gnuradio.nix index 83a5aea..a262a71 100644 --- a/modules/dump-dvb/gnuradio.nix +++ b/modules/dump-dvb/gnuradio.nix @@ -1,32 +1,32 @@ { pkgs, config, lib, ... }: let - receiver = pkgs.gnuradio-decoder; - cfg = config.services.dump-dvb.gnuradio; + receiver = pkgs.gnuradio-decoder; + cfg = config.services.dump-dvb.gnuradio; in - { - options.services.dump-dvb.gnuradio = { - enable = lib.mkOption { - type = lib.types.bool; - default = false; - description = ''Wether to enable dump-dvb gnuradio reciever''; - }; - device = lib.mkOption { - type = lib.types.str; - default = ""; - example = "hackrf=0"; - description = ''Device string to pass to gnuradio''; - }; - frequency = lib.mkOption { - type = lib.types.int; - default = 170795000; - description = ''Frequency to tune radio to''; - }; - offset = lib.mkOption { - type = lib.types.int; - default = 19550; - description = ''Offset of the signal from center frequency''; - }; +{ + options.services.dump-dvb.gnuradio = { + enable = lib.mkOption { + type = lib.types.bool; + default = false; + description = ''Wether to enable dump-dvb gnuradio reciever''; }; + device = lib.mkOption { + type = lib.types.str; + default = ""; + example = "hackrf=0"; + description = ''Device string to pass to gnuradio''; + }; + frequency = lib.mkOption { + type = lib.types.int; + default = 170795000; + description = ''Frequency to tune radio to''; + }; + offset = lib.mkOption { + type = lib.types.int; + default = 19550; + description = ''Offset of the signal from center frequency''; + }; + }; config = lib.mkIf config.services.dump-dvb.gnuradio.enable { @@ -45,20 +45,20 @@ in }; }; - users.groups.gnuradio = {}; - users.users.gnuradio = { - name = "gnuradio"; - description = "gnu radio service user"; - isSystemUser = true; - group = "gnuradio"; - extraGroups = [ "plugdev" ]; - }; + users.groups.gnuradio = { }; + users.users.gnuradio = { + name = "gnuradio"; + description = "gnu radio service user"; + isSystemUser = true; + group = "gnuradio"; + extraGroups = [ "plugdev" ]; + }; - security.wrappers.gnuradio-decode = { - owner = "gnuradio"; - group = "users"; - capabilities = "cap_sys_nice+eip"; - source = "${receiver}/bin/gnuradio-decoder-cpp"; + security.wrappers.gnuradio-decode = { + owner = "gnuradio"; + group = "users"; + capabilities = "cap_sys_nice+eip"; + source = "${receiver}/bin/gnuradio-decoder-cpp"; }; }; diff --git a/modules/dump-dvb/telegram-decoder.nix b/modules/dump-dvb/telegram-decoder.nix index 58b2e41..044b303 100644 --- a/modules/dump-dvb/telegram-decoder.nix +++ b/modules/dump-dvb/telegram-decoder.nix @@ -2,62 +2,62 @@ let cfg = config.services.dump-dvb.telegram-decoder; in - { - options.services.dump-dvb.telegram-decoder = { - enable = lib.mkOption { - type = lib.types.bool; - default = false; - description = ''Wether to enable dump-dvb telegram-decoder''; - }; - server = lib.mkOption { - type = lib.types.listOf lib.types.str; - default = [ "https://dump.dvb.solutions/" ]; - description = ''URL of the dump-dvb websocket''; - }; - configFile = lib.mkOption { - type = lib.types.str; - default = "/etc/telegram-decoder/settings.json"; - description = ''Path to telegram-decoder config''; - }; - authTokenFile = lib.mkOption { - type = lib.types.str; - default = "/etc/telegram-decoder/token"; - description = ''Path to telegram-decoder auth token''; - }; +{ + options.services.dump-dvb.telegram-decoder = { + enable = lib.mkOption { + type = lib.types.bool; + default = false; + description = ''Wether to enable dump-dvb telegram-decoder''; + }; + server = lib.mkOption { + type = lib.types.listOf lib.types.str; + default = [ "https://dump.dvb.solutions/" ]; + description = ''URL of the dump-dvb websocket''; + }; + configFile = lib.mkOption { + type = lib.types.str; + default = "/etc/telegram-decoder/settings.json"; + description = ''Path to telegram-decoder config''; + }; + authTokenFile = lib.mkOption { + type = lib.types.str; + default = "/etc/telegram-decoder/token"; + description = ''Path to telegram-decoder auth token''; + }; + }; + + + config = lib.mkIf config.services.dump-dvb.telegram-decoder.enable { + + environment.systemPackages = [ pkgs.telegram-decoder ]; + + users.groups.telegram-decoder = { }; + + users.users.telegram-decoder = { + name = "telegram-decoder"; + description = "gnu radio service user"; + group = "telegram-decoder"; + isSystemUser = true; }; + systemd.services."telegram-decoder" = { + enable = true; + wantedBy = [ "multi-user.target" ]; - config = lib.mkIf config.services.dump-dvb.telegram-decoder.enable { + script = "exec ${pkgs.telegram-decoder}/bin/telegram-decode --config ${cfg.configFile} --server ${builtins.concatStringsSep " " cfg.server} &"; - environment.systemPackages = [ pkgs.telegram-decoder ]; - - users.groups.telegram-decoder = {}; - - users.users.telegram-decoder = { - name = "telegram-decoder"; - description = "gnu radio service user"; - group = "telegram-decoder"; - isSystemUser = true; + environment = { + AUTHENTICATION_TOKEN_PATH = cfg.authTokenFile; }; - systemd.services."telegram-decoder" = { - enable = true; - wantedBy = [ "multi-user.target" ]; - - script = "exec ${pkgs.telegram-decoder}/bin/telegram-decode --config ${cfg.configFile} --server ${builtins.concatStringsSep " " cfg.server} &"; - - environment = { - AUTHENTICATION_TOKEN_PATH=cfg.authTokenFile; - }; - - serviceConfig = { - Type = "forking"; - User = "telegram-decoder"; - Restart = "on-failure"; - StartLimitBurst = "2"; - StartLimitIntervalSec = "150s"; - }; + serviceConfig = { + Type = "forking"; + User = "telegram-decoder"; + Restart = "on-failure"; + StartLimitBurst = "2"; + StartLimitIntervalSec = "150s"; }; }; + }; - } +} diff --git a/modules/traffic-stop-boxes/radio-config.nix b/modules/traffic-stop-boxes/radio-config.nix index 0458123..33bf0ea 100644 --- a/modules/traffic-stop-boxes/radio-config.nix +++ b/modules/traffic-stop-boxes/radio-config.nix @@ -1,16 +1,16 @@ { config, lib, ... }: let -file = "/etc/nixos/configs" + "/config_${toString config.dump-dvb.systemNumber}.json"; # make sure that the box has our nix-config checkout, lol -receiver_configs = [ - { frequency = 170795000; offset = 19550; device = "hackrf=0"; } # dresden - barkhausen - { frequency = 170795000; offset = 19500; device = "hackrf=0"; } # dresden - zentralwerk - { frequency = 153850000; offset = 20000; device = ""; } # chemnitz - { frequency = 170795000; offset = 19550; device = "hackrf=0"; } # dresden unused - { frequency = 170795000; offset = 19550; device = "hackrf=0"; } # dresden unused -]; + file = "/etc/nixos/configs" + "/config_${toString config.dump-dvb.systemNumber}.json"; # make sure that the box has our nix-config checkout, lol + receiver_configs = [ + { frequency = 170795000; offset = 19550; device = "hackrf=0"; } # dresden - barkhausen + { frequency = 170795000; offset = 19500; device = "hackrf=0"; } # dresden - zentralwerk + { frequency = 153850000; offset = 20000; device = ""; } # chemnitz + { frequency = 170795000; offset = 19550; device = "hackrf=0"; } # dresden unused + { frequency = 170795000; offset = 19550; device = "hackrf=0"; } # dresden unused + ]; -receiver_config = lib.elemAt receiver_configs config.dump-dvb.systemNumber; + receiver_config = lib.elemAt receiver_configs config.dump-dvb.systemNumber; in { services.dump-dvb.gnuradio = { diff --git a/pkgs/deployment.nix b/pkgs/deployment.nix index 5b6c320..8192f98 100644 --- a/pkgs/deployment.nix +++ b/pkgs/deployment.nix @@ -3,7 +3,8 @@ let installScript = (system: let ip = "10.13.37.${toString (system.config.dump-dvb.systemNumber + 100)}"; - in (pkgs.writeScriptBin "deploy" '' + in + (pkgs.writeScriptBin "deploy" '' #!${pkgs.runtimeShell} ssh root@${ip} "ps cax | grep \"nixos-rebuild\" > /dev/null" if [ $? -eq 0 ] @@ -16,21 +17,25 @@ let fi '')); - installScripts = pkgs.lib.mapAttrs' (name: system: - pkgs.lib.attrsets.nameValuePair ("deploy-" + name) (installScript system)) + installScripts = pkgs.lib.mapAttrs' + (name: system: + pkgs.lib.attrsets.nameValuePair ("deploy-" + name) (installScript system)) systems; deployAllExecutablePathsConcatted = pkgs.lib.strings.concatMapStringsSep " " (path: "${path}/bin/deploy") - (builtins.attrValues installScripts); + (builtins.attrValues installScripts); deployAllScript = (name: - pkgs.writeScriptBin name ('' - #!${pkgs.runtimeShell} -ex - ${pkgs.parallel}/bin/parallel --will-cite -j10 ::: ${deployAllExecutablePathsConcatted} || echo "Some deployment failed" - '')); + pkgs.writeScriptBin name ( + '' + #!${pkgs.runtimeShell} -ex + ${pkgs.parallel}/bin/parallel --will-cite -j10 ::: ${deployAllExecutablePathsConcatted} || echo "Some deployment failed" + '' + )); -in { +in +{ deploy-all = deployAllScript "deploy-all"; nuke-all = deployAllScript "nuke-all"; } // installScripts diff --git a/user-config.nix b/user-config.nix index d2dd512..331cf3e 100644 --- a/user-config.nix +++ b/user-config.nix @@ -1,12 +1,12 @@ { - services.dump-dvb.gnuradio = { - enable = true; -# frequency = 105200000; -# offset = 1100; -# device = ""; - }; - services.dump-dvb.telegram-decoder = { - enable = true; - }; + services.dump-dvb.gnuradio = { + enable = true; + # frequency = 105200000; + # offset = 1100; + # device = ""; + }; + services.dump-dvb.telegram-decoder = { + enable = true; + }; }