28 lines
788 B
Nix
28 lines
788 B
Nix
{ den, modules, ... }:
|
|
{
|
|
modules.battery-ac-targets = {
|
|
nixos =
|
|
{ ... }:
|
|
{
|
|
services.udev.extraRules = ''
|
|
SUBSYSTEM=="power_supply",ENV{POWER_SUPPLY_ONLINE}=="0", RUN+="/run/current-system/systemd/bin/systemctl start battery.target"
|
|
SUBSYSTEM=="power_supply", ENV{POWER_SUPPLY_ONLINE}=="1", RUN+="/run/current-system/systemd/bin/systemctl start ac.target"
|
|
'';
|
|
systemd.targets = {
|
|
"ac" = {
|
|
description = "On AC power";
|
|
unitConfig = {
|
|
StopWhenUnneeded = "yes";
|
|
};
|
|
};
|
|
"battery" = {
|
|
description = "On battery power";
|
|
unitConfig = {
|
|
StopWhenUnneeded = "yes";
|
|
};
|
|
};
|
|
};
|
|
};
|
|
};
|
|
}
|