summaryrefslogtreecommitdiffstats
path: root/lass/1systems/aergia/physical.nix
blob: 692f68dcc9ba7c6a9679135d4dbb59728e26a41d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
{ config, lib, pkgs, modulesPath, ... }:
{
  imports = [
    ./config.nix
    (modulesPath + "/installer/scan/not-detected.nix")
    <stockholm/lass/2configs/antimicrox>
  ];
  disko.devices = import ./disk.nix;

  networking.hostId = "deadbeef";
  # boot.loader.efi.canTouchEfiVariables = true;
  boot.loader.grub = {
    enable = true;
    device = "/dev/nvme0n1";
    efiSupport = true;
    efiInstallAsRemovable = true;
  };

  boot.kernelPackages = pkgs.linuxPackages_latest;

  boot.kernelParams = [
    # Enable energy savings during sleep
    "mem_sleep_default=deep"

    # use less power with pstate
    "amd_pstate=passive"

    # for ryzenadj -i
    "iomem=relaxed"

    # suspend
    "resume_offset=178345675"
  ];

  boot.kernelModules = [
    # Enables the amd cpu scaling https://www.kernel.org/doc/html/latest/admin-guide/pm/amd-pstate.html
    # On recent AMD CPUs this can be more energy efficient.
    "amd-pstate"
    "kvm-amd"

    # needed for zenstates
    "msr"

    # zenpower
    "zenpower"
  ];

  boot.extraModulePackages = [
    (config.boot.kernelPackages.zenpower.overrideAttrs (old: {
      src = pkgs.fetchFromGitea {
        domain = "git.exozy.me";
        owner = "a";
        repo = "zenpower3";
        rev = "c176fdb0d5bcba6ba2aba99ea36812e40f47751f";
        hash = "sha256-d2WH8Zv7F0phZmEKcDiaak9On+Mo9bAFhMulT/N5FWI=";
      };
    }))
  ];

  # hardware.cpu.amd.updateMicrocode = true;

  services.xserver.videoDrivers = [
    "amdgpu"
  ];

  boot.initrd.availableKernelModules = [
    "nvme"
    "thunderbolt"
    "xhci_pci"
    "usbhid"
  ];

  boot.initrd.kernelModules = [
    "amdgpu"
  ];

  environment.systemPackages = [
    pkgs.vulkan-tools
    pkgs.ryzenadj
    (pkgs.writers.writeDashBin "set_tdp" ''
      set -efux
      watt=$1
      value=$(( $watt * 1000 ))
      ${pkgs.ryzenadj}/bin/ryzenadj --stapm-limit="$value" --fast-limit="$value" --slow-limit="$value"
    '')
  ];

  # textsize
  services.xserver.dpi = 200;

  # corectrl
  programs.corectrl = {
    enable = true;
    gpuOverclock = {
      enable = true;
      ppfeaturemask = "0xffffffff";
    };
  };
  users.users.mainUser.extraGroups = [ "corectrl" ];

  # use newer ryzenadj
  nixpkgs.config.packageOverrides = super: {
    ryzenadj = super.ryzenadj.overrideAttrs (old: {
      version = "unstable-2023-01-15";
      src = pkgs.fetchFromGitHub {
        owner = "FlyGoat";
        repo = "RyzenAdj";
        rev = "1052fb52b2c0e23ac4cd868c4e74d4a9510be57c"; # unstable on 2023-01-15
        sha256 = "sha256-/IxkbQ1XrBrBVrsR4EdV6cbrFr1m+lGwz+rYBqxYG1k=";
      };
    });
  };

  # keyboard quirks
  services.xserver.displayManager.sessionCommands = ''
    ${pkgs.xorg.xmodmap}/bin/xmodmap -e 'keycode 96 = F12 Insert F12 F12' # rebind shift + F12 to shift + insert
  '';
  services.udev.extraHwdb = /* sh */ ''
    # disable back buttons
    evdev:input:b0003v2F24p0135* # /dev/input/event2
      KEYBOARD_KEY_70026=reserved
      KEYBOARD_KEY_70027=reserved
  '';

  # ignore power key

  # update cpu microcode
  hardware.cpu.amd.updateMicrocode = true;

  # suspend to disk
  swapDevices = [{
    device = "/swapfile";
  }];
  boot.resumeDevice = "/dev/mapper/aergia1";
  services.logind.lidSwitch = "suspend-then-hibernate";
  services.logind.extraConfig = ''
    HandlePowerKey=hibernate
  '';

  # firefox touchscreen support
  environment.sessionVariables.MOZ_USE_XINPUT2 = "1";
}