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

Merge pull request #21 from diniamo/nix-package-no-empty-config

nix: add package option, avoid config file on empty settings
This commit is contained in:
raf 2025-05-15 23:43:07 +03:00 committed by GitHub
commit 1546da382e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

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