Skip to content

Instantly share code, notes, and snippets.

@zmej420
Created May 25, 2023 16:09
Show Gist options
  • Save zmej420/1611911d23beb7e2c1790ccf6f11c90d to your computer and use it in GitHub Desktop.
Save zmej420/1611911d23beb7e2c1790ccf6f11c90d to your computer and use it in GitHub Desktop.
Every hour automatically add all dirs in /mnt to chia farm, and remove dead mounts
# Every hour automatically add all dirs in /mnt to chia farm, and remove dead mounts
{pkgs,...}:
{
systemd = {
services.plotAdder = {
description = "chia plot adder service";
requires = [ "chia.mount" ];
wantedBy = [ "chia.mount" ];
after = [ "chia.mount" ];
serviceConfig = {
ExecStart = pkgs.writeScript "plotadder" ''
#!/run/current-system/sw/bin/zsh
plotdirs=($(chia plots show | tail +5))
for plotdir in $plotdirs ; do
if [[ ! -d "$plotdir" ]] ; then
chia plots remove -d "$plotdir"
fi
done
mounts=($(ls -d /mnt/*))
for mp in $mounts ; do
# echo $mp
if (($plotdirs[(I)$mp])); then
# echo "$mp already added"
else
echo chia plots add -d "$mp"
chia plots add -d "$mp"
fi
done
'';
User="chia";
Group="chia";
};
};
timers = {
plotAdder = {
enable = true;
timerConfig = {
OnCalendar = [ "*:00:00" ];
RandomizedDelaySec = "60";
};
wantedBy = [ "timers.target" ];
};
};
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment