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 }: 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,23 +29,18 @@ in {
}; };
config = mkIf cfg.enable { config = mkIf cfg.enable {
environment.systemPackages = [defaultPackage]; environment.systemPackages = [cfg.package];
systemd = { systemd.services.superfreq = {
packages = [defaultPackage]; wantedBy = ["multi-user.target"];
services.superfreq = { serviceConfig = {
wantedBy = ["multi-user.target"]; Environment = optional (cfg.settings != {}) ["SUPERFREQ_CONFIG=${cfgFile}"];
serviceConfig = let WorkingDirectory = "";
cfgFile = format.generate "superfreq-config.toml" cfg.settings; ExecStart = "${getExe cfg.package} daemon --verbose";
in { Restart = "on-failure";
Environment = ["SUPERFREQ_CONFIG=${cfgFile}"];
WorkingDirectory = "";
ExecStart = "${getExe defaultPackage} daemon --verbose";
Restart = "on-failure";
RuntimeDirectory = "superfreq"; RuntimeDirectory = "superfreq";
RuntimeDirectoryMode = "0755"; RuntimeDirectoryMode = "0755";
};
}; };
}; };
@ -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.
''; '';
} }