dotfiles
My PC Dotfiles & Websitegit clone https://github.com/maydayv7/dotfiles
modules/hardware/cpu.nix (1182B)
1## CPU Configuration ##
2_: {
3 flake.modules.nixos.cpu = {
4 config,
5 options,
6 lib,
7 ...
8 }: let
9 inherit (lib) mkOption optional types;
10 cfg = config.hardware.cpu;
11 opt = options.hardware.cpu;
12 in {
13 options.hardware.cpu = {
14 model = mkOption {
15 description = "CPU Model";
16 type = types.enum [
17 ""
18 "amd"
19 "intel"
20 ];
21 default = "";
22 };
23
24 cores = mkOption {
25 description = "Number of CPU Cores";
26 type = types.int;
27 default = 4;
28 };
29
30 mode = mkOption {
31 description = "CPU Frequency Governor Mode";
32 type = types.enum [
33 "ondemand"
34 "performance"
35 "powersave"
36 ];
37 default = "performance";
38 };
39 };
40
41 config = {
42 warnings = optional (cfg.model == "") (opt.model.description + " is unset");
43 powerManagement.cpuFreqGovernor = cfg.mode;
44 nix.settings.max-jobs = cfg.cores;
45
46 specialisation.powersave.configuration = lib.mkIf (cfg.model != "") {
47 system.nixos.label = "special.powersave";
48 hardware.cpu.mode = lib.mkForce "powersave";
49 };
50 };
51 };
52}