1 { config, lib, pkgs, ... }:
6 cfg = config.services.ananicy;
7 configFile = pkgs.writeText "ananicy.conf" (generators.toKeyValue { } cfg.settings);
8 extraRules = pkgs.writeText "extraRules" cfg.extraRules;
9 servicename = if ((lib.getName cfg.package) == (lib.getName pkgs.ananicy-cpp)) then "ananicy-cpp" else "ananicy";
14 enable = mkEnableOption (lib.mdDoc "Ananicy, an auto nice daemon");
18 default = pkgs.ananicy;
19 defaultText = literalExpression "pkgs.ananicy";
20 example = literalExpression "pkgs.ananicy-cpp";
21 description = lib.mdDoc ''
22 Which ananicy package to use.
27 type = with types; attrsOf (oneOf [ int bool str ]);
32 description = lib.mdDoc ''
33 See <https://github.com/Nefelim4ag/Ananicy/blob/master/ananicy.d/ananicy.conf>
37 extraRules = mkOption {
40 description = lib.mdDoc ''
41 Extra rules in json format on separate lines. See:
42 <https://github.com/Nefelim4ag/Ananicy#configuration>
43 <https://gitlab.com/ananicy-cpp/ananicy-cpp/#global-configuration>
45 example = literalExpression ''
47 { "name": "eog", "type": "Image-View" }
48 { "name": "fdupes", "type": "BG_CPUIO" }
56 config = mkIf cfg.enable {
58 systemPackages = [ cfg.package ];
59 etc."ananicy.d".source = pkgs.runCommandLocal "ananicyfiles" { } ''
61 # ananicy-cpp does not include rules or settings on purpose
62 cp -r ${pkgs.ananicy}/etc/ananicy.d/* $out
64 cp ${configFile} $out/ananicy.conf
65 ${optionalString (cfg.extraRules != "") "cp ${extraRules} $out/nixRules.rules"}
69 # ananicy and ananicy-cpp have different default settings
70 services.ananicy.settings =
72 mkOD = mkOptionDefault;
75 cgroup_load = mkOD true;
76 type_load = mkOD true;
77 rule_load = mkOD true;
78 apply_nice = mkOD true;
79 apply_ioclass = mkOD true;
80 apply_ionice = mkOD true;
81 apply_sched = mkOD true;
82 apply_oom_score_adj = mkOD true;
83 apply_cgroup = mkOD true;
84 } // (if ((lib.getName cfg.package) == (lib.getName pkgs.ananicy-cpp)) then {
85 # https://gitlab.com/ananicy-cpp/ananicy-cpp/-/blob/master/src/config.cpp#L12
86 loglevel = mkOD "warn"; # default is info but its spammy
87 cgroup_realtime_workaround = mkOD config.systemd.enableUnifiedCgroupHierarchy;
89 # https://github.com/Nefelim4ag/Ananicy/blob/master/ananicy.d/ananicy.conf
90 check_disks_schedulers = mkOD true;
95 # https://gitlab.com/ananicy-cpp/ananicy-cpp/#cgroups applies to both ananicy and -cpp
96 enableUnifiedCgroupHierarchy = mkDefault false;
97 packages = [ cfg.package ];
98 services."${servicename}" = {
99 wantedBy = [ "default.target" ];
105 maintainers = with maintainers; [ artturin ];