Skip to content

Commit

Permalink
nixos/laptop: init
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagokokada committed Sep 20, 2023
1 parent d611822 commit 8287125
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 73 deletions.
39 changes: 18 additions & 21 deletions hosts/hachune-nixos/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,25 @@ in
mediaDir = "/mnt/media/${config.meta.username}";
};

nixos.server = {
enable = true;
iperf3.enable = true;
jellyfin.enable = true;
networkd.enable = true;
plex.enable = true;
rtorrent.enable = true;
ssh.enable = true;
tailscale.enable = true;
duckdns-updater = {
nixos = {
laptop.tlp = {
enable = true;
certs.enable = true;
domain = "hachune-nixos.duckdns.org";
cpuFreqGovernor = "schedutil";
};
server = {
enable = true;
iperf3.enable = true;
jellyfin.enable = true;
networkd.enable = true;
plex.enable = true;
rtorrent.enable = true;
ssh.enable = true;
tailscale.enable = true;
duckdns-updater = {
enable = true;
certs.enable = true;
domain = "hachune-nixos.duckdns.org";
};
};
};

Expand All @@ -47,14 +53,5 @@ in
home-manager.users.${config.meta.username}.theme.wallpaper.path = pkgs.wallpapers.hatsune-miku_stylized-ultrawide;

# Reduce power consumption
services.tlp = {
enable = true;
settings = {
CPU_SCALING_GOVERNOR_ON_AC = "schedutil";
CPU_SCALING_GOVERNOR_ON_BAT = "schedutil";
RUNTIME_PM_ON_AC = "auto";
};
};

time.timeZone = "America/Sao_Paulo";
}
21 changes: 7 additions & 14 deletions hosts/sankyuu-nixos/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ in
# The audio device from this notebook doesn't seem to like short buffers too much
quantum = 128;
};
laptop.tlp = {
cpuFreqGovernor = "schedutil";
batteryThreshold = {
start = 75;
stop = 80;
};
};
};

programs.steam.gamescopeSession.args = [
Expand All @@ -67,20 +74,6 @@ in

# Used for firmware updates
services.fwupd.enable = true;
services.tlp.settings = {
# Set battery thresholds
START_CHARGE_THRESH_BAT0 = 75;
STOP_CHARGE_THRESH_BAT0 = 80;
# Use `tlp setcharge` to restore the charging thresholds
RESTORE_THRESHOLDS_ON_BAT = 1;
# Increase performance on AC
PLATFORM_PROFILE_ON_AC = "performance";
PLATFORM_PROFILE_ON_BAT = "balanced";
# Use schedutil governor
CPU_SCALING_GOVERNOR_ON_AC = "schedutil";
CPU_SCALING_GOVERNOR_ON_BAT = "schedutil";
};


# https://gitlab.freedesktop.org/pipewire/pipewire/-/issues/1849
systemd.services.fix-mic-light = {
Expand Down
43 changes: 5 additions & 38 deletions nixos/laptop.nix → nixos/laptop/default.nix
Original file line number Diff line number Diff line change
@@ -1,46 +1,20 @@
{ config, pkgs, lib, ... }:

{
imports = [
./wireless.nix
./tlp.nix
];

options.nixos.laptop.enable = lib.mkEnableOption "laptop config" // {
default = (config.device.type == "laptop");
};

config = lib.mkIf config.nixos.laptop.enable {
networking = {
# Use Network Manager
networkmanager = {
enable = true;
wifi.backend = "iwd";
};
};

# Configure hibernation
boot.resumeDevice = lib.mkIf (config.swapDevices != [ ])
(lib.mkDefault (builtins.head config.swapDevices).device);

# Install laptop related packages
environment.systemPackages = with pkgs; [ iw ];

# Configure special hardware in laptops
hardware = {
# Enable bluetooth
bluetooth = { enable = true; };
};

# Enable programs that need special configuration
programs = {
# Enable NetworkManager applet
nm-applet = { enable = true; };
};

# Make nm-applet restart in case of failure
systemd.user.services.nm-applet = {
serviceConfig = {
RestartSec = 3;
Restart = "on-failure";
};
};

# Enable laptop specific services
services = {
# Enable Blueman to manage Bluetooth
Expand All @@ -56,13 +30,6 @@
lidSwitchExternalPower = lib.mkDefault "lock";
};

# Use systemd-resolved for DNS
resolved = {
enable = true;
# Can make DNS lookups really slow
dnssec = "false";
};

# Reduce power consumption
tlp.enable = true;
};
Expand Down
54 changes: 54 additions & 0 deletions nixos/laptop/tlp.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{ config, pkgs, lib, ... }:

let
cfg = config.nixos.laptop.tlp;
in
{
options.nixos.laptop.tlp = {
enable = lib.mkEnableOption "TLP config" // {
default = config.nixos.laptop.enable;
};
cpuFreqGovernor = lib.mkOption {
default = config.powerManagement.cpuFreqGovernor;
types = lib.types.nullOr lib.types.string;
example = "schedutil";
description = "CPU frequency governor to be set via TLP.";
};
batteryThreshold = {
start = lib.mkOption {
default = 0;
types = lib.types.int;
description = "Start of battery charging threshold";
};
stop = lib.mkOption {
default = 0;
types = lib.types.int;
description = "Stop of battery charging threshold";
};
};
};

config = lib.mkIf cfg.enable {
# Reduce power consumption
services.tlp = {
enable = true;
# https://linrunner.de/tlp/support/optimizing.html
settings = {
# Enable the platform profile low-power
PLATFORM_PROFILE_ON_BAT = lib.mkDefault "balanced";
# Enable the platform profile performance
PLATFORM_PROFILE_ON_AC = lib.mkDefault "performance";
# Enable runtime power management
RUNTIME_PM_ON_AC = lib.mkDefault "auto";
# CPU frequency governor
CPU_SCALING_GOVERNOR_ON_AC = lib.mkIf (cfg.cpuFreqGovernor != null) cfg.cpuFreqGovernor;
CPU_SCALING_GOVERNOR_ON_BAT = lib.mkIf (cfg.cpuFreqGovernor != null) cfg.cpuFreqGovernor;
# Set battery thresholds
START_CHARGE_THRESH_BAT0 = cfg.batteryThreshold.start;
STOP_CHARGE_THRESH_BAT0 = cfg.batteryThreshold.stop;
# Use `tlp setcharge` to restore the charging thresholds
RESTORE_THRESHOLDS_ON_BAT = lib.mkDefault 1;
};
};
};
}
47 changes: 47 additions & 0 deletions nixos/laptop/wireless.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{ config, pkgs, lib, ... }:

{
options.nixos.laptop.wireless.enable = lib.mkEnableOption "Wi-Fi/Bluetooth config" // {
default = config.nixos.laptop.enable;
};

config = lib.mkIf config.nixos.laptop.enable {
networking = {
# Use Network Manager
networkmanager = {
enable = true;
wifi.backend = "iwd";
};
};

# Install Wireless related packages
environment.systemPackages = with pkgs; [ iw ];

# Enable bluetooth
hardware.bluetooth.enable = true;

# Enable NetworkManager applet
programs.nm-applet.enable = true;

# Make nm-applet restart in case of failure
systemd.user.services.nm-applet = {
serviceConfig = {
RestartSec = 3;
Restart = "on-failure";
};
};

# Wireless related config
services = {
# Enable Blueman to manage Bluetooth
blueman.enable = true;

# Use systemd-resolved for DNS
resolved = {
enable = true;
# Can make DNS lookups really slow
dnssec = "false";
};
};
};
}

0 comments on commit 8287125

Please sign in to comment.