Hi all,
I made a very simple module that creates systemd targets for AC and battery power states, allowing you to bind services and sockets to run only when plugged in.
Here is an example that will turn off borg, syncthing and ipfs when your laptop is unplugged.
{
inputs.power-targets = {
url = "git+https://seed.radicle.garden/z3nj6UEy3kcz2dVNNSe1FH6Je9PKH.git";
};
outputs = { inputs, ... }: {
nixosConfigurations.your-machine = nixpkgs.lib.nixosSystem {
modules = [
inputs.power-targets
{
powerTargets = {
acName = "AC"; # name in /sys/class/power_supply/
services = {
syncthing.enable = true;
borgbackup-job-borgbase.enable = true;
};
sockets = {
ipfs-api.enable = true;
};
};
}
];
};
};
}