1
Fork 0
mirror of https://github.com/RGBCube/superfreq synced 2025-07-28 09:27:44 +00:00

nix: package superfreq; add NixOS module

This commit is contained in:
NotAShelf 2025-05-14 02:37:23 +03:00
parent fd23e1b9aa
commit 8f04194f95
No known key found for this signature in database
GPG key ID: 29D95B64378DB4BF
4 changed files with 125 additions and 33 deletions

66
nix/module.nix Normal file
View file

@ -0,0 +1,66 @@
inputs: {
config,
pkgs,
lib,
...
}: let
inherit (lib.modules) mkIf;
inherit (lib.options) mkOption mkEnableOption;
inherit (lib.types) submodule;
inherit (lib.meta) getExe;
cfg = config.programs.superfreq;
defaultPackage = inputs.self.packages.${pkgs.stdenv.system}.default;
format = pkgs.formats.toml {};
in {
options.programs.superfreq = {
enable = mkEnableOption "Automatic CPU speed & power optimizer for Linux";
settings = mkOption {
default = {};
type = submodule {freeformType = format.type;};
description = "Configuration for Superfreq.";
};
};
config = mkIf cfg.enable {
environment.systemPackages = [defaultPackage];
systemd = {
packages = [defaultPackage];
services.superfreq = {
wantedBy = ["multi-user.target"];
serviceConfig = let
cfgFile = format.generate "superfreq-config.toml" cfg.settings;
in {
Environment = ["SUPERFREQ_CONFIG=${cfgFile}"];
WorkingDirectory = "";
ExecStart = "${getExe defaultPackage} daemon --verbose";
Restart = "on-failure";
RuntimeDirectory = "superfreq";
RuntimeDirectoryMode = "0755";
};
};
};
assertions = [
{
assertion = !config.services.power-profiles-daemon.enable;
message = ''
You have set services.power-profiles-daemon.enable = true;
which conflicts with Superfreq.
'';
}
{
assertion = !config.programs.auto-cpufreq.enable;
message = ''
You have set programs.auto-cpufreq.enable = true;
which conflicts with Superfreq.
'';
}
];
};
}