Skip to content

Commit

Permalink
power-meter
Browse files Browse the repository at this point in the history
  • Loading branch information
Czichy committed Dec 5, 2024
1 parent f292cad commit 81c88b7
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 63 deletions.
1 change: 1 addition & 0 deletions hosts/HL-1-MRZ-HOST-01/guests.nix
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
// mkMicrovm "ibkr-flex" "HL-3-RZ-IBKR-01" "enp4s0" "02:01:27:ff:ed:77" "vlan40" {
}
// mkMicrovm "power-meter" "HL-3-RZ-POWER-01" "enp4s0" "02:01:27:f1:ed:77" "vlan40" {
enableStorageDataset = true;
}
);
};
Expand Down
101 changes: 38 additions & 63 deletions hosts/HL-1-MRZ-HOST-01/guests/power-meter.nix
Original file line number Diff line number Diff line change
@@ -1,37 +1,14 @@
{
inputs,
config,
pkgs,
secretsPath,
hostName,
...
}: let
# |----------------------------------------------------------------------| #
query = "639991";
slug = "https://health.czichy.com/ping/";
download-ibkr-flex =
pkgs.writeShellScriptBin "ibkr-flex-download"
''
#!/usr/bin/env bash
set -euo pipefail
echo "Downloading Flex Report"
token="$(cat ${config.age.secrets.ibkrFlexToken.path})";
/run/current-system/sw/bin/ibkr-rust-flex -q ${query} -t "$token" --dump-path /TWS_Flex_Reports
for file in /TWS_Flex_Reports/*.xml ; do
fileDate=$(${pkgs.gawk}/bin/awk -F[_.] '{print $3 }' <<<"$(basename "$file")");
destination="$(${pkgs.gawk}/bin/awk -F[-] '{print $1 }' <<<"$fileDate")/$(${pkgs.gawk}/bin/awk -F[-] '{print $1"-"$2 }' <<<"$fileDate")/"
echo "$destination"
mkdir -p "/TWS_Flex_Reports/$destination";
mv "$file" "/TWS_Flex_Reports/$destination";
done
pingKey="$(cat ${config.age.secrets.ibkr-flex-hc-ping.path})";
${pkgs.curl}/bin/curl -m 10 --retry 5 --retry-connrefused "${slug}$pingKey/ibkr-flex-download"
'';
# |----------------------------------------------------------------------| #
in {
}:
# let
# |----------------------------------------------------------------------| #
# |----------------------------------------------------------------------| #
# in
{
microvm.mem = 512;
microvm.vcpu = 1;
microvm.shares = [
Expand All @@ -49,52 +26,50 @@ in {

# |----------------------------------------------------------------------| #
users = {
users.ibkr = {
users.power = {
isSystemUser = true;
group = "ibkr";
group = "power";
};
groups.ibkr = {};
groups.power = {};
};
# |----------------------------------------------------------------------| #
age.secrets = {
ibkrFlexToken = {
symlink = true;
file = secretsPath + "/hosts/HL-1-MRZ-HOST-01/guests/ibkr-flex/token.age";
mode = "0600";
owner = "root";
};
};
age.secrets.ibkr-flex-hc-ping = {
file = secretsPath + "/hosts/HL-4-PAZ-PROXY-01/healthchecks-ping.age";
mode = "440";
owner = "root";
};
# age.secrets = {
# ibkrFlexToken = {
# symlink = true;
# file = secretsPath + "/hosts/HL-1-MRZ-HOST-01/guests/ibkr-flex/token.age";
# mode = "0600";
# owner = "root";
# };
# };
# age.secrets.ibkr-flex-hc-ping = {
# file = secretsPath + "/hosts/HL-4-PAZ-PROXY-01/healthchecks-ping.age";
# mode = "440";
# owner = "root";
# };
# ------------------------------
# | SYSTEM PACKAGES |
# ------------------------------
environment.systemPackages = with pkgs; [
gawk
pkg-config
openssh
inputs.ibkr-rust.packages.${pkgs.system}.flex
inputs.power-meter.packages.${pkgs.system}.power-meter
];
# |----------------------------------------------------------------------| #
systemd.timers."ibkr-flex-download" = {
wantedBy = ["timers.target"];
timerConfig = {
Perisistent = true;
OnCalendar = "Mon..Fri 23:30";
Unit = "ibkr-flex-download.service";
};
};
# systemd.timers."ibkr-flex-download" = {
# wantedBy = ["timers.target"];
# timerConfig = {
# Perisistent = true;
# OnCalendar = "Mon..Fri 23:30";
# Unit = "ibkr-flex-download.service";
# };
# };

systemd.services."ibkr-flex-download" = {
serviceConfig = {
Type = "simple";
User = "root";
ExecStart = "${download-ibkr-flex}/bin/ibkr-flex-download";
};
};
# systemd.services."ibkr-flex-download" = {
# serviceConfig = {
# Type = "simple";
# User = "root";
# ExecStart = "${download-ibkr-flex}/bin/ibkr-flex-download";
# };
# };

# |----------------------------------------------------------------------| #
environment.persistence."/persist".files = [
Expand Down

0 comments on commit 81c88b7

Please sign in to comment.