Skip to content

Commit

Permalink
feat: mem-cap zotero and firefox, implement tb-conservation
Browse files Browse the repository at this point in the history
- enable ThinkBook conservation mode to preserve battery life
- cap the memory footprint of firefox and zotero by systemd-run
- use `firefox` instead of `firefox-wayland` as the latter is already an
  alias
LEXUGE committed Dec 20, 2024

Verified

This commit was signed with the committer’s verified signature.
LEXUGE Kanyang Ying
1 parent 2419266 commit 2c36122
Showing 9 changed files with 97 additions and 18 deletions.
2 changes: 1 addition & 1 deletion cfgs/deck/default.nix
Original file line number Diff line number Diff line change
@@ -99,7 +99,7 @@
# minecraft
tor-browser-bundle-bin
sbctl
firefox-wayland
firefox
htop
dnsutils
smartmontools
2 changes: 1 addition & 1 deletion cfgs/img-deck/default.nix
Original file line number Diff line number Diff line change
@@ -109,7 +109,7 @@ with lib;
};
my.home.nixos = {
extraPackages = with pkgs; [
firefox-wayland
firefox
htop
dnsutils
smartmontools
2 changes: 1 addition & 1 deletion cfgs/img-tb14/default.nix
Original file line number Diff line number Diff line change
@@ -109,7 +109,7 @@ with lib;
};
my.home.nixos = {
extraPackages = with pkgs; [
firefox-wayland
firefox
htop
dnsutils
smartmontools
2 changes: 1 addition & 1 deletion cfgs/img-x1c7/default.nix
Original file line number Diff line number Diff line change
@@ -109,7 +109,7 @@ with lib;
};
my.home.nixos = {
extraPackages = with pkgs; [
firefox-wayland
firefox
htop
dnsutils
smartmontools
2 changes: 1 addition & 1 deletion cfgs/tb14/default.nix
Original file line number Diff line number Diff line change
@@ -70,7 +70,7 @@
tor-browser-bundle-bin
tpm2-tools
sbctl
firefox-wayland
firefox
tdesktop
htop
qbittorrent
9 changes: 1 addition & 8 deletions cfgs/tb14/hardware.nix
Original file line number Diff line number Diff line change
@@ -47,12 +47,5 @@
enable32Bit = true;
};

# TODO: TLP doesn't play well with GNOME. Try figure out how to do the charge threshold thing with UPower later.
# services.tlp = {
# enable = true;
# settings = {
# START_CHARGE_THRESH_BAT0 = 40; # 40 and bellow it starts to charge
# STOP_CHARGE_THRESH_BAT0 = 80; # 80 and above it stops charging
# };
# };
my.tb-conservation.enable = true;
}
2 changes: 1 addition & 1 deletion cfgs/x1c7/default.nix
Original file line number Diff line number Diff line change
@@ -70,7 +70,7 @@
tor-browser-bundle-bin
tpm2-tools
sbctl
firefox-wayland
firefox
tdesktop
htop
qbittorrent
50 changes: 46 additions & 4 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -135,10 +135,50 @@
pkgs = prev;
overlay = true;
});
# NOTE: Currently not used, but put here as an example
pidgin = final: prev: {
pidgin-with-plugins = prev.pidgin.override {
plugins = [ prev.pidgin-otr ];
# # Currently not used, but put here as an example
# pidgin = final: prev: {
# pidgin-with-plugins = prev.pidgin.override {
# plugins = [ prev.pidgin-otr ];
# };
# };

mem-cap = final: prev: {
zotero = prev.buildEnv {
name = "zotero-mem-cap-suite";
# Intentional, other schemes may take up twice of storage and possibly a rebuild
ignoreCollisions = false;
paths = [
# uncapped version
(prev.writeShellScriptBin "zotero-mem-uncapped" ''
${prev.zotero}/bin/zotero "$@"
'')
# capped version
(lib.hiPrio (
prev.writeShellScriptBin "zotero" ''
${prev.systemd}/bin/systemd-run --user --scope -p MemoryHigh=4G ${prev.zotero}/bin/zotero "$@"
''
))
prev.zotero
];
};

firefox = prev.buildEnv {
name = "firefox-mem-cap-suite";
# Intentional, other schemes may take up twice of storage and possibly a rebuild
ignoreCollisions = false;
paths = [
# uncapped version
(prev.writeShellScriptBin "firefox-mem-uncapped" ''
${prev.firefox}/bin/firefox "$@"
'')
# capped version
(lib.hiPrio (
prev.writeShellScriptBin "firefox" ''
${prev.systemd}/bin/systemd-run --user --scope -p MemoryHigh=4G ${prev.firefox}/bin/firefox "$@"
''
))
prev.firefox
];
};
};
};
@@ -150,6 +190,7 @@
nixosConfigurations.tb14 = mkSystem {
name = "tb14";
extraMods = [
nixosModules.tb-conservation
nixosModules.clash
nixosModules.base
nixosModules.lanzaboote
@@ -171,6 +212,7 @@
ash-emacs.overlays.emacs-overlay
ash-emacs.overlays.default
vimrc.overlays.default
self.overlays.mem-cap
];
system = system.x86_64-linux;
};
44 changes: 44 additions & 0 deletions modules/tb-conservation/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
lib,
pkgs,
config,
...
}:

with lib;

let
cfg = config.my.uxplay;
in
{
options.my.tb-conservation = {
enable = mkEnableOption "ThinkBook Battery Conservation Mode";
};

config = mkIf cfg.enable {
systemd.services.conservation-mode = {
enable = true;
description = "Turn on the ThinkBook power conservation mode for battery health";
wantedBy = [ "multi-user.target" ];

serviceConfig = {
Type = "oneshot";
RemainAfterExit = true;
};

unitConfig.RequiresMountsFor = "/sys";
serviceConfig = {
ExecStart = (
pkgs.writeShellScript "start_conservation_mode" ''
echo 1 > /sys/bus/platform/drivers/ideapad_acpi/VPC2004:00/conservation_mode
''
);
ExecStop = (
pkgs.writeShellScript "stop_conservation_mode" ''
echo 0 > /sys/bus/platform/drivers/ideapad_acpi/VPC2004:00/conservation_mode
''
);
};
};
};
}

0 comments on commit 2c36122

Please sign in to comment.