Skip to content

Simple linux service for giving other services or apps some rest based on power conditions

License

Notifications You must be signed in to change notification settings

Lenivaya/resterrs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

54 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

resterrs 😴

Simple linux service for giving other services or apps some rest based on power conditions

CI License

monkey sleeping

Table of contents

Use cases

  • Managing of user services
    • automatic start/stop of user services based on power conditions
  • Managing of system services
    • automatic start/stop of system services based on power conditions
  • Managing of user apps
    • automatic kill of apps based on power conditions
  • Managing of arbitrary commands
    • running commands based on power conditions

By using word services I mean systemd services

Use cases explanation

A good config example is worth a thousand words.

This application was born from my specific workflow needs. I use a laptop with multiple services and applications that are connected to external monitors and power. In this setup, I want everything running at full capacity.

However, there's often a case where I unplug my laptop, or it's unplugged by other means (power shortages due to war), when that happens I definitely wouldn't want to do manual work stopping services I don't need while running on battery. Some examples include:

  • deskflow: For sharing mouse/keyboard between computers
  • syncthing: For home network file sharing (meaningless when not at home)
  • picom: For desktop compositing and pretty shadows/animations
  • easyeffects: For audio processing
  • And any other services that can be automatically managed based on power conditions

Disabling and enabling such things manually is a pain in the ass, so it's definitely better to have some minimal automation for it. Based on the first-glance research, something similar can be achieved through writing udev rules:

SUBSYSTEM=="power_supply",ENV{POWER_SUPPLY_ONLINE}=="0",RUN+="/bin/killcompton.sh"
SUBSYSTEM=="power_supply",ENV{POWER_SUPPLY_ONLINE}=="1",RUN+="/bin/startcompton.sh"

However, this solution is cumbersome to maintain and lacks user-friendly configuration options. So let's get our hands dirty and write some things on rust.

Usage

NixOS

To start using this service on NixOS, you must add this repo as input to your flake:

{
  inputs = {
    resterrs = {
      url = "github:Lenivaya/resterrs";
      inputs.nixpkgs.follows = "nixpkgs";
    };
  };
  # ...
}

then import nixos module from this flake:

{
  imports = [
    inputs.resterrs.nixosModules.default
  ];
}

and then you can configure it according to the configuration in nix section

Configuration

Configuration examples

Configuration in TOML

config.toml

system_services_to_stop = [
    "fwupd",
    "syncthing",
    "bpftune"
]
user_services_to_stop = [
    "kdeconnect",
    "picom",
    "easyeffects"
]
apps_to_stop = [
    "telegram-desktop",
    "vesktop",
    "easyeffects"
]
commands_unplugged = [
    "bluetoothctl power off"
]
commands_plugged = [
    "bluetoothctl power on"
]
username = "leniviy"

Configuration in Nix

{
  services.resterrs = {
    enable = true;
    settings = {
      system_services_to_stop = [
        "fwupd"
        "syncthing"
        "bpftune"
      ];
      user_services_to_stop = [
        "kdeconnect"
        "picom"
        "easyeffects"
      ];
      apps_to_stop = [
        "telegram-desktop"
        "vesktop"
        "deskflow"
      ];
      commands_unplugged = [
        "bluetoothctl power off"
      ];
      commands_plugged = [
        "bluetoothctl power on"
      ];
      username = config.user.name;
    };
    extraServicePackages = with pkgs; [
      bluez
    ];
  };
}

About

Simple linux service for giving other services or apps some rest based on power conditions

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published