]> Git — Sourcephile - julm/julm-nix.git/blob - hosts/patate/hardware.nix
acpid: use acEventCommands
[julm/julm-nix.git] / hosts / patate / hardware.nix
1 { config, lib, pkgs, hostName, ... }:
2 {
3 hardware.cpu.intel.updateMicrocode = true;
4 hardware.opengl.extraPackages = [
5 pkgs.intel-media-driver # LIBVA_DRIVER_NAME=iHD
6 pkgs.vaapiIntel # LIBVA_DRIVER_NAME=i965 (older but works better for Firefox/Chromium)
7 pkgs.vaapiVdpau
8 pkgs.libvdpau-va-gl
9 ];
10 powerManagement.cpuFreqGovernor = lib.mkDefault "ondemand";
11 services.thinkfan = {
12 enable = true;
13 levels = [
14 [0 0 57]
15 [1 56 62]
16 [2 61 65]
17 [3 64 66]
18 [4 65 68]
19 [5 67 71]
20 [6 70 76]
21 [7 75 81]
22 [127 80 32767]
23 ];
24 };
25
26 # https://bugzilla.kernel.org/show_bug.cgi?id=110941
27 boot.kernelParams = [ "intel_pstate=no_hwp" ];
28 boot.kernelModules = [ "kvm-intel" ];
29 boot.cleanTmpDir = true;
30 boot.tmpOnTmpfs = true;
31 boot.extraModulePackages = [
32 #config.boot.kernelPackages.exfat-nofuse
33 ];
34 boot.loader.grub = {
35 enable = true;
36 version = 2;
37 device = "/dev/disk/by-id/ata-CT250MX500SSD1_2004E2849DD1";
38 configurationLimit = 3;
39 #zfsSupport = true;
40 /*
41 efiSupport = true;
42 efi = {
43 canTouchEfiVariables = false;
44 efiSysMountPoint = "/boot/efi";
45 };
46 */
47 #enableCryptodisk = true;
48 };
49 services.acpid = {
50 enable = true;
51 handlers = {
52 brightnessDown = {
53 event = "video/brightnessdown.*";
54 action = "${pkgs.acpilight}/bin/xbacklight -dec 10";
55 };
56 brightnessUp = {
57 event = "video/brightnessup.*";
58 action = "${pkgs.acpilight}/bin/xbacklight -inc 10";
59 };
60 };
61 acEventCommands = ''
62 vals=($1)
63 case ''${vals[3]} in
64 00000000) # unplugged
65 ${pkgs.linuxPackages.cpupower}/bin/cpupower frequency-set -g powersave;;
66 00000001) # plugged in
67 ${pkgs.linuxPackages.cpupower}/bin/cpupower frequency-set -g ondemand;;
68 esac
69 '';
70 };
71
72 fileSystems."/boot" =
73 { device = "/dev/disk/by-partlabel/${hostName}_ssd_boot";
74 fsType = "ext2";
75 };
76 fileSystems."/boot/efi" =
77 { device = "/dev/disk/by-partlabel/${hostName}_ssd_efi";
78 fsType = "vfat";
79 };
80 swapDevices = [
81 { device = "/dev/disk/by-partlabel/${hostName}_ssd_swap";
82 randomEncryption = {
83 enable = true;
84 cipher = "aes-xts-plain64";
85 source = "/dev/urandom";
86 };
87 }
88 ];
89 zramSwap = {
90 enable = true;
91 algorithm = lib.mkDefault "zstd";
92 # There is little point creating a zram of greater
93 # than twice the size of memory
94 # since we expect a 2:1 compression ratio.
95 # Note that zram uses about 0.1% of the size of the disk
96 # when not in use so a huge zram is wasteful.
97 memoryPercent = lib.mkDefault 150;
98 # Linux supports multithreaded compression for 1 device since 3.15.
99 # See https://lkml.org/lkml/2014/2/28/404 for details.
100 swapDevices = lib.mkDefault 1;
101 };
102 boot.kernel.sysctl = {
103 # Increase cache pressure, which increases the tendency of the kernel to
104 # reclaim memory used for caching of directory and inode objects. You will use
105 # less memory over a longer period of time. The performance hit is negated by
106 # the downside of swapping sooner.
107 "vm.vfs_cache_pressure" = lib.mkDefault 500;
108
109 # Increasing how aggressively the kernel will swap memory pages since we are
110 # using ZRAM first.
111 "vm.swappiness" = lib.mkDefault 100;
112
113 # Background processes will start writing right away when it hits the 1% limit
114 "vm.dirty_background_ratio" = lib.mkDefault 1;
115
116 # The system won’t force synchronous I/O until it gets to 50% dirty_ratio.
117 "vm.dirty_ratio" = lib.mkDefault 50;
118 };
119
120 # The 32-bit host id of the host, formatted as 8 hexadecimal characters.
121 # You should try to make this id unique among your hosts.
122 # Manually generated with : head -c4 /dev/urandom | od -A none -t x4 | cut -d ' ' -f 2
123 networking.hostId = "ec2adb40";
124
125 # none is the recommended elevator with ZFS (which has its own I/O scheduler)
126 # and/or for SSD, whereas HDD could use mq-deadline.
127 services.udev.extraRules = ''
128 # set none scheduler for non-rotating disks
129 ACTION=="add|change", KERNEL=="sd[a-z]", ATTR{queue/rotational}=="0", ATTR{queue/scheduler}="none"
130 '';
131
132 boot.supportedFilesystems = [ "ntfs" "vfat" "zfs" ];
133 boot.initrd.supportedFilesystems = [ "zfs" ];
134 boot.initrd.availableKernelModules = [
135 "ahci"
136 "drbg"
137 "ehci_pci"
138 "gf128mul"
139 "hmac"
140 "sd_mod"
141 ];
142
143 boot.zfs.forceImportAll = false;
144 boot.zfs.forceImportRoot = false;
145 boot.zfs.enableUnstable = false;
146 boot.zfs.requestEncryptionCredentials = [ hostName ];
147 services.zfs.autoScrub.enable = true;
148
149 fileSystems."/" =
150 { device = "${hostName}/root";
151 fsType = "zfs";
152 };
153 fileSystems."/nix" =
154 { device = "${hostName}/nix";
155 fsType = "zfs";
156 };
157 fileSystems."/home/sevy" =
158 { device = "${hostName}/home";
159 fsType = "zfs";
160 };
161 fileSystems."/home/sevy/Documents" =
162 { device = "${hostName}/home/Documents";
163 fsType = "zfs";
164 };
165 fileSystems."/home/sevy/Images" =
166 { device = "${hostName}/home/Images";
167 fsType = "zfs";
168 };
169 fileSystems."/home/sevy/Téléchargements" =
170 { device = "${hostName}/home/Downloads";
171 fsType = "zfs";
172 };
173 fileSystems."/home/sevy/.thunderbird" =
174 { device = "${hostName}/home/Mails";
175 fsType = "zfs";
176 };
177 fileSystems."/home/sevy/Vidéos" =
178 { device = "${hostName}/home/Videos";
179 fsType = "zfs";
180 };
181 fileSystems."/var" =
182 { device = "${hostName}/var";
183 fsType = "zfs";
184 };
185 fileSystems."/var/cache" =
186 { device = "${hostName}/var/cache";
187 fsType = "zfs";
188 };
189 fileSystems."/var/log" =
190 { device = "${hostName}/var/log";
191 fsType = "zfs";
192 };
193 fileSystems."/var/tmp" =
194 { device = "${hostName}/var/tmp";
195 fsType = "zfs";
196 };
197
198 }