2021-12-06 16:07:01 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.ananicy;
|
|
|
|
configFile = pkgs.writeText "ananicy.conf" (generators.toKeyValue { } cfg.settings);
|
2023-07-15 17:15:38 +00:00
|
|
|
extraRules = pkgs.writeText "extraRules" (concatMapStringsSep "\n" (l: builtins.toJSON l) cfg.extraRules);
|
|
|
|
extraTypes = pkgs.writeText "extraTypes" (concatMapStringsSep "\n" (l: builtins.toJSON l) cfg.extraTypes);
|
|
|
|
extraCgroups = pkgs.writeText "extraCgroups" (concatMapStringsSep "\n" (l: builtins.toJSON l) cfg.extraCgroups);
|
2021-12-06 16:07:01 +00:00
|
|
|
servicename = if ((lib.getName cfg.package) == (lib.getName pkgs.ananicy-cpp)) then "ananicy-cpp" else "ananicy";
|
|
|
|
in
|
|
|
|
{
|
|
|
|
options = {
|
|
|
|
services.ananicy = {
|
2022-09-09 14:08:57 +00:00
|
|
|
enable = mkEnableOption (lib.mdDoc "Ananicy, an auto nice daemon");
|
2021-12-06 16:07:01 +00:00
|
|
|
|
2024-01-02 11:29:13 +00:00
|
|
|
package = mkPackageOption pkgs "ananicy" {
|
|
|
|
example = "ananicy-cpp";
|
2021-12-06 16:07:01 +00:00
|
|
|
};
|
|
|
|
|
2024-01-02 11:29:13 +00:00
|
|
|
rulesProvider = mkPackageOption pkgs "ananicy" {
|
|
|
|
example = "ananicy-cpp";
|
|
|
|
} // {
|
2023-07-15 17:15:38 +00:00
|
|
|
description = lib.mdDoc ''
|
|
|
|
Which package to copy default rules,types,cgroups from.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2021-12-06 16:07:01 +00:00
|
|
|
settings = mkOption {
|
|
|
|
type = with types; attrsOf (oneOf [ int bool str ]);
|
|
|
|
default = { };
|
|
|
|
example = {
|
|
|
|
apply_nice = false;
|
|
|
|
};
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
|
|
|
See <https://github.com/Nefelim4ag/Ananicy/blob/master/ananicy.d/ananicy.conf>
|
2021-12-06 16:07:01 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
extraRules = mkOption {
|
2023-07-15 17:15:38 +00:00
|
|
|
type = with types; listOf attrs;
|
|
|
|
default = [ ];
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2023-07-15 17:15:38 +00:00
|
|
|
Rules to write in 'nixRules.rules'. See:
|
2022-08-12 12:06:08 +00:00
|
|
|
<https://github.com/Nefelim4ag/Ananicy#configuration>
|
|
|
|
<https://gitlab.com/ananicy-cpp/ananicy-cpp/#global-configuration>
|
2021-12-06 16:07:01 +00:00
|
|
|
'';
|
2023-07-15 17:15:38 +00:00
|
|
|
example = [
|
|
|
|
{ name = "eog"; type = "Image-Viewer"; }
|
|
|
|
{ name = "fdupes"; type = "BG_CPUIO"; }
|
|
|
|
];
|
|
|
|
};
|
|
|
|
extraTypes = mkOption {
|
|
|
|
type = with types; listOf attrs;
|
|
|
|
default = [ ];
|
|
|
|
description = lib.mdDoc ''
|
|
|
|
Types to write in 'nixTypes.types'. See:
|
|
|
|
<https://gitlab.com/ananicy-cpp/ananicy-cpp/#types>
|
2021-12-06 16:07:01 +00:00
|
|
|
'';
|
2023-07-15 17:15:38 +00:00
|
|
|
example = [
|
|
|
|
{ type = "my_type"; nice = 19; other_parameter = "value"; }
|
|
|
|
{ type = "compiler"; nice = 19; sched = "batch"; ioclass = "idle"; }
|
|
|
|
];
|
|
|
|
};
|
|
|
|
extraCgroups = mkOption {
|
|
|
|
type = with types; listOf attrs;
|
|
|
|
default = [ ];
|
|
|
|
description = lib.mdDoc ''
|
|
|
|
Cgroups to write in 'nixCgroups.cgroups'. See:
|
|
|
|
<https://gitlab.com/ananicy-cpp/ananicy-cpp/#cgroups>
|
|
|
|
'';
|
|
|
|
example = [
|
|
|
|
{ cgroup = "cpu80"; CPUQuota = 80; }
|
|
|
|
];
|
2021-12-06 16:07:01 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
environment = {
|
|
|
|
systemPackages = [ cfg.package ];
|
|
|
|
etc."ananicy.d".source = pkgs.runCommandLocal "ananicyfiles" { } ''
|
|
|
|
mkdir -p $out
|
|
|
|
# ananicy-cpp does not include rules or settings on purpose
|
2023-07-15 17:15:38 +00:00
|
|
|
if [[ -d "${cfg.rulesProvider}/etc/ananicy.d/00-default" ]]; then
|
|
|
|
cp -r ${cfg.rulesProvider}/etc/ananicy.d/* $out
|
|
|
|
else
|
|
|
|
cp -r ${cfg.rulesProvider}/* $out
|
|
|
|
fi
|
|
|
|
|
|
|
|
# configured through .setings
|
|
|
|
rm -f $out/ananicy.conf
|
2021-12-06 16:07:01 +00:00
|
|
|
cp ${configFile} $out/ananicy.conf
|
2023-07-15 17:15:38 +00:00
|
|
|
${optionalString (cfg.extraRules != [ ]) "cp ${extraRules} $out/nixRules.rules"}
|
|
|
|
${optionalString (cfg.extraTypes != [ ]) "cp ${extraTypes} $out/nixTypes.types"}
|
|
|
|
${optionalString (cfg.extraCgroups != [ ]) "cp ${extraCgroups} $out/nixCgroups.cgroups"}
|
2021-12-06 16:07:01 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
# ananicy and ananicy-cpp have different default settings
|
|
|
|
services.ananicy.settings =
|
|
|
|
let
|
|
|
|
mkOD = mkOptionDefault;
|
|
|
|
in
|
|
|
|
{
|
|
|
|
cgroup_load = mkOD true;
|
|
|
|
type_load = mkOD true;
|
|
|
|
rule_load = mkOD true;
|
|
|
|
apply_nice = mkOD true;
|
|
|
|
apply_ioclass = mkOD true;
|
|
|
|
apply_ionice = mkOD true;
|
|
|
|
apply_sched = mkOD true;
|
|
|
|
apply_oom_score_adj = mkOD true;
|
|
|
|
apply_cgroup = mkOD true;
|
|
|
|
} // (if ((lib.getName cfg.package) == (lib.getName pkgs.ananicy-cpp)) then {
|
|
|
|
# https://gitlab.com/ananicy-cpp/ananicy-cpp/-/blob/master/src/config.cpp#L12
|
|
|
|
loglevel = mkOD "warn"; # default is info but its spammy
|
2022-01-19 23:45:15 +00:00
|
|
|
cgroup_realtime_workaround = mkOD config.systemd.enableUnifiedCgroupHierarchy;
|
2023-07-15 17:15:38 +00:00
|
|
|
log_applied_rule = mkOD false;
|
2021-12-06 16:07:01 +00:00
|
|
|
} else {
|
|
|
|
# https://github.com/Nefelim4ag/Ananicy/blob/master/ananicy.d/ananicy.conf
|
|
|
|
check_disks_schedulers = mkOD true;
|
|
|
|
check_freq = mkOD 5;
|
|
|
|
});
|
|
|
|
|
|
|
|
systemd = {
|
|
|
|
# https://gitlab.com/ananicy-cpp/ananicy-cpp/#cgroups applies to both ananicy and -cpp
|
|
|
|
enableUnifiedCgroupHierarchy = mkDefault false;
|
|
|
|
packages = [ cfg.package ];
|
|
|
|
services."${servicename}" = {
|
|
|
|
wantedBy = [ "default.target" ];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
meta = {
|
|
|
|
maintainers = with maintainers; [ artturin ];
|
|
|
|
};
|
|
|
|
}
|