nixos/hosts/server/modules/bitcoin-git.nix
2024-06-21 13:58:14 +02:00

32 lines
894 B
Nix

{ pkgs, ... }: {
systemd.timers."bitcoin-git" = {
wantedBy = [ "timers.target" ];
timerConfig = {
Unit = "bitcoin-git.service";
OnCalendar = "daily";
Persistent = true;
};
};
systemd.services."bitcoin-git" = {
script = ''
[ ! -d "/home/hadi/btcprice" ] && ${pkgs.git}/bin/git clone git@github.com:anotherhadi/btcprice /home/hadi/btcprice
cd "/home/hadi/btcprice"
price=$(${pkgs.curl}/bin/curl eur.rate.sx/1BTC)
echo "# Bitcoin Price in EURO" >README.md
echo "" >>README.md
echo "1 Bitcoin = $price" >>README.md
echo "" >>README.md
echo "Date: $(date)" >>README.md
${pkgs.git}/bin/git add .
${pkgs.git}/bin/git commit -m "Update price (hadi)"
${pkgs.git}/bin/git push -u origin main
exit 0
'';
serviceConfig = {
Type = "oneshot";
User = "hadi";
};
};
}