diff --git a/flake.nix b/flake.nix index b097bacd..b3de377a 100644 --- a/flake.nix +++ b/flake.nix @@ -119,6 +119,7 @@ kernel.patches = [ "cjktty" ]; impermanence.enable = true; networking.hostname = "pc"; + sysctl.laptop-mode = 5; }; hardware = { diff --git a/modules/system/default.nix b/modules/system/default.nix index 64f49a4f..c7c70d4a 100644 --- a/modules/system/default.nix +++ b/modules/system/default.nix @@ -15,6 +15,7 @@ inputs: ./security.nix ./sops.nix ./user.nix + ./sysctl.nix ]; config = { @@ -22,13 +23,6 @@ inputs: time.timeZone = "Asia/Shanghai"; boot = { - kernel.sysctl = - { - "vm.oom_kill_allocating_task" = true; - "vm.oom_dump_tasks" = false; - "vm.overcommit_memory" = 1; - "kernel.sysrq" = 438; - }; supportedFilesystems = [ "ntfs" ]; consoleLogLevel = 7; }; diff --git a/modules/system/sysctl.nix b/modules/system/sysctl.nix new file mode 100644 index 00000000..9f04f5f8 --- /dev/null +++ b/modules/system/sysctl.nix @@ -0,0 +1,24 @@ +inputs: +{ + options.nixos.system.sysctl = let inherit (inputs.lib) mkOption types; in + { + laptop-mode = mkOption { type = types.nullOr types.int; default = null; }; + }; + config = + let + inherit (inputs.lib) mkIf mkMerge; + inherit (inputs.config.nixos.system) sysctl; + in mkMerge + [ + { + boot.kernel.sysctl = + { + "vm.oom_kill_allocating_task" = true; + "vm.oom_dump_tasks" = false; + "vm.overcommit_memory" = 1; + "kernel.sysrq" = 438; + }; + } + (mkIf (sysctl.laptop-mode != null) { boot.kernel.sysctl."vm.laptop_mode" = sysctl.laptop-mode; }) + ]; +}