watt: init at 1.2.0

This commit is contained in:
Soliprem
2026-06-29 23:56:06 +02:00
parent 1eceba956f
commit 451d7918ff
6 changed files with 158 additions and 0 deletions
@@ -16,6 +16,8 @@
- [Nezha](https://github.com/nezhahq/nezha), a self-hosted, lightweight server and website monitoring and O&M tool. Available as [services.nezha](#opt-services.nezha.enable).
- [Watt](https://github.com/NotAShelf/watt), a CPU frequency and power management daemon for Linux. Available as [services.watt](#opt-services.watt.enable).
- [mail-tlsa-check-exporter](https://github.com/ietf-tools/mail-tlsa-check-exporter), validates SMTP / IMAP server certificates against a TLSA record as a Prometheus exporter. Available as [services.prometheus.exporters.mail-tlsa-check](#opt-services.prometheus.exporters.mail-tlsa-check.enable).
- [CastSponsorSkip](https://github.com/gabe565/CastSponsorSkip/), skips YouTube sponsorships (and sometimes ads) on all local Google Cast devices.
+1
View File
@@ -727,6 +727,7 @@
./services/hardware/usbmuxd.nix
./services/hardware/usbrelayd.nix
./services/hardware/vdr.nix
./services/hardware/watt.nix
./services/home-automation/deye-dummycloud.nix
./services/home-automation/ebusd.nix
./services/home-automation/esphome.nix
+71
View File
@@ -0,0 +1,71 @@
{
config,
pkgs,
lib,
...
}:
let
inherit (lib)
mkIf
mkOption
mkEnableOption
mkPackageOption
getExe
;
inherit (lib.types) submodule;
cfg = config.services.watt;
format = pkgs.formats.toml { };
cfgFile = format.generate "watt-config.toml" cfg.settings;
conflictingServices = [
"power-profiles-daemon"
"auto-cpufreq"
"tlp"
"cpupower-gui"
"thermald"
];
in
{
options.services.watt = {
enable = mkEnableOption "automatic CPU speed & power optimizer for Linux";
package = mkPackageOption pkgs "watt" { };
settings = mkOption {
default = { };
type = submodule { freeformType = format.type; };
description = "Configuration for Watt. Options at https://github.com/notaShelf/watt";
};
};
config = mkIf cfg.enable {
assertions = map (service: {
assertion = !config.services.${service}.enable;
message = "You have set services.${service}.enable = true; which conflicts with Watt.";
}) conflictingServices;
environment.systemPackages = [ cfg.package ];
# This is necessary for the Watt CLI. The environment variable
# passed to the systemd service will take priority in read order.
environment.etc."watt.toml".source = cfgFile;
services.dbus.packages = [ cfg.package ];
systemd.services.watt = {
wantedBy = [ "multi-user.target" ];
conflicts = map (service: "${service}.service") conflictingServices;
serviceConfig = {
WorkingDirectory = "";
ExecStart = getExe cfg.package;
Restart = "on-failure";
RuntimeDirectory = "watt";
RuntimeDirectoryMode = "0755";
};
};
};
}
+1
View File
@@ -1825,6 +1825,7 @@ in
wasabibackend = runTest ./wasabibackend.nix;
wastebin = runTest ./wastebin.nix;
watchdogd = runTest ./watchdogd.nix;
watt = runTest ./watt.nix;
webhook = runTest ./webhook.nix;
weblate = runTest ./web-apps/weblate.nix;
wg-access-server = runTest ./wg-access-server.nix;
+19
View File
@@ -0,0 +1,19 @@
{ pkgs, lib, ... }:
{
name = "watt";
meta.maintainers = with lib.maintainers; [ Soliprem ];
nodes.machine = _: {
services.watt.enable = true;
};
testScript = ''
machine.wait_for_unit("watt.service")
machine.succeed("watt --version | grep ${pkgs.watt.version}")
machine.wait_until_succeeds("busctl --system status net.hadess.PowerProfiles")
machine.wait_until_succeeds("busctl --system status dev.notashelf.Watt")
machine.succeed("busctl --system introspect net.hadess.PowerProfiles /net/hadess/PowerProfiles net.hadess.PowerProfiles")
machine.succeed("busctl --system introspect dev.notashelf.Watt /dev/notashelf/Watt dev.notashelf.Watt")
machine.succeed("busctl --system get-property dev.notashelf.Watt /dev/notashelf/Watt dev.notashelf.Watt Version | grep ${pkgs.watt.version}")
'';
}
+64
View File
@@ -0,0 +1,64 @@
{
lib,
stdenv,
rustPlatform,
fetchFromGitHub,
versionCheckHook,
nixosTests,
nix-update-script,
}:
rustPlatform.buildRustPackage (finalAttrs: {
pname = "watt";
version = "1.2.0";
__structuredAttrs = true;
src = fetchFromGitHub {
owner = "notashelf";
repo = "watt";
tag = "v${finalAttrs.version}";
hash = "sha256-mb7z1NHhS5DtFNzi/H/XQR5RfhYY5ELxJg8DFMWtzmU=";
};
cargoHash = "sha256-2eHr88gMfiwimpcPa/ZQ08C2YalO91fH6BSvcyLNcso=";
cargoBuildFlags = [
"-p=watt"
"-p=xtask"
];
enableParallelBuilding = true;
useNextest = true;
nativeInstallCheckInputs = [ versionCheckHook ];
doInstallCheck = true;
# xtask doesn't support passing --target
# but nix hooks expect the folder structure from when it's set
env.CARGO_BUILD_TARGET = stdenv.hostPlatform.rust.cargoShortTarget;
postInstall =
lib.optionalString (stdenv.buildPlatform.canExecute stdenv.hostPlatform) ''
# Install required files with the 'dist' task
$out/bin/xtask dist --completions-dir $out/share/completions
''
+ ''
# Avoid populating PATH with an 'xtask' cmd
rm $out/bin/xtask
install -Dm644 dbus/net.hadess.PowerProfiles.conf \
$out/share/dbus-1/system.d/net.hadess.PowerProfiles.conf
'';
passthru = {
tests.nixos = nixosTests.watt;
updateScript = nix-update-script { };
};
meta = {
description = "Modern CPU frequency and power management utility for Linux";
homepage = "https://github.com/NotAShelf/watt";
license = lib.licenses.mpl20;
maintainers = with lib.maintainers; [ Soliprem ];
mainProgram = "watt";
platforms = lib.platforms.linux;
};
})