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

nix: add package option, avoid empty config, move to services

This commit is contained in:
diniamo 2025-05-15 20:41:53 +02:00
parent 5531358da2
commit 723ce1b7b8

View file

@ -5,18 +5,21 @@ inputs: {
... ...
}: let }: let
inherit (lib.modules) mkIf; inherit (lib.modules) mkIf;
inherit (lib.options) mkOption mkEnableOption; inherit (lib.options) mkOption mkEnableOption mkPackageOption;
inherit (lib.types) submodule; inherit (lib.types) submodule;
inherit (lib.lists) optional;
inherit (lib.meta) getExe; inherit (lib.meta) getExe;
cfg = config.programs.superfreq; cfg = config.services.superfreq;
defaultPackage = inputs.self.packages.${pkgs.stdenv.system}.default;
format = pkgs.formats.toml {}; format = pkgs.formats.toml {};
cfgFile = format.generate "superfreq-config.toml" cfg.settings;
in { in {
options.programs.superfreq = { options.services.superfreq = {
enable = mkEnableOption "Automatic CPU speed & power optimizer for Linux"; enable = mkEnableOption "Automatic CPU speed & power optimizer for Linux";
package = mkPackageOption inputs.self.packages.${pkgs.stdenv.system} "superfreq" {
pkgsText = "self.packages.\${pkgs.stdenv.system}";
};
settings = mkOption { settings = mkOption {
default = {}; default = {};
@ -26,25 +29,20 @@ in {
}; };
config = mkIf cfg.enable { config = mkIf cfg.enable {
environment.systemPackages = [defaultPackage]; environment.systemPackages = [cfg.package];
systemd = { systemd.services.superfreq = {
packages = [defaultPackage];
services.superfreq = {
wantedBy = ["multi-user.target"]; wantedBy = ["multi-user.target"];
serviceConfig = let serviceConfig = {
cfgFile = format.generate "superfreq-config.toml" cfg.settings; Environment = optional (cfg.settings != {}) ["SUPERFREQ_CONFIG=${cfgFile}"];
in {
Environment = ["SUPERFREQ_CONFIG=${cfgFile}"];
WorkingDirectory = ""; WorkingDirectory = "";
ExecStart = "${getExe defaultPackage} daemon --verbose"; ExecStart = "${getExe cfg.package} daemon --verbose";
Restart = "on-failure"; Restart = "on-failure";
RuntimeDirectory = "superfreq"; RuntimeDirectory = "superfreq";
RuntimeDirectoryMode = "0755"; RuntimeDirectoryMode = "0755";
}; };
}; };
};
assertions = [ assertions = [
{ {
@ -57,7 +55,7 @@ in {
{ {
assertion = !config.services.auto-cpufreq.enable; assertion = !config.services.auto-cpufreq.enable;
message = '' message = ''
You have set programs.auto-cpufreq.enable = true; You have set services.auto-cpufreq.enable = true;
which conflicts with Superfreq. which conflicts with Superfreq.
''; '';
} }