9 cfg = config.services.ananicy;
10 configFile = pkgs.writeText "ananicy.conf" (lib.generators.toKeyValue { } cfg.settings);
11 extraRules = pkgs.writeText "extraRules" (
12 lib.concatMapStringsSep "\n" (l: builtins.toJSON l) cfg.extraRules
14 extraTypes = pkgs.writeText "extraTypes" (
15 lib.concatMapStringsSep "\n" (l: builtins.toJSON l) cfg.extraTypes
17 extraCgroups = pkgs.writeText "extraCgroups" (
18 lib.concatMapStringsSep "\n" (l: builtins.toJSON l) cfg.extraCgroups
21 if ((lib.getName cfg.package) == (lib.getName pkgs.ananicy-cpp)) then "ananicy-cpp" else "ananicy";
22 # Ananicy-CPP with BPF is not supported on hardened kernels https://github.com/NixOS/nixpkgs/issues/327382
24 if (servicename == "ananicy-cpp" && config.boot.kernelPackages.isHardened) then
25 (cfg.package { withBpf = false; })
30 options.services.ananicy = {
31 enable = lib.mkEnableOption "Ananicy, an auto nice daemon";
33 package = lib.mkPackageOption pkgs "ananicy" { example = "ananicy-cpp"; };
35 rulesProvider = lib.mkPackageOption pkgs "ananicy" { example = "ananicy-cpp"; } // {
37 Which package to copy default rules,types,cgroups from.
41 settings = lib.mkOption {
54 See <https://github.com/Nefelim4ag/Ananicy/blob/master/ananicy.d/ananicy.conf>
58 extraRules = lib.mkOption {
59 type = with lib.types; listOf attrs;
62 Rules to write in 'nixRules.rules'. See:
63 <https://github.com/Nefelim4ag/Ananicy#configuration>
64 <https://gitlab.com/ananicy-cpp/ananicy-cpp/#global-configuration>
69 type = "Image-Viewer";
77 extraTypes = lib.mkOption {
78 type = with lib.types; listOf attrs;
81 Types to write in 'nixTypes.types'. See:
82 <https://gitlab.com/ananicy-cpp/ananicy-cpp/#types>
88 other_parameter = "value";
98 extraCgroups = lib.mkOption {
99 type = with lib.types; listOf attrs;
102 Cgroups to write in 'nixCgroups.cgroups'. See:
103 <https://gitlab.com/ananicy-cpp/ananicy-cpp/#cgroups>
114 config = lib.mkIf cfg.enable {
116 systemPackages = [ finalPackage ];
117 etc."ananicy.d".source = pkgs.runCommandLocal "ananicyfiles" { } ''
119 # ananicy-cpp does not include rules or settings on purpose
120 if [[ -d "${cfg.rulesProvider}/etc/ananicy.d/00-default" ]]; then
121 cp -r ${cfg.rulesProvider}/etc/ananicy.d/* $out
123 cp -r ${cfg.rulesProvider}/* $out
126 # configured through .setings
127 rm -f $out/ananicy.conf
128 cp ${configFile} $out/ananicy.conf
129 ${lib.optionalString (cfg.extraRules != [ ]) "cp ${extraRules} $out/nixRules.rules"}
130 ${lib.optionalString (cfg.extraTypes != [ ]) "cp ${extraTypes} $out/nixTypes.types"}
131 ${lib.optionalString (cfg.extraCgroups != [ ]) "cp ${extraCgroups} $out/nixCgroups.cgroups"}
135 # ananicy and ananicy-cpp have different default settings
136 services.ananicy.settings =
138 mkOD = lib.mkOptionDefault;
141 cgroup_load = mkOD true;
142 type_load = mkOD true;
143 rule_load = mkOD true;
144 apply_nice = mkOD true;
145 apply_ioclass = mkOD true;
146 apply_ionice = mkOD true;
147 apply_sched = mkOD true;
148 apply_oom_score_adj = mkOD true;
149 apply_cgroup = mkOD true;
152 if servicename == "ananicy-cpp" then
154 # https://gitlab.com/ananicy-cpp/ananicy-cpp/-/blob/master/src/config.cpp#L12
155 loglevel = mkOD "warn"; # default is info but its spammy
156 cgroup_realtime_workaround = true;
157 log_applied_rule = mkOD false;
161 # https://github.com/Nefelim4ag/Ananicy/blob/master/ananicy.d/ananicy.conf
162 check_disks_schedulers = mkOD true;
168 packages = [ finalPackage ];
169 services."${servicename}" = {
170 wantedBy = [ "default.target" ];
175 meta.maintainers = with lib.maintainers; [ artturin ];